Skip to content

MAKING PREDICTIONS WITH LACE

Loading a predefined emulator

The easiest way to load an emulator is to use the set_emulator class. This can be done with an archive or a training set. This will load a trained emulator with the specifications of the emulator label.

archive = gadget_archive.GadgetArchive(postproc="Pedersen21")
emulator = set_emulator(
        emulator_label="Pedersen23_ext",
        archive=archive,
    )
archive = gadget_archive.GadgetArchive(postproc="Pedersen21")
emulator = set_emulator(
        emulator_label="Pedersen23_ext",
        training_set="Pedersen21",
    )

The supported emulators can be found in the Emulators_trainingSets.md file.

Loading a custom emulator

Another option is to load an emulator model that does not correspond to a predifined emulator label. This can be done by, for example:

emulator = NNEmulator(training_set='Cabayol23', 
            emulator_label='Cabayol23+',
            model_path='path/to/model.pt',
            drop_sim=None,
            train=False)

where model_path is the path to the .pt file containing the trained model and train=False indicates that the model is not being trained. In the model you are loading has been trained by dropping simulations, you should specify which simulations to drop using the drop_sim argument.

Making predictions

To emulate the P1D of a simulation, you can use the emulate_p1d_Mpc method. This method requires a dictionary containing the simulation parameters.

p1d = emulator.emulate_p1d_Mpc(sim_params, k_Mpc)

Predicitng from a config file

One can also make predictions and plot them by using the predict.py script in the scripts folder. This script allows to make predictions on a test set, plot the P1D errors and save the predictions. An example of how to use this script is:

bash python python bin/predict.py --config config_files/config_predict.yaml Similarly to the training script, the config file accepts the following fields:

There are two ways of loading an emulator: 1. By providing an emulator label (see list of supported emulators here) - emulator_type: Choose between "NN" (neural network) or "GP" (Gaussian process) emulator - emulator_label: Label of the predefined model to use (see list of supported emulators here) - drop_sim: Simulation to exclude from training (optional) - archive: Configuration for loading simulation archive - file: "Nyx" or "Gadget" - version: Version of the simulation archive - sim_test: Label of the test simulation to use for predictions. See list of available simulations here. - average_over_z: Whether to average P1D errors over redshift (true/false) - save_plot_path: Path where to save the validation plot. If None, the plot is not saved. - save_predictions_path: Path where to save the predictions. If None, the predictions are not saved.

  1. By providing a path to the directory containing the trained model (this directory should contain the .pt file.
  2. emulator_type: Choose between "NN" (neural network) or "GP" (Gaussian process) emulator
  3. drop_sim: Simulation to exclude from training (optional)
  4. archive: Configuration for loading simulation archive
  5. file: "Nyx" or "Gadget"
  6. version: Version of the simulation archive
  7. sim_test: Label of the test simulation to use for predictions. See list of available simulations here.
  8. emulator_params: List of parameters used by the emulator. The default is ["Delta2_p", "n_p", "alpha_p", "sigT_Mpc", "gamma", "kF_Mpc"].
  9. average_over_z: Whether to average P1D errors over redshift (true/false)
  10. save_plot_path: Path where to save the validation plot. If None, the plot is not saved.
  11. save_predictions_path: Path where to save the predictions. If None, the predictions are not saved.
  12. hyperparameters: Dictionary containing the hyperparameters of the emulator. This will be used ONLY if emulator_label is not provided.
  13. model_path: Path to the directory containing the trained model (this directory should contain the .pt file).