Skip to content

Allow np.ufunc to make new compound models #3866

Description

@mhvk

This issue is mostly to remind us/@embray of an idea that mentioned in #3861 (comment): could one not just support operations like + on model classes but also np.ufunc? This would seem possible if one defined __numpy_ufunc__ appropriately, and would mean one would nearly for free get all ufuncs covered as models, ie., one could have np.sin(Const1D+Scale) construct a new model class.

Possibly somewhat unrelatedly, by way of similarity, it might then be good to have F | G being equivalent to G(F) -- obviously, this needs some trickery in G.__new__...

Activity

  1. cdeil commented on Jun 19, 2015

    @cdeil
    Member

    It would be nice to get a lot of analytical functions for free as models instead of having to write wrappers for each one. (Assuming this can be implemented ...) What are the limitations? I guess these models couldn't have fit_deriv? But that's often not important. Anything else obvious that's hard or impossible?

  2. mhvk commented on Jun 19, 2015

    @mhvk
    ContributorAuthor

    fit_deriv would not be hard -- see https://github.com/astropy/astropy/pull/3715/files#diff-2a3560744629608434d0eff93c50cf2aR13
    The main issue, I think, is that there is as far as I know no way to make this work without __numpy_ufunc__, i.e., those with numpy <1.10 will have to import the mathematical functions from somewhere.

  3. embray commented on Jun 23, 2015

    @embray
    Member

    In any case fit_deriv is not currently implemented for compound models in general, though I think there's an open issue for that wherein I've described what needs to be done to implement it. For the most part I think it's straightforward, but I haven't actually tried yet.

  4. embray commented on Jun 23, 2015

    @embray
    Member

    This is the one #3783

  5. mhvk commented on Jun 30, 2015

    @mhvk
    ContributorAuthor

    In numpy/numpy#5844 (comment), @argriffing pointed to algopy, which defines functions on models as well, and might well have gradient-estimating code, etc., that is useful here (or for modeling more generally).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions