Skip to content

Implement log spectral density for squared exponential#2143

Open
elliottperryman wants to merge 1 commit intopyro-ppl:masterfrom
elliottperryman:master
Open

Implement log spectral density for squared exponential#2143
elliottperryman wants to merge 1 commit intopyro-ppl:masterfrom
elliottperryman:master

Conversation

@elliottperryman
Copy link

Added a new function to compute the log spectral density for the squared exponential kernel.

I was using HSGP in my numpyro model and found that using the eigenvalues can be computed more stably using the log domain. Treating them in log-space is perfectly fine (alpha > 0 & length > 0 & other term is an exponential). I am not saying my implementation is the best code or something, but I would like to ask if this could be useful.

Added a new function to compute the log spectral density for the squared exponential kernel,
@juanitorduz
Copy link
Collaborator

Hi! @elliottperryman Can you elaborate a bit more? (Do you have a reference or example?)

c3 = special.gamma(nu)
return c1 * c2 / c3

# def log_diag_spectral_density_squared_exponential(
Copy link
Member

Choose a reason for hiding this comment

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

Pls revert

e = jnp.exp(-0.5 * jnp.sum(w**2 * length**2, axis=-1))
return c * e

def log_spectral_density_squared_exponential(
Copy link
Member

Choose a reason for hiding this comment

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

Could you add test for this?

@elliottperryman
Copy link
Author

I have two points that may be of interest to users:

  • Almost all uses of this function will take a square root, which is easier in log space
  • The calculation "jnp.log(alpha) + 0.5jnp.log(2jnp.pi) + jnp.log(length)" which is implemented the c term of the squared exponential density does not need to be recomputed for every eigenvalue.

I can make a jupyter notebook demoing the differences if that helps.

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.

3 participants