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

ValueError: Querying emulator outside of original parameter range. #149

Closed
Aseman7 opened this issue Dec 19, 2022 · 10 comments
Closed

ValueError: Querying emulator outside of original parameter range. #149

Aseman7 opened this issue Dec 19, 2022 · 10 comments

Comments

@Aseman7
Copy link

Aseman7 commented Dec 19, 2022

Thanks for your attention in advance. As for the examples file, after running of setup. ipynb successfully, I want to run single.ipynb, but the following cell

%time model.train(priors),

it can not run correctly and I got this error (without any change in the previous cells):

ValueError: Querying emulator outside of original parameter range.

@mileslucas
Copy link
Member

Sorry for the delayed response,I will take a look at this soon. Can you let me know which versions of Python and Starfish you are using?

This error occurs when you try and retrieve a spectrum outside of your model grid, not sure why it could be happening in the tutorial.

@Aseman7
Copy link
Author

Aseman7 commented Jan 9, 2023 via email

@astro-catherine
Copy link

I am running into the same error, though I am using my own data and running Python 3.9.12.

@gully
Copy link
Collaborator

gully commented Feb 3, 2023

This error should arise when you try to evaluate the spectral emulator with values outside of the original grid window, so for example the emulator was trained from [5000, 5700] and you attempt to recreate a 5704.1 Teff.

Usually one prevents an MCMC from wandering past these boundaries by enforcing a prior that does not allow the walkers to reach this point---can you confirm that the prior and likelihood are structured in such a way that would prevent the spectral reconstruction from occurring if handed an out-of-bounds grid point?

@astro-catherine
Copy link

The ranges I currently have set are Teff=[3700, 5500], logg=[4.0, 5.0], and Z=[-0.5, 0.5], and the priors I have set are
priors = {
"T": st.norm(4968, 100),
"Z": st.uniform(-0.5, 0.5),
"logg": st.uniform(4.0, 5.0)}
Though I have tried a few different variations on these values.

@AustenWallis
Copy link

Hi, (not apart of the devs but ran into this error before too), ensure your global covariance kernel variables , log_amp and log_ls also match within the 'priors = {...}' and the 'model = SpectrumModel(...)'. In addition, that the two variables give you a reasonable standard deviation fit on the residuals graph before these steps. If not, it will also output the same valueerror. Don't know if this helps!

@gully
Copy link
Collaborator

gully commented Feb 6, 2023

Hi @astro-catherine, a few thoughts:

  1. The "T": st.norm(4968, 100) prior has finite support outside of Teff=[3700, 5500] bounds. Do you still get the same error if you use a Uniform prior on T? Are you progressing any steps before the error is raised, or is it immediate?
  2. I forget what happens with edge cases, if say a logg=5.00000 is proposed, does it violate the boundary? I suppose that's vanishing probability, but would be good to know (would likely only happen if you were initializing samplers on integer numbers somehow).
  3. Agreed with @AustenWallis, even though the covariance kernel variables are not strictly part of the grid dimensions, the error might just be raising the wrong message in response to some other deviance.
  4. How are you doing the initializing? Is it with samples from the prior or some other heuristic? I suppose there could be hidden assumptions in the initialization that send samplers outside the domain.

Do any of those solve the problem?

@Aseman7
Copy link
Author

Aseman7 commented Feb 6, 2023

Thank you very much for your answers, those are useful. Solved my problem, for solving it

  1. I simultaneously assigned a value to "logg" in the priors and did not freeze it.
    "logg": st.norm (4.9, 0.007),

2: I changed the value for the covariance kernel variables according to #148.

Either one alone didn't solve my problem. I tried them several times.

Now that the training for numerical optimization has been completed correctly, the next problem is that I don't have a correct residual graph even after using an optimized initial model. "In the single.ipynb as Starfish example, I see the residual graph is getting true after this step unlike mine." Do you have any suggestions to correct it? Any help would be appreciated.

After training

I write here the original ranges, SpectrumModel, and priors too, thanks a lot:

ranges = [[2400, 3900], [4.5, 5.5], [-1, 1]] # T, logg, Z

model = SpectrumModel(
"F_SPEX_emu.hdf5",
data=data,
grid_params=[3080, 4.9, 0],
Av=0,
global_cov=dict(log_amp=-11, log_ls=2)) #We want our global_cov:log_amp to be reasonable, so pay attention to the 𝜎-contours in the residuals plots.)
model

priors = {
"T": st.norm(3050, 20),
"logg": st.norm(4.9, 0.0068),
"Z": st.uniform(-0.5, 0.5),
"Av": st.halfnorm(0, 0.2),
"global_cov:log_amp": st.norm(-11, 3),
"global_cov:log_ls": st.uniform(0, 10),
}

@AustenWallis
Copy link

AustenWallis commented Feb 6, 2023

A log_amp value of -11 is okay for the example spectrum given in 'single.ipynb' where the flux values are around ~6x10^-1. Your flux is 1x10^-19, trying changing the log_amp to around -30 (equally with the prior)? My best guess is just playing with this number until you see scale in the residuals appearing.

@gully
Copy link
Collaborator

gully commented Feb 10, 2023

Yay, glad this issue is resolved. And yes, what @AustenWallis said. If you have absolute flux units the absolute value of your noise model terms will have to be adjusted to be at least in the same order of magnitude for initialization. I'm inclined to close this Issue since the proposed solutions have been shown to work, and there is no outstanding bug. @astro-catherine if you are still experiencing problems please reopen the Issue or make a new Issue with any revised friction points. Thank you all 🙏

@gully gully closed this as completed Feb 10, 2023
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

No branches or pull requests

5 participants