Skip to content

Separate optimization from statistic redux#2441

Merged
embray merged 14 commits into
astropy:masterfrom
embray:fitter-separation
Jun 10, 2014
Merged

Separate optimization from statistic redux#2441
embray merged 14 commits into
astropy:masterfrom
embray:fitter-separation

Conversation

@embray

@embray embray commented May 5, 2014

Copy link
Copy Markdown
Member

This is a rebased version of #1914. I decided to go ahead and make a new PR so that it can easily be run through Travis and the like. Otherwise no major differences. Once the CI gives us a green checkmark this should be merged instead of #1914.

@embray embray added this to the v0.4.0 milestone May 5, 2014
@astrofrog

Copy link
Copy Markdown
Member

@embray - it looks like the sphinx failures are genuine.

@embray

embray commented May 19, 2014

Copy link
Copy Markdown
Member Author

I fixed a few of the problems with the doc build, but the issue remains as to what to do with the "what's new" page. I raised this question the mailing list.

@embray

embray commented May 23, 2014

Copy link
Copy Markdown
Member Author

Rebased this to get Travis to build once more against the latest master, where the problem with the "what's new" doc page should be moot.

@embray

embray commented May 23, 2014

Copy link
Copy Markdown
Member Author

Assuming this passes, finally, I hope to get it merged. Current work I'm doing on the modeling package depends on this work (albeit none of it is necessary for 0.4).

@eteq

eteq commented May 27, 2014

Copy link
Copy Markdown
Member

@nden @mhvk - does anyone want to review this? Or should we merge this now, given that the tests are passing (and it was in before feature freeze)? Or push it to 1.0?

@mhvk

mhvk commented May 27, 2014

Copy link
Copy Markdown
Contributor

@eteq - I'm not involved in this (though it certainly seems a good idea, so in that sense an uninformed +1).

@nden

nden commented May 27, 2014

Copy link
Copy Markdown
Contributor

@eteq It says it's a copy of #1914 which I wrote so I don't think I should review it but all relevant comments are in #1914.

@embray

embray commented May 27, 2014

Copy link
Copy Markdown
Member Author

This is basically ready to go as far as I'm concerned. I'm working currently on a few improvements on top of this but they won't be ready in time for 0.4 and won't be significant changes to the overall structure. So I think this is better to have now than not. Though I'm happy to update the PR if anyone would like to review this and point out any glaring issues--in fact it would be appreciated.

Comment thread docs/modeling/new.rst

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a user-defined fit statistic is quite common.
So it shouldn't be necessary to import functions with underscores (i.e. private implementation details).
How about making those functions public by removing the underscores and include them in the docs (maybe in this part of the docs)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops ... I made the same comments here and you disagreed: #1878 (comment)

Note that e.g. in Sherpa this is an FAQ: http://cxc.harvard.edu/sherpa/faq/user_stat.html

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and am working on refactoring how that's done. In the meantime though this basically documents how they existing code is implemented so that other developers can copy it. I'm working on simplifying things so that fewer "internal" details need to be worried about, but that will have to wait til later.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I disagreed with you there, but I agree with this in spirit. It's just not a high priority and not an issue for how these docs are currently to be read or who the intended audience is :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, in my refactor of this the custom statistic functions are just as straightforward to implement as in Sherpa. For example, this is what least_square looks like (in the current in development version, so far):

def least_square(measured_values, approximated_values, weights=None):
    return np.sum(residuals(measured_values, approximated_values, weights=weights) ** 2)

(where residuals is defined in a similarly obvious way). I should note that the arguments currently accepted by this function are not what general functions are limited to. Custom statistics will be able to accept additional arguments as needed, such as uncertainties.

@cdeil

cdeil commented May 27, 2014

Copy link
Copy Markdown
Member

I have one comment on docs/modeling/new.rst. Making these long examples of 10+ lines with interspersed text is a bad idea in my opinion. It can't be quickly copy & pasted & tried out by the user and it quickly breaks because it can't be tested. (This happened to the old version.)

I tried improving this in #1878 which was never merged (mostly my fault) and by now would probably have to re-done from scratch.

@embray

embray commented May 27, 2014

Copy link
Copy Markdown
Member Author

@cdeil Do you think it would help if, at the end of the docs, a "full example" were pieced together from the previous text?

@cdeil

cdeil commented May 27, 2014

Copy link
Copy Markdown
Member

IMO the best way would be to write such long examples is directly as "full example" (that's what I did in #1878 for this) so that the user can run the example and it can be run as part of the tests.

If you don't want to make this change to the docs, how about putting the full example as a unit test (still has to be manually updated in two places, but at least it's tested).

@embray

embray commented May 27, 2014

Copy link
Copy Markdown
Member Author

If I understand correctly, that would involve writing any explanation in the comments of the example. I have to problem with that, I just want to make sure I understand correctly.

@cdeil

cdeil commented May 27, 2014

Copy link
Copy Markdown
Member

Writing explanations in the comments of the example is one option.

Another one is writing the comments before and / or after the full example.
It's possible to refer to line numbers as I tried here ... I think that's the nicest option for the user, but it's a bit tedious for the guy writing / maintaining the docs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new class is currently not covered by tests ... can you add at least one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out it is covered by the test test_fitter_against_LevMar, but I'll add another explicitly for that fitter.

@cdeil

cdeil commented May 27, 2014

Copy link
Copy Markdown
Member

I've left some inline comments ... mainly asking for a test that covers the new code.

I can try this out tomorrow (it would be nice if there were working examples in the docs I can just run).
Here's the example code from the docs with proper indentation as an IPython notebook.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

objective_function : callable
    Objective function

@embray

embray commented May 27, 2014

Copy link
Copy Markdown
Member Author

I'm not so sure about that. Having the explanation not inline with the code means repeated looking up and down the page and trying to match up the explanation with the particular line of code. That's a real pain. One could open two copies of the page side-by-side but that's not always feasible either.

Comment thread astropy/modeling/fitting.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a dot . at the end of this sentence.
The Parameters section in the Sphinx output is currently garbled because of this (check the html output).

@cdeil

cdeil commented May 27, 2014

Copy link
Copy Markdown
Member

Having the explanation not inline with the code means repeated looking up and down the page and trying to match up the explanation with the particular line of code.

IMO a code example I can actually run is much more important than where the explanations are placed. But I'll shut up about that now.

@embray

embray commented Jun 6, 2014

Copy link
Copy Markdown
Member Author

@cdeil I'm probably going to hold off on going too crazy right now on the examples in the documentation, though I agree with you on all this in general. Reason being (and I hate to keep having to say this) I'm working on an overhaul of how the optimizer/statistic separation is implemented. The basic idea is still the same but I'm trying to simplify things a little. I would go ahead and append my work on that to this PR, but it depends on #2580 (and isn't quite yet finished).

All that said, should we maybe hold off on this entirely until my refactoring is ready or is it good to go ahead and pull this in now?

@cdeil

cdeil commented Jun 6, 2014

Copy link
Copy Markdown
Member

All that said, should we maybe hold off on this entirely until my refactoring is ready or is it good to go ahead and pull this in now?

I think the sooner your re-factorings go into master, the better. I wouldn't worry much about what goes in 0.4 or not, I think it's clear that astropy.modeling is still very much in flux and there's the big red warning at the top of the docs.

Let me know if I can help with reviewing some PR or if there's something I could maybe implement.

embray and others added 12 commits June 6, 2014 15:04
…taldcroft that these examples expose an unfortunate degree of complexity involved in creating new Fitters, such that it is not really at a point where casual users can do it.  But these docs are still useful to have for developers to look at--in the future I hope to try to hide more of the sausage-making if I can.  Also redid the section headings per the preferred formatting.
…oing through a 'utils' module. Use the NumpyRNGContext where appropriate.
…out by @cdeil in astropy#2441, but also including several other mistakes I found while reading through the docs.
Comment thread astropy/modeling/optimizers.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives a sphinx warning and makes the travis-ci build fail:
https://travis-ci.org/astropy/astropy/jobs/26970976#L3333

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. I thought I saw that in the logs too but I couldn't find where it was coming from. Incidentally, I removed this already but in a different branch (the one where I'm refactoring) =_=

embray added 2 commits June 9, 2014 17:26
@embray

embray commented Jun 10, 2014

Copy link
Copy Markdown
Member Author

Tests passing now. If there are no further comments this should be merged, with the understanding that there will continue to be improvements here shortly after 0.4 is out, I hope.

@astrofrog

Copy link
Copy Markdown
Member

Sounds good! Thanks for all your work on this!

@embray

embray commented Jun 10, 2014

Copy link
Copy Markdown
Member Author

Thanks to @nden for the lion's share of the work.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants