Repository navigation
Gaussian1dModel.stddev is incorrectly used - #1106
Conversation
|
+1 Good catch. |
|
Shall I attach code to this issue? |
|
Can't hurt. |
|
Weird, I'm getting a 'forbidden' error when trying to attach my fix (in my modeling/fix-gaussian-stddev branch) to this issue. Have you had that before? |
|
Ah, turns out I had to update |
|
Yeah I dunno, I still just use @eteq's issue2pr.py script. |
There was a problem hiding this comment.
👍 This is a bit less prone to embarrassing misreading I think 😉
|
@nden - should I just update the expected values for the tests? |
|
@astrofrog Yes, sure. Thank you. |
|
@nden - I fixed all the failing tests except one which I don't understand. Do you think you could have a look to see if you can figure out what is going on? |
|
I think the Gaussian2DModel has a similar issue, so looking into that |
|
I tidied up and fixed the equation for the 2D Gaussian - however, I would appreciate if someone could double check the equations, since there are no tests for the numerical accuracy of the 2D Gaussian. |
|
By the way, I think there's some optimizations that could be made for the calculations of the Gaussians, but I'll leave that to a separate issue (for example, avoiding recomputing the square of a parameter several times) |
|
Indeed, there are ways lots of these models could be optimized by breaking them up into separate terms that only need to be recomputed when one of the parameters is changed. But that is indeed something that needs to be tackled on a case by case basis probably, along with some profiling. Also almost all of the functions should eventually be redone to be written in Cython (and at some point I still want to explore using things like numexpr and/or Numba in Astropy but again that's another issue). |
|
I actually think some of the functions are so generic that they should live outside |
|
Indeed. That would be a necessary step anyways to providing multiple alternative implementations. |
|
@astrofrog The two failing tests are the only ones that use/test scipy. I can't reproduce the error locally. How do I find out the version of scipy running on Travis? Is it in travis.yml - scipy 0.12? |
|
@nden - the version of scipy used on travis is given in the header of the test output: So it's using 0.12. I'm also using 0.12 locally. |
There was a problem hiding this comment.
There is another bug here with the order of param_names. This function should be:
def eval(self, x, y, p):
a = 0.5 * ((np.cos(p[5]) / p[3]) ** 2 +
(np.sin(p[5]) / p[4]) ** 2)
b = 0.5 * (np.cos(p[5]) * np.sin(p[5]) *
(1. / p[3] ** 2 - 1. / p[4] ** 2))
c = 0.5 * ((np.sin(p[5]) / p[3]) ** 2 +
(np.cos(p[5]) / p[4]) ** 2)
return p[0] * np.exp(-(a * (x - p[1]) ** 2 +
b * (x - p[1]) * (y - p[2]) +
c * (y - p[2]) ** 2))
The eval was getting stddev's and mean's wrong.
There was a problem hiding this comment.
Thanks - this should be fixed
|
@astrofrog @cdeil I've ran variations of the failing test. The result of the SLSQP fitter depends on the level of noise added to the signal. For example, if |
|
Yes, change the test in whatever way necessary to achieve absolutely reproducible results in the unit tests. Generally we don't want to have any test with borderline behaviour (e.g. different on 32 and 64 bit machines) |
|
I'll try and change |
|
If the tests pass, this is ready for a review. |
There was a problem hiding this comment.
Please put stddev before fwhm so that Gaussian1DModel(1, 2, 3) will set the parameters corresponding to param_names, i.e. stddev=3. I think this is less confusing.
…ng for input paramters
|
@cdeil - should |
|
IMO having the model |
|
@cdeil - done |
|
Maybe we can change the |
|
@astrofrog @adrn I timed it both ways fitting an 100x100 array and @astrofrog 's implementation is about 10% faster. May be we should sacrifice readability in favor of performance here. |
There was a problem hiding this comment.
This test is written like a class. A function at the module level is probably sufficient, something like:
def test_gaussian2D():
m = models.Gaussian2DModel(2., 3., 4., x_stddev=1., y_stddev=5., theta=30.)
assert m(3., 4.) == 2.
|
@nden - ok, sounds good. If you are happy with this, and the tests pass, then this is good to go. |
Gaussian1dModel.stddev is incorrectly used This also fixed points 1 and 2 in #1077
While trying to fit some data, I noticed that the
Gaussian1DModelis wrong:it should be: