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

Make it easy to fix values of parameters in a configuration #117

Closed
musoke opened this issue May 3, 2023 · 2 comments
Closed

Make it easy to fix values of parameters in a configuration #117

musoke opened this issue May 3, 2023 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@musoke
Copy link
Contributor

musoke commented May 3, 2023

I have created a configuration file in which some of the parameters are random.

I want to generate some images in which the random parameters are set to known, fixed values. I am envisioning being able to write something along the lines of

import deeplenstronomy.deeplenstronomy as dl
import yaml

with open("dls_config.yaml", "r") as stream:
    try:
        config = yaml.safe_load(stream)
    except yaml.YAMLError as exc:
        raise exc

fixed_params = [
  {"path": ['PLANE_1', 'OBJECT_1', 'MASS_PROFILE_1', 'Rs'], "value":1.0},
  {"path": ['PLANE_1', 'OBJECT_1', 'MASS_PROFILE_1', 'alpha_Rs'], "value":1.0},
]

dl.make_dataset(config, param_overrides=fixed_params)
@musoke musoke changed the title make it easy to generate a sim dict with fix values of random parameters make it easy to fix values of random parameters in a configuration May 10, 2023
@musoke musoke changed the title make it easy to fix values of random parameters in a configuration DLS: make it easy to fix values of random parameters in a configuration May 22, 2023
@musoke musoke changed the title DLS: make it easy to fix values of random parameters in a configuration Make it easy to fix values of parameters in a configuration May 22, 2023
@Jasonpoh Jasonpoh self-assigned this May 29, 2023
@Jasonpoh Jasonpoh added the question Further information is requested label May 29, 2023
@Jasonpoh
Copy link
Contributor

There are currently two ways to fix parameters in a configuration:

1) Fix those values directly in the yaml file.

This is a bit clunky, but you could duplicate that yaml file and fix those values directly in the yaml file and generate a second dataset with those fixed model parameters.

2) Use Dataset.update_param

The Dataset object has a method update_param which allows you to update parameters to new values. For example:

model.update_param({'PLANE_1-OBJECT_1-MASS_PROFILE_1-theta_E-g': 2}, 'CONFIGURATION_1')

Changes the Einstein radius of all my PLANE_1, OBJECT_1, MASS_PROFILE_1 objects to 2. Follow this up with:

model.regenerate()

which will take the updated parameter dictionaries to regenerate an updated dataset including images.

I think method 2 is very similar to what you suggested. Let me know if this solves your requirements!

@musoke
Copy link
Contributor Author

musoke commented May 30, 2023

@Jasonpoh, thank you for the reply.

I ended up doing what you describe in 1).

  1. is indeed quite similar to what wanted, the main difference being that the data set is generated first. I may use that in future if it works for me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants