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

Interactive plot #46

Merged
merged 5 commits into from
Aug 12, 2024
Merged

Interactive plot #46

merged 5 commits into from
Aug 12, 2024

Conversation

robjmcgibbon
Copy link
Contributor

I added a method to allow for visualisation of the effect of varying parameter values on the emulator predictions. Maybe visualisation.py would be a better place to put it though.

Screenshot from 2024-02-06 11-45-17

I tested this by adding a single line (schecter_emulator.interactive_plot(predict_x, xlabel='Stellar mass', ylabel='dn/dlogM')) to the end of the getting started example. If you decide to merge this then I'd need to add it an example somewhere in the documentation.

The plot is pretty responsive for me when testing with two parameters. For a large emulator model this might not be the case though, as the emulator has to make a prediction every time you move the slider.

The axis limits of the plot are set by the initial values. This means that the line can move off the plot, but I think resizing the plot would make it more difficult to see the effect of varying the parameters.

It would be nice to save the plot as an html/javascript for sharing. In the past I've used the bokeh package for these kind of plots, but I didn't want to add another dependency.

@robjmcgibbon
Copy link
Contributor Author

Running the formatter also edited multi_gaussian_process.py and swift.py

Copy link
Collaborator

@Moyoxkit Moyoxkit left a comment

Choose a reason for hiding this comment

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

I really like this addition, these sort of visualisations also really nicely highlight the use of the emulators! I have some minor comments, only on some of the phrasing. After fixing these I'll be happy to merge.

to try an interactive plot. Every emulator object contains an
`interactive_plot` method. This generates a plot with a slider
for each parameter. The plot will update to show the emulator
predictions when sliders are adjusted.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a line that explains the default reference line.

.. image:: interactive_plot.png

It is possible to pass reference data to be plotted when calling
:meth:`swiftemulator.emulators.base.BaseEmulator.interactive\_plot`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you could add this to the example? Similar to the previous comment I would at least mention the reference line and/or the extra datapoints

"""
Generates an interactive plot which displays the emulator predictions.
If no reference data is passed to be overplotted then the plot will
display a line which corresponds to the predictions for the mean
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it the mean or the midpoint of the ranges? (also out of curiosity, I guess it's the same for uniform points)

name = model_specification.parameter_names[i]
lo_lim = sorted(model_specification.parameter_limits[i])[0]
hi_lim = sorted(model_specification.parameter_limits[i])[1]
param_means[name] = (lo_lim + hi_lim) / 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe refer to it as midpoints as that is more correct (also clarifies my earlier comment)

@Moyoxkit
Copy link
Collaborator

Moyoxkit commented Feb 6, 2024

Just thinking about it now, just like for the parameter sweeps it might be nice to be able to give it a reference set of parameters (in case you have already done a fit for example). Not super important for when you compare with external points, but it could provide a nicer "default" comparison line

@Moyoxkit
Copy link
Collaborator

Moyoxkit commented Feb 6, 2024

@EvgeniiChaikin maybe this is also interesting for you to look at and see if you have suggestions

@robjmcgibbon
Copy link
Contributor Author

Just thinking about it now, just like for the parameter sweeps it might be nice to be able to give it a reference set of parameters (in case you have already done a fit for example). Not super important for when you compare with external points, but it could provide a nicer "default" comparison line

I've implemented that, along with the documentation changes you suggested

@JBorrow JBorrow merged commit cebb4fd into SWIFTSIM:main Aug 12, 2024
5 checks passed
@JBorrow
Copy link
Member

JBorrow commented Aug 12, 2024

Thanks for this!

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