Skip to content

Fix for mean functions #2111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed

Conversation

bwengals
Copy link
Contributor

@bwengals bwengals commented May 2, 2017

This PR addresses #2078 by fixing the shape of mean function outputs. It also contains tests for the bug in #2078. I had tried including some refactoring but removed this. Now this is just a fix for the mean functions + tests.

pymc3/gp/cov.py Outdated
@@ -342,7 +337,7 @@ def square_dist(self, X, Z):
sqd = -2.0 * tt.dot(X, tt.transpose(X)) +\
(tt.reshape(Xs, (-1, 1)) + tt.reshape(Xs, (1, -1)))
else:
Z = tt.as_tensor_variable(Z)
Z = tt.as_tensor_variable(X)
Copy link
Member

Choose a reason for hiding this comment

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

Is this intentional? If so, might need a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no not intentional! good catch...

pymc3/gp/mean.py Outdated
Parameters
----------
coeffs : variables
Linear coefficients
intercept : variable, array or integer
Intercept for linear function (Defaults to zero)
"""
Mean.__init__(self)
Mean.__init__(self, input_dim, active_dims)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should use super here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, fixed

@bwengals
Copy link
Contributor Author

bwengals commented May 3, 2017

While addressing your corrections I found that Add and Prod for mean functions don't work correctly. Will address in separate PR.

Edit: I think this is due to my changes --- subclassing Mean on ParameterizedFunction which requires the input_dim and active_dim args. Maybe this PR is the place for these fixes then.

raise ValueError('mean_func must be a subclass of Mean')
self.M = mean_func


Copy link
Member

Choose a reason for hiding this comment

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

Was moving this an aesthetic change, or is there a reason for checking the covariance function first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was so the default mean function could take parameters that the user would have set when they instantiated the covariance function

pymc3/gp/mean.py Outdated
over that dimension or column of X.
"""

def __init__(self, input_dim, active_dims=None):
Copy link
Member

Choose a reason for hiding this comment

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

Is there a downside to having a default of input_dim=1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm I'm not sure. It's certainly the most likely thing a user would do. When these functions are instantiated they don't know about X yet, so if a user forgets to set it explicitly they'll get an error at runtime.

@bwengals
Copy link
Contributor Author

Also, are there other mean functions that might be of interest @fonnesbeck ?

@fonnesbeck
Copy link
Member

I'm sure there are fancy things you can do with mean functions, but you don't really see anyone doing it. As long as we can apply a little prior information to the mean (which we can with a linear mean) then we are probably set for the time being.

@bwengals
Copy link
Contributor Author

bwengals commented Jun 2, 2017

I decided to just address #2078, which was just a simple fix for outputs with the wrong shape. I removed the scope creep... Nother day. I think this should be ready for review then @fonnesbeck @twiecki

@fonnesbeck
Copy link
Member

These look good. Is this still a WIP, or are you ready to merge?

@bwengals
Copy link
Contributor Author

bwengals commented Jun 4, 2017

Yes I think so @fonnesbeck. Those 3 recent commits change the output shape for the mean functions from (n, 1) to (n, ), as per #2262 .

@aseyboldt
Copy link
Member

@bwengals Needs a rebase.

@bwengals
Copy link
Contributor Author

bwengals commented Jun 9, 2017

@aseyboldt resolved it

@aseyboldt
Copy link
Member

The failing tests seem to be due to the numpy update to 1.13
We should probably fix that in a different PR, merge that and then rerun the tests.

@twiecki
Copy link
Member

twiecki commented Jun 20, 2017

@fonnesbeck Should we merge this before 3.1?

@bwengals bwengals mentioned this pull request Jun 21, 2017
@bwengals
Copy link
Contributor Author

see #2337

@junpenglao
Copy link
Member

close in favor of #2337

@junpenglao junpenglao closed this Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants