Skip to content
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

Modifying cartesian product to allow for >2D input arrays #4482

Merged
merged 3 commits into from
Feb 26, 2021
Merged

Modifying cartesian product to allow for >2D input arrays #4482

merged 3 commits into from
Feb 26, 2021

Conversation

ckrapu
Copy link
Contributor

@ckrapu ckrapu commented Feb 21, 2021

Currently, using the implementation of MarginalKron for structured Gaussian processes is limited by an inability to initialize the GP for input arrays for the Kronecker product which have more than 1 dimension. For example, creating a Kronecker GP with a 2D spatial covariance kernel added to a 1D temporal covariance kernel is not possible while adding a 1D spatial to a 1D temporal kernel is possible. This issue limits the utility of the Kronecker GP from being used in arguably its most suitable use case (independent space/time covariance kernels). To recreate this issue, see this gist.

The main change to the function cartesian is to first create a cartesian product of integer vectors, and then use these to index into the input arrays instead.

@ckrapu
Copy link
Contributor Author

ckrapu commented Feb 21, 2021

I didn't run the tests locally here - I'll edit and fix as appropriate so that it passes.

@bwengals
Copy link
Contributor

I checked out the branch and tried the gist, it works great.

arguably its most suitable use case

Definitely agree.

Maybe a test of the new functionality with a 2D X input could be added, or existing test modified?

@ckrapu
Copy link
Contributor Author

ckrapu commented Feb 23, 2021

Thanks for taking a look at this! I just added a new test which covers the usage of a 2D input as well as a 1D length-1 input.

)
auto_cart = cartesian(a, b, c)
np.testing.assert_array_almost_equal(manual_cartesian, auto_cart)

Copy link
Contributor

Choose a reason for hiding this comment

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

I would think that assert_array_equal is sufficient here (no almost). I noticed the other test_cartesian does this so they should both be fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point - those assertions have been changed.

Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

LGTM

From your example gist my understanding is that the function you changed plays a role for the kron_Xs in the marginal likelihood?

Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

Ah sorry one more thing: Please add a line to the release notes.

@ckrapu
Copy link
Contributor Author

ckrapu commented Feb 26, 2021

Thanks for adding the release note!

LGTM

From your example gist my understanding is that the function you changed plays a role for the kron_Xs in the marginal likelihood?

Yes, it turns out that most of the functionality in the marginal likelihood bit was working fine - the only change was in how the input coordinates are preprocessed via pm.math.cartesian from a short array of per-axis grid coordinates to a tall array of points.

@michaelosthege michaelosthege merged commit 47b3658 into pymc-devs:master Feb 26, 2021
sthagen added a commit to sthagen/pymc-devs-pymc that referenced this pull request Feb 27, 2021
Modifying cartesian product to allow for >2D input arrays (pymc-devs#4482)
Pyrsos added a commit to Pyrsos/pymc3 that referenced this pull request Mar 1, 2021
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.

None yet

3 participants