NDEs

colfi.element

colfi.element.CELU()[source]
colfi.element.ELU()[source]
class colfi.element.ELU_1[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
colfi.element.LeakyReLU()[source]
colfi.element.LogSigmoid()[source]
colfi.element.PReLU()[source]
colfi.element.RReLU()[source]
colfi.element.ReLU()[source]
colfi.element.ReLU6()[source]
colfi.element.SELU()[source]
colfi.element.SiLU()[source]
colfi.element.Sigmoid()[source]
class colfi.element.Sigmoid_1[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
colfi.element.Softplus()[source]
class colfi.element.Softplus_1[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.element.Softplus_2[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
colfi.element.Softsign()[source]
colfi.element.Tanh()[source]
colfi.element.Tanhshrink()[source]
colfi.element.activation(activation_name='RReLU')[source]

Activation functions.

Parameters:

activation_name (str, optional) – The name of activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’. Default: ‘RReLU’

Returns:

Activation function.

Return type:

object

colfi.element.avgPool1d(kernel_size)[source]
colfi.element.avgPool2d(kernel_size)[source]
colfi.element.avgPool3d(kernel_size)[source]
colfi.element.dropout()[source]
colfi.element.dropout2d()[source]
colfi.element.dropout3d()[source]
colfi.element.elu_1()[source]
colfi.element.get_dropout(drouput_name='dropout')[source]

Get the dropout.

colfi.element.maxPool1d(kernel_size)[source]
colfi.element.maxPool2d(kernel_size)[source]
colfi.element.maxPool3d(kernel_size)[source]
colfi.element.pooling(pool_name='maxPool2d', kernel_size=2)[source]
colfi.element.sigmoid_1()[source]
colfi.element.softplus_1()[source]
colfi.element.softplus_2()[source]

colfi.nodeframe

colfi.nodeframe.decreasingNode(node_in=1970, node_out=5, hidden_layer=3, get_allNode=True)[source]

A network structure that the number of neurons in each hidden layer is decreased proportionally.

Parameters:
  • node_in (int) – The number of nodes in the input layer.

  • node_out (int) – The number of nodes in the output layer.

  • hidden_layer (int) – The number of the hidden layers.

  • get_allNode (bool) – If True, return the number of nodes of all layers, otherwise, only return the number of nodes of hidden layers. Default: True

Returns:

A list that contains the number of nodes in each layer.

Return type:

list

colfi.sequence

class colfi.sequence.Activation[source]

Bases: object

Activation functions, to be used by class LinearSeq.

class colfi.sequence.BatchNorm[source]

Bases: object

Batch Normalization, to be used by class LinearSeq.

class colfi.sequence.Dropout[source]

Bases: object

Dropout, to be used by class LinearSeq.

class colfi.sequence.LinearSeq(nodes, mainBN=True, finalBN=False, mainActive='rrelu', finalActive='None', mainDropout='None', finalDropout='None')[source]

Bases: SeqName, BatchNorm, Activation, Dropout

Sequence of Linear.

Parameters:
  • nodes (list) – A list that contains the number of nodes in each layer.

  • mainBN (bool, optional) – If True, the network will contain batch normalization layer in its main part. Default: True

  • finalBN (bool, optional) – If True, the network will contain batch normalization layer in its last layer. Default: False

  • mainActive (str, optional) – The activation function used in the main part of the network. See activation() for the available activation functions. Default: ‘rrelu’

  • finalActive (str, optional) – The activation function used in the last layer of the network. See activation() for the available activation functions. Default: ‘None’

  • mainDropout (str, optional) – The dropout used in the main part of the network, ‘None’ or ‘dropout’. Default: ‘None’

  • finalDropout (str, optional) – The dropout used in the final layer of the network, ‘None’ or ‘dropout’. Default: ‘None’

get_seq()[source]
class colfi.sequence.Pooling[source]

Bases: object

Pooling, to be used by classes LinearSeq & Conv2dSeq

class colfi.sequence.SeqName(module_name)[source]

Bases: object

The name of sequence, to be used by class LinearSeq.

seq_name()[source]

colfi.fcnet_ann

class colfi.fcnet_ann.FcNet(node_in=2000, node_out=6, hidden_layer=3, nodes=None, activation_func='RReLU')[source]

Bases: Module

Get a fully connected network.

Parameters:
  • node_in (int) – The number of the input nodes.

  • node_out (int) – The number of the output nodes.

  • hidden_layer (int) – The number of the hidden layers.

  • nodes (None or list, optional) – If list, it should be a collection of nodes of the network, e.g. [node_in, node_hidden1, node_hidden2, …, node_out]

  • activation_func (str, optional) – Activation function. See activation(). Default: ‘RReLU’

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_ann.MultiBranchFcNet(nodes_in=[100, 100, 20], node_out=6, branch_hiddenLayer=1, trunk_hiddenLayer=3, nodes_all=None, activation_func='RReLU')[source]

Bases: Module

Get a multibranch network.

Parameters:
  • nodes_in (list) – The number of the input nodes for each branch. e.g. [node_in_branch1, node_in_branch2, …]

  • node_out (int) – The number of the output nodes.

  • branch_hiddenLayer (int) – The number of the hidden layers for the branch part.

  • trunk_hiddenLayer (int) – The number of the hidden layers for the trunk part.

  • nodes_all (list, optional) – The number of nodes of the multibranch network. e.g. [nodes_branch1, nodes_branch2, …, nodes_trunk]

  • activation_func (str, optional) – Activation function. See activation(). Default: ‘RReLU’

forward(x_all)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_ann.MultiBranchFcNet_MC(node_in=6, nodes_out=[100, 100, 20], trunk_hiddenLayer=3, branch_hiddenLayer=1, nodes_all=None, activation_func='RReLU')[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_ann.MultiBranchFcNet_test(nodes_in=[100, 100, 20], node_out=6, branch_hiddenLayer=1, trunk_hiddenLayer=3, nodes_all=None, activation_func='RReLU')[source]

Bases: Module

Get a multibranch network.

Parameters:
  • nodes_in (list) – The number of the input nodes for each branch. e.g. [node_in_branch1, node_in_branch2, …]

  • node_out (int) – The number of the output nodes.

  • branch_hiddenLayer (int) – The number of the hidden layers for the branch part.

  • trunk_hiddenLayer (int) – The number of the hidden layers for the trunk part.

  • nodes_all (list, optional) – The number of nodes of the multibranch network. e.g. [nodes_branch1, nodes_branch2, …, nodes_trunk]

  • activation_func (str, optional) – Activation function. See activation(). Default: ‘RReLU’

forward(x_all)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
colfi.fcnet_ann.loss_funcs(name='L1')[source]

Some loss functions.

Parameters:

name (str, optional) – Abbreviation of loss function name, which can be ‘L1’, ‘MSE’, or ‘SmoothL1’. Default: ‘L1’.

Returns:

The corresponding loss function.

Return type:

object

colfi.fcnet_ann.split_nodes(nodes, weight=[])[source]

colfi.fcnet_mdn

class colfi.fcnet_mdn.BetaMDN(node_in=100, node_out=1, hidden_layer=3, comp_n=3, nodes=None, activation_func='Softplus')[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_mdn.Branch[source]

Bases: Module

training: bool
class colfi.fcnet_mdn.GaussianMDN(node_in=100, node_out=1, hidden_layer=3, comp_n=3, nodes=None, activation_func='Softplus')[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_mdn.MultiBranchBetaMDN(nodes_in=[100, 100, 100], node_out=2, branch_hiddenLayer=1, trunk_hiddenLayer=1, comp_n=3, nodes_all=None, activation_func='Softplus')[source]

Bases: Module

forward(x_all)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_mdn.MultiBranchGaussianMDN(nodes_in=[100, 100, 100], node_out=2, branch_hiddenLayer=1, trunk_hiddenLayer=1, comp_n=3, nodes_all=None, activation_func='Softplus')[source]

Bases: Module

forward(x_all)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_mdn.MultiBranchMultivariateGaussianMDN(nodes_in=[100, 100, 100], node_out=2, branch_hiddenLayer=1, trunk_hiddenLayer=1, comp_n=3, nodes_all=None, activation_func='Softplus')[source]

Bases: Module

forward(x_all)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_mdn.MultivariateGaussianMDN(node_in=100, node_out=2, hidden_layer=3, comp_n=3, nodes=None, activation_func='Softplus')[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_mdn.MultivariateGaussianMDN_AvgMu(node_in=100, node_out=2, hidden_layer=3, comp_n=3, nodes=None, activation_func='Softplus')[source]

Bases: Module

The difference between this class and MultivariateGaussianMDN_AvgMultiNoise is that only the mu and w of the mixture model are averaged.

forward(x, multi_noise=1)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_mdn.MultivariateGaussianMDN_AvgMultiNoise(node_in=100, node_out=2, hidden_layer=3, comp_n=3, nodes=None, activation_func='Softplus')[source]

Bases: Module

The difference between this class and MultivariateGaussianMDN is the forward function, where outputs caused by multiple noises are averaged.

forward(x, multi_noise=1)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
colfi.fcnet_mdn.beta_PDF(alpha, beta, target, log=True)[source]

https://zh.wikipedia.org/wiki/%CE%92%E5%88%86%E5%B8%83

return: x^(alpha-1) (1-x)^(beta-1) Gamma(alpha+beta) / Gamma(alpha)/Gamma(beta), where Gamma is the Gamma function

Note: target > 0 & 1-target > 0, so, 0 < target < 1, so, should use minmax normalization

colfi.fcnet_mdn.beta_loss(omega, alpha, beta, target, logsumexp=True)[source]
colfi.fcnet_mdn.beta_sampler(omega, alpha, beta, chain_leng=10000)[source]
colfi.fcnet_mdn.gaussian_PDF(mu, sigma, target, log=True)[source]

https://en.wikipedia.org/wiki/Normal_distribution

return:

colfi.fcnet_mdn.gaussian_loss(omega, mu, sigma, target, logsumexp=True)[source]

torch.logsumexp will help us to avoid a lot of numerical instabilities in the training process, see: https://deep-and-shallow.com/2021/03/20/mixture-density-networks-probabilistic-regression-for-uncertainty-estimation/

Note: It is better to set logsumexp=True

colfi.fcnet_mdn.gaussian_sampler(omega, mu, sigma, chain_leng=10000)[source]

Draw samples from a MoG.

colfi.fcnet_mdn.loss_funcs(comp_type, params_n)[source]
colfi.fcnet_mdn.multivariateGaussian_PDF(mu, cholesky_factor, target, log=True)[source]
colfi.fcnet_mdn.multivariateGaussian_loss(omega, mu, cholesky_factor, target, logsumexp=True)[source]

Calculates the error, given the MoG parameters and the target

The loss is the negative log likelihood of the data given the MoG parameters.

torch.logsumexp will help us to avoid a lot of numerical instabilities in training see: https://deep-and-shallow.com/2021/03/20/mixture-density-networks-probabilistic-regression-for-uncertainty-estimation/

colfi.fcnet_mdn.multivariateGaussian_sampler(omega, mu, cholesky_factor, chain_leng=10000)[source]
colfi.fcnet_mdn.samplers(comp_type, params_n)[source]

colfi.fcnet_g

class colfi.fcnet_g.Branch[source]

Bases: Module

training: bool
class colfi.fcnet_g.MLPGaussian(node_in=100, node_out=1, hidden_layer=3, nodes=None, activation_func='Softplus')[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_g.MLPMultivariateGaussian(node_in=100, node_out=2, hidden_layer=3, nodes=None, activation_func='Softplus')[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_g.MLPMultivariateGaussian_AvgMultiNoise(node_in=100, node_out=2, hidden_layer=3, nodes=None, activation_func='Softplus')[source]

Bases: Module

forward(x, multi_noise=1)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_g.MultiBranchMLPGaussian(nodes_in=[100, 100, 100], node_out=2, branch_hiddenLayer=1, trunk_hiddenLayer=1, nodes_all=None, activation_func='Softplus')[source]

Bases: Module

forward(x_all)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class colfi.fcnet_g.MultiBranchMLPMultivariateGaussian(nodes_in=[100, 100, 100], node_out=2, branch_hiddenLayer=1, trunk_hiddenLayer=1, nodes_all=None, activation_func='Softplus')[source]

Bases: Module

forward(x_all)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
colfi.fcnet_g.gaussian_loss(params, sigma, target)[source]

https://en.wikipedia.org/wiki/Normal_distribution

return:

colfi.fcnet_g.loss_funcs(params_n)[source]
colfi.fcnet_g.multivariateGaussian_loss(params, cholesky_factor, target)[source]

colfi.models_ann

class colfi.models_ann.Loader(path='ann', randn_num=0.123)[source]

Bases: object

Load the saved networks.

load_chain()[source]
load_chain_ann()[source]
load_hparams()[source]
load_loss()[source]
load_ndeType(raise_err=False)[source]
load_net()[source]
class colfi.models_ann.MultiBranchMLP(train_set, param_names, vali_set=[None, None], obs_errors=None, cov_matrix=None, params_dict=None, branch_hiddenLayer=1, trunk_hiddenLayer=2, activation_func='Softplus', loss_name='L1', noise_type='multiNormal', factor_sigma=0.2, multi_noise=5)[source]

Bases: OneBranchMLP

Predict cosmological parameters with multibranch network for multiple sets of datasets.

Parameters:
  • train_set (list) – The training set that contains simulated observations (measurements) which is a list observations with shape [(N,obs_length_1), (N,obs_length_2), …] and simulated parameters of a specific cosmological (or theoretical) model. i.e. [observations, parameters]

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • vali_set (list, optional) – The validation set that contains simulated observations (measurements) which is a list observations with shape [(N,obs_length_1), (N,obs_length_2), …] and simulated parameters of a specific cosmological (or theoretical) model. The validation set can also be set to None. i.e. [observations, parameters] or [None, None]. Default: [None, None]

  • obs_errors (None or list, optional) – Observational errors, it is a list of errors with shape [(obs_length_1,), (obs_length_2,), …]. If cov_matrix is set to None, the observational errors should be given. Default: None

  • cov_matrix (None or list, optional) – A list of covariance matrix with shape [(obs_length_1, obs_length_1), (obs_length_2, obs_length_2), …]. If there is no covariance for some observations, the covariance matrix should be set to None. e.g. [cov_matrix_1, None, cov_matrix_3]. If a covariance matrix is given, obs_errors will be ignored. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

  • branch_hiddenLayer (int, optional) – The number of the hidden layer for the branch part of the network. Default: 1

  • trunk_hiddenLayer (int, optional) – The number of the hidden layer for the trunk part of the network. Default: 2

  • activation_func (str, optional) – Activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’ (see activation()). Default: ‘Softplus’

  • loss_name (str, optional) – The name of loss function used in the network, which can be ‘L1’, ‘MSE’, or ‘SmoothL1’. See loss_funcs(). Default: ‘L1’

  • noise_type (str, optional) – The type of Gaussian noise added to the training set, which can be ‘singleNormal’ or ‘multiNormal’. Default: ‘multiNormal’

  • factor_sigma (float, optional) – For the case of noise_type = ‘singleNormal’, factor_sigma should be set to 1. For the case of noise_type = ‘multiNormal’, it is the standard deviation of the coefficient of the observational error (standard deviation). Default: 0.2

  • multi_noise (int, optional) – The number of realization of noise added to the measurement in one epoch. Default: 5

Variables:
  • obs_base (array-like, optional) – The base value of observations that is used for data normalization when training the network to ensure that the scaled observations are ~ 1., it is suggested to set the mean of the simulated observations. The default is the mean of the simulated observations.

  • params_base (array-like, optional) – The base value of parameters that is used for data normalization when training the network to ensure that the scaled parameters are ~ 1., it is suggested to set the mean of the posterior distribution (or the simulated parameters). The default is the mean of the simulated parameters.

  • params_space (array-like) – The parameter space with the shape of (n, 2), where n is the number of parameters. For each parameter, it is: [lower_limit, upper_limit].

  • lr (float, optional) – The learning rate setting of the network. Default: 1e-2

  • lr_branch (float, optional) – The learning rate setting of the branch part. Default: 1e-2

  • lr_min (float, optional) – The minimum of the learning rate. Default: 1e-8

  • batch_size (int, optional) – The batch size setting of the network. Default: 1250

  • auto_batchSize (bool, optional) – If True, the batch size will be set automatically in the training process, otherwise, use the setting of batch_size. Default: False

  • epoch (int, optional) – The number of epoch of the training process. Default: 2000

  • epoch_branch (int, optional) – The number of epoch for the branch part. This only works when training the branch part. Default: 2000

  • base_epoch (int, optional) – The base number (or the minimum number) of epoch. Default: 1000

  • auto_epoch (bool, optional) – If True, the epoch will be set automatically in the training process, otherwise, use the setting of epoch. Default: False

  • print_info (bool, optional) – If True, will print the information of the network. Default: False

  • scale_obs (bool, optional) – If True, the input data (measurements) will be scaled based on the base values of the data. Default: True

  • scale_params (bool, optional) – If True, the target data (cosmological parameters) will be scaled based on the base values of parameters. See DataPreprocessing. Default: True

  • norm_obs (bool, optional) – If True, the input data (measurements) of the network will be normalized. Default: True

  • norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized. Default: True

  • independent_norm_obs (bool, optional) – If True, the measurements will be normalized independently. This only works when norm_obs=True. Default: False

  • independent_norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized independently. This only works when norm_params=True. Default: True

  • norm_type (str, optional) – The method of normalization, which can be ‘z_score’, ‘minmax’, or ‘mean’ (see Normalize). Default: ‘z_score’

  • spaceSigma_min (int, optional) – The minimum parameter space to be learned, e.g. for spaceSigma_min=5, the parameter space to be learned is \([-5\sigma, +5\sigma]\). Default: 5

  • burnInEnd (bool, optional) – If True, it is the end of the burn-in phase, which means the ANN chain has reached a stable state. Default: False

  • burnInEnd_step (None or int, optional) – The burn-in end step. If None, it means the burn-in phase not end. Default: None

  • transfer_learning (bool, optional) – If True, the network will be initialized using the well-trained network of the previous step. Default: False

  • randn_num (float or str, optional) – A random number that identifies the saved results. Default: float

  • nde_type (str, optional) – A string that indicate which NDE is used, which should be ‘ANN’.

  • file_identity_str (str, optional) – A string that identifies the files saved to the disk, which is useful to identify the saved files. Default: ‘’

Note

It is suggested to set lr and lr_branch the same value.

predict(obs, in_type='numpy')[source]
predict_chain(obs_data, cov_matrix=None, chain_leng=10000)[source]
train(repeat_n=3, showEpoch_n=100, train_branch=False, parallel=True, train_trunk=False, fix_lr=0.0001, reduce_fix_lr=False, fast_training=False)[source]

Train the network.

Parameters:
  • repeat_n (int, optional) – The number of repeat feed to the network for each batch size data, which will increase the number of iterations in each epoch. Default: 3

  • showEpoch_n (int, optional) – The number of epoch that show the training information. Default: 100

  • fast_training (bool, optional) – If True, the batch size will be set to batch_size*multi_noise and the network will be trained fast. If False, the network will be slowly trained to get better. Default: False

Returns:

  • object – The network object.

  • array-like – The losses of training set and validation set.

train_branch_trunk(repeat_n=3, showEpoch_n=100, train_branch_trunk=True, fast_training=False)[source]
transfer_branchNet(device=None)[source]
class colfi.models_ann.OneBranchMLP(train_set, param_names, vali_set=[None, None], obs_errors=None, cov_matrix=None, params_dict=None, hidden_layer=3, activation_func='Softplus', loss_name='L1', noise_type='multiNormal', factor_sigma=0.2, multi_noise=5)[source]

Bases: Transfer, DataPreprocessing, CutParams

Predict cosmological parameters with multilayer perceptron (MLP) for one set of datasets.

Parameters:
  • train_set (list) – The training set that contains simulated observations (measurements) with shape (N, obs_length) and simulated parameters of a specific cosmological (or theoretical) model. i.e. [observations, parameters]

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • vali_set (list, optional) – The validation set that contains simulated observations (measurements) with shape (N, obs_length) and simulated parameters of a specific cosmological (or theoretical) model, i.e. [observations, parameters]. The validation set can also be set to None, i.e. [None, None]. Default: [None, None]

  • obs_errors (None or array-like, optional) – Observational errors with shape (obs_length,). If cov_matrix is set to None, the observational errors should be given. Default: None

  • cov_matrix (None or array-like, optional) – Covariance matrix of the observational data. If a covariance matrix is given, obs_errors will be ignored. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

  • hidden_layer (int, optional) – The number of the hidden layer of the network. Default: 3

  • activation_func (str, optional) – Activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’ (see activation()). Default: ‘Softplus’

  • loss_name (str, optional) – The name of loss function used in the network, which can be ‘L1’, ‘MSE’, or ‘SmoothL1’. See loss_funcs(). Default: ‘L1’

  • noise_type (str, optional) – The type of Gaussian noise added to the training set, which can be ‘singleNormal’ or ‘multiNormal’. Default: ‘multiNormal’

  • factor_sigma (float, optional) – For the case of noise_type = ‘singleNormal’, factor_sigma should be set to 1. For the case of noise_type = ‘multiNormal’, it is the standard deviation of the coefficient of the observational error (standard deviation). Default: 0.2

  • multi_noise (int, optional) – The number of realization of noise added to the measurement in one epoch. Default: 5

Variables:
  • obs_base (array-like, optional) – The base value of observations that is used for data normalization when training the network to ensure that the scaled observations are ~ 1., it is suggested to set the mean of the simulated observations. The default is the mean of the simulated observations.

  • params_base (array-like, optional) – The base value of parameters that is used for data normalization when training the network to ensure that the scaled parameters are ~ 1., it is suggested to set the mean of the posterior distribution (or the simulated parameters). The default is the mean of the simulated parameters.

  • params_space (array-like) – The parameter space with the shape of (n, 2), where n is the number of parameters. For each parameter, it is: [lower_limit, upper_limit].

  • lr (float, optional) – The learning rate setting of the network. Default: 1e-2

  • lr_min (float, optional) – The minimum of the learning rate. Default: 1e-8

  • batch_size (int, optional) – The batch size setting of the network. Default: 1250

  • auto_batchSize (bool, optional) – If True, the batch size will be set automatically in the training process, otherwise, use the setting of batch_size. Default: False

  • epoch (int, optional) – The number of epoch of the training process. Default: 2000

  • base_epoch (int, optional) – The base number (or the minimum number) of epoch. Default: 1000

  • auto_epoch (bool, optional) – If True, the epoch will be set automatically in the training process, otherwise, use the setting of epoch. Default: False

  • print_info (bool, optional) – If True, will print the information of the network. Default: False

  • scale_obs (bool, optional) – If True, the input data (measurements) will be scaled based on the base values of the data. Default: False

  • scale_params (bool, optional) – If True, the target data (cosmological parameters) will be scaled based on the base values of parameters. See DataPreprocessing. Default: True

  • norm_obs (bool, optional) – If True, the input data (measurements) of the network will be normalized. Default: True

  • norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized. Default: True

  • independent_norm_obs (bool, optional) – If True, the measurements will be normalized independently. This only works when norm_obs=True. Default: False

  • independent_norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized independently. This only works when norm_params=True. Default: True

  • norm_type (str, optional) – The method of normalization, which can be ‘z_score’, ‘minmax’, or ‘mean’ (see Normalize). Default: ‘z_score’

  • spaceSigma_min (int, optional) – The minimum parameter space to be learned, e.g. for spaceSigma_min=5, the parameter space to be learned is \([-5\sigma, +5\sigma]\). Default: 5

  • burnInEnd (bool, optional) – If True, it is the end of the burn-in phase, which means the ANN chain has reached a stable state. Default: False

  • burnInEnd_step (None or int, optional) – The burn-in end step. If None, it means the burn-in phase not end. Default: None

  • transfer_learning (bool, optional) – If True, the network will be initialized using the well-trained network of the previous step. Default: False

  • randn_num (float or str, optional) – A random number that identifies the saved results. Default: float

  • nde_type (str, optional) – A string that indicate which NDE is used, which should be ‘ANN’.

  • file_identity_str (str, optional) – A string that identifies the files saved to the disk, which is useful to identify the saved files. Default: ‘’

copyLayers_fromTrainedNet()[source]
load_wellTrainedNet(path='ann', randn_num='0.123')[source]
plot_contour(smooth=3, fill_contours=False, chain_true=None, label_true='True')[source]
plot_loss(alpha=0.6, show_logLoss=False, title_labels='', show_minLoss=True)[source]
predict(obs, use_GPU=False, in_type='numpy')[source]
predict_chain(obs_data, cov_matrix=None, chain_leng=10000, use_GPU=False)[source]
predict_params(sim_obs, use_GPU=False)[source]
print_loss()[source]
save_chain(path='ann')[source]
save_hparams(path='ann')[source]
save_loss(path='ann')[source]
save_ndeType(path='ann')[source]
save_net(path='ann', middle_save=False)[source]
property statistic_dim_obs
property statistic_dim_params
train(repeat_n=3, showEpoch_n=100, fast_training=False)[source]

Train the network.

Parameters:
  • repeat_n (int, optional) – The number of repeat feed to the network for each batch size data, which will increase the number of iterations in each epoch. Default: 3

  • showEpoch_n (int, optional) – The number of epoch that show the training information. Default: 100

  • fast_training (bool, optional) – If True, the batch size will be set to batch_size*multi_noise and the network will be trained fast. If False, the network will be slowly trained to get better. Default: False

Returns:

  • object – The network object.

  • array-like – The losses of training set and validation set.

class colfi.models_ann.OptimizeMLP(sim_data, obs_data, param_names, cov_matrix=None, params_dict=None)[source]

Bases: object

Train networks and predict cosmological parameters using the given simulated data.

Parameters:
  • sim_data (array-like or list) – The simulated data.

  • obs_data (array-like or list) – The observational data.

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • cov_matrix (array-like, list, or None, optional) – Covariance matrix of the observational data. It should be an array with shape (obs_length, obs_length), or a list of covariance matrix with shape [(obs_length_1, obs_length_1), (obs_length_2, obs_length_2), …]. If there is no covariance for some observations, the covariance matrix should be set to None. e.g. [cov_matrix_1, None, cov_matrix_3]. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

Variables:

chain_leng (int, optional) – The length of each ANN chain. Default: 10000

Note

A lot of networks can be trained using the given simulated data, therefore, this class can be used to test the effect of hyperparameters of the network.

auto_train(repeat_net=100, procs_n=5, path='ann', save_details=True, **hparams)[source]

Automatically train several networks for the given hyperparameters.

Parameters:
  • repeat_net (int, optional) – The number of times a network is repeatedly trained with the same data and hyperparameters.

  • procs_n (int, optional) – The number of processes.

  • path (str, optional) – The path of the results to be saved. Default: ‘ann’

  • save_details (bool, optional) – If True, will save the items for each network. Default: True

  • **hparams (dict) – A dictionary with only one item, whose value is a list that contains several hyperparameters used to train several networks.

Return type:

None.

property cov_copy
get_sets(num_train, num_vali)[source]
property obs_errors
class colfi.models_ann.PredictMBMLP(path='ann', randn_num='0.123')[source]

Bases: MultiBranchMLP, Loader

Repredict cosmological parameters using the saved networks.

Parameters:
  • path (str) – The path of the results saved. Default: ‘ann’

  • randn_num (str or int) – A random number that identifies the saved results.

class colfi.models_ann.PredictOBMLP(path='ann', randn_num='0.123')[source]

Bases: OneBranchMLP, Loader

Repredict cosmological parameters using the saved networks.

Parameters:
  • path (str) – The path of the results saved. Default: ‘ann’

  • randn_num (str or int) – A random number that identifies the saved results.

colfi.models_mdn

class colfi.models_mdn.CheckNormType(comp_type='Gaussian', norm_params='z_score')[source]

Bases: object

check_normType()[source]
class colfi.models_mdn.MultiBranchMDN(train_set, param_names, vali_set=[None, None], obs_errors=None, cov_matrix=None, params_dict=None, comp_type='Gaussian', comp_n=3, branch_hiddenLayer=1, trunk_hiddenLayer=2, activation_func='Softplus', noise_type='singleNormal', factor_sigma=1, multi_noise=5)[source]

Bases: MultiBranchMLP, CheckNormType

Predict cosmological parameters with multibranch MDN for multiple sets of datasets.

Parameters:
  • train_set (list) – The training set that contains simulated observations (measurements) which is a list observations with shape [(N,obs_length_1), (N,obs_length_2), …] and simulated parameters of a specific cosmological (or theoretical) model. i.e. [observations, parameters]

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • vali_set (list, optional) – The validation set that contains simulated observations (measurements) which is a list observations with shape [(N,obs_length_1), (N,obs_length_2), …] and simulated parameters of a specific cosmological (or theoretical) model. The validation set can also be set to None. i.e. [observations, parameters] or [None, None]. Default: [None, None]

  • obs_errors (None or list, optional) – Observational errors, it is a list of errors with shape [(obs_length_1,), (obs_length_2,), …]. If cov_matrix is set to None, the observational errors should be given. Default: None

  • cov_matrix (None or list, optional) – A list of covariance matrix with shape [(obs_length_1, obs_length_1), (obs_length_2, obs_length_2), …]. If there is no covariance for some observations, the covariance matrix should be set to None. e.g. [cov_matrix_1, None, cov_matrix_3]. If a covariance matrix is given, obs_errors will be ignored. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

  • comp_type (str, optional) – The name of component used in the MDN method, which can be ‘Gaussian’ or ‘Beta’. Default: ‘Gaussian’

  • comp_n (int, optional) – The number of components used in the MDN method. Default: 3

  • branch_hiddenLayer (int, optional) – The number of the hidden layer for the branch part of the network. Default: 1

  • trunk_hiddenLayer (int, optional) – The number of the hidden layer for the trunk part of the network. Default: 2

  • activation_func (str, optional) – Activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’ (see activation()). Default: ‘Softplus’

  • noise_type (str, optional) – The type of Gaussian noise added to the training set, which should be ‘singleNormal’. Default: ‘singleNormal’

  • factor_sigma (float, optional) – For the case of noise_type = ‘singleNormal’, factor_sigma should be set to 1. Default: 1

  • multi_noise (int, optional) – The number of realization of noise added to the measurement in one epoch. Default: 5

Variables:
  • obs_base (array-like, optional) – The base value of observations that is used for data normalization when training the network to ensure that the scaled observations are ~ 1., it is suggested to set the mean of the simulated observations. The default is the mean of the simulated observations.

  • params_base (array-like, optional) – The base value of parameters that is used for data normalization when training the network to ensure that the scaled parameters are ~ 1., it is suggested to set the mean of the posterior distribution (or the simulated parameters). The default is the mean of the simulated parameters.

  • params_space (array-like) – The parameter space with the shape of (n, 2), where n is the number of parameters. For each parameter, it is: [lower_limit, upper_limit].

  • lr (float, optional) – The learning rate setting of the network. Default: 1e-2

  • lr_branch (float, optional) – The learning rate setting of the branch part. Default: 1e-2

  • lr_min (float, optional) – The minimum of the learning rate. Default: 1e-8

  • batch_size (int, optional) – The batch size setting of the network. Default: 1250

  • auto_batchSize (bool, optional) – If True, the batch size will be set automatically in the training process, otherwise, use the setting of batch_size. Default: False

  • epoch (int, optional) – The number of epoch of the training process. Default: 2000

  • epoch_branch (int, optional) – The number of epoch for the branch part. This only works when training the branch part. Default: 2000

  • base_epoch (int, optional) – The base number (or the minimum number) of epoch. Default: 1000

  • auto_epoch (bool, optional) – If True, the epoch will be set automatically in the training process, otherwise, use the setting of epoch. Default: False

  • print_info (bool, optional) – If True, will print the information of the network. Default: False

  • scale_obs (bool, optional) – If True, the input data (measurements) will be scaled based on the base values of the data. Default: True

  • scale_params (bool, optional) – If True, the target data (cosmological parameters) will be scaled based on the base values of parameters. See DataPreprocessing. Default: True

  • norm_obs (bool, optional) – If True, the input data (measurements) of the network will be normalized. Default: True

  • norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized. Default: True

  • independent_norm_obs (bool, optional) – If True, the measurements will be normalized independently. This only works when norm_obs=True. Default: False

  • independent_norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized independently. This only works when norm_params=True. Default: True

  • norm_type (str, optional) – The method of normalization, which can be ‘z_score’, ‘minmax’, or ‘mean’ (see Normalize). Default: ‘z_score’

  • spaceSigma_min (int, optional) – The minimum parameter space to be learned, e.g. for spaceSigma_min=5, the parameter space to be learned is \([-5\sigma, +5\sigma]\). Default: 5

  • burnInEnd (bool, optional) – If True, it is the end of the burn-in phase, which means the ANN chain has reached a stable state. Default: False

  • burnInEnd_step (None or int, optional) – The burn-in end step. If None, it means the burn-in phase not end. Default: None

  • transfer_learning (bool, optional) – If True, the network will be initialized using the well-trained network of the previous step. Default: False

  • randn_num (float or str, optional) – A random number that identifies the saved results. Default: float

  • nde_type (str, optional) – A string that indicate which NDE is used, which should be ‘MDN’.

  • file_identity_str (str, optional) – A string that identifies the files saved to the disk, which is useful to identify the saved files. Default: ‘’

predict_chain(obs_data, chain_leng=10000)[source]
property sampler
train(repeat_n=3, showEpoch_n=100, train_branch=False, parallel=True, train_trunk=False, fix_lr=0.0001, reduce_fix_lr=False, fast_training=False)[source]

Train the network.

Parameters:
  • repeat_n (int, optional) – The number of repeat feed to the network for each batch size data, which will increase the number of iterations in each epoch. Default: 3

  • showEpoch_n (int, optional) – The number of epoch that show the training information. Default: 100

  • fast_training (bool, optional) – If True, the batch size will be set to batch_size*multi_noise and the network will be trained fast. If False, the network will be slowly trained to get better. Default: False

Returns:

  • object – The network object.

  • array-like – The losses of training set and validation set.

class colfi.models_mdn.OneBranchMDN(train_set, param_names, vali_set=[None, None], obs_errors=None, cov_matrix=None, params_dict=None, comp_type='Gaussian', comp_n=3, hidden_layer=3, activation_func='Softplus', noise_type='singleNormal', factor_sigma=1, multi_noise=5)[source]

Bases: OneBranchMLP, CheckNormType

Predict cosmological parameters with mixture density network (MDN) for one set of datasets.

Parameters:
  • train_set (list) – The training set that contains simulated observations (measurements) with shape (N, obs_length) and simulated parameters of a specific cosmological (or theoretical) model. i.e. [observations, parameters]

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • vali_set (list, optional) – The validation set that contains simulated observations (measurements) with shape (N, obs_length) and simulated parameters of a specific cosmological (or theoretical) model, i.e. [observations, parameters]. The validation set can also be set to None, i.e. [None, None]. Default: [None, None]

  • obs_errors (None or array-like, optional) – Observational errors with shape (obs_length,). If cov_matrix is set to None, the observational errors should be given. Default: None

  • cov_matrix (None or array-like, optional) – Covariance matrix of the observational data. If a covariance matrix is given, obs_errors will be ignored. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

  • comp_type (str, optional) – The name of component used in the MDN method, which can be ‘Gaussian’ or ‘Beta’. Default: ‘Gaussian’

  • comp_n (int, optional) – The number of components used in the MDN method. Default: 3

  • hidden_layer (int, optional) – The number of the hidden layer of the network. Default: 3

  • activation_func (str, optional) – Activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’ (see activation()). Default: ‘Softplus’

  • noise_type (str, optional) – The type of Gaussian noise added to the training set, which should be ‘singleNormal’. Default: ‘singleNormal’

  • factor_sigma (float, optional) – For the case of noise_type = ‘singleNormal’, factor_sigma should be set to 1. Default: 1

  • multi_noise (int, optional) – The number of realization of noise added to the measurement in one epoch. Default: 5

Variables:
  • obs_base (array-like, optional) – The base value of observations that is used for data normalization when training the network to ensure that the scaled observations are ~ 1., it is suggested to set the mean of the simulated observations. The default is the mean of the simulated observations.

  • params_base (array-like, optional) – The base value of parameters that is used for data normalization when training the network to ensure that the scaled parameters are ~ 1., it is suggested to set the mean of the posterior distribution (or the simulated parameters). The default is the mean of the simulated parameters.

  • params_space (array-like) – The parameter space with the shape of (n, 2), where n is the number of parameters. For each parameter, it is: [lower_limit, upper_limit].

  • lr (float, optional) – The learning rate setting of the network. Default: 1e-2

  • lr_min (float, optional) – The minimum of the learning rate. Default: 1e-8

  • batch_size (int, optional) – The batch size setting of the network. Default: 1250

  • auto_batchSize (bool, optional) – If True, the batch size will be set automatically in the training process, otherwise, use the setting of batch_size. Default: False

  • epoch (int, optional) – The number of epoch of the training process. Default: 2000

  • base_epoch (int, optional) – The base number (or the minimum number) of epoch. Default: 1000

  • auto_epoch (bool, optional) – If True, the epoch will be set automatically in the training process, otherwise, use the setting of epoch. Default: False

  • print_info (bool, optional) – If True, will print the information of the network. Default: False

  • scale_obs (bool, optional) – If True, the input data (measurements) will be scaled based on the base values of the data. Default: False

  • scale_params (bool, optional) – If True, the target data (cosmological parameters) will be scaled based on the base values of parameters. See DataPreprocessing. Default: True

  • norm_obs (bool, optional) – If True, the input data (measurements) of the network will be normalized. Default: True

  • norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized. Default: True

  • independent_norm_obs (bool, optional) – If True, the measurements will be normalized independently. This only works when norm_obs=True. Default: False

  • independent_norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized independently. This only works when norm_params=True. Default: True

  • norm_type (str, optional) – The method of normalization, which can be ‘z_score’, ‘minmax’, or ‘mean’ (see Normalize). Default: ‘z_score’

  • spaceSigma_min (int, optional) – The minimum parameter space to be learned, e.g. for spaceSigma_min=5, the parameter space to be learned is \([-5\sigma, +5\sigma]\). Default: 5

  • burnInEnd (bool, optional) – If True, it is the end of the burn-in phase, which means the ANN chain has reached a stable state. Default: False

  • burnInEnd_step (None or int, optional) – The burn-in end step. If None, it means the burn-in phase not end. Default: None

  • transfer_learning (bool, optional) – If True, the network will be initialized using the well-trained network of the previous step. Default: False

  • randn_num (float or str, optional) – A random number that identifies the saved results. Default: float

  • nde_type (str, optional) – A string that indicate which NDE is used, which should be ‘MDN’.

  • file_identity_str (str, optional) – A string that identifies the files saved to the disk, which is useful to identify the saved files. Default: ‘’

predict_chain(obs_data, chain_leng=10000)[source]
property sampler
train(repeat_n=3, showEpoch_n=100, fast_training=False)[source]

Train the network.

Parameters:
  • repeat_n (int, optional) – The number of repeat feed to the network for each batch size data, which will increase the number of iterations in each epoch. Default: 3

  • showEpoch_n (int, optional) – The number of epoch that show the training information. Default: 100

  • fast_training (bool, optional) – If True, the batch size will be set to batch_size*multi_noise and the network will be trained fast. If False, the network will be slowly trained to get better. Default: False

Returns:

  • object – The network object.

  • array-like – The losses of training set and validation set.

train_AvgMu(repeat_n=3, showEpoch_n=100, fast_training=True)[source]
train_AvgMultiNoise(repeat_n=3, showEpoch_n=100, fast_training=True)[source]
class colfi.models_mdn.OptimizeMDN(sim_data, obs_data, param_names, cov_matrix=None, params_dict=None)[source]

Bases: OptimizeMLP

Train MDNs and predict cosmological parameters using the given simulated data.

Parameters:
  • sim_data (array-like or list) – The simulated data.

  • obs_data (array-like or list) – The observational data.

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • cov_matrix (array-like, list, or None, optional) – Covariance matrix of the observational data. It should be an array with shape (obs_length, obs_length), or a list of covariance matrix with shape [(obs_length_1, obs_length_1), (obs_length_2, obs_length_2), …]. If there is no covariance for some observations, the covariance matrix should be set to None. e.g. [cov_matrix_1, None, cov_matrix_3]. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

Variables:

chain_leng (int, optional) – The length of each ANN chain. Default: 10000

Note

A lot of MDNs can be trained using the given simulated data, therefore, this class can be used to test the effect of hyperparameters of the MDN.

class colfi.models_mdn.PredictMBMDN(path='ann', randn_num='0.123')[source]

Bases: MultiBranchMDN, Loader

Repredict cosmological parameters using the saved networks.

Parameters:
  • path (str) – The path of the results saved. Default: ‘ann’

  • randn_num (str or int) – A random number that identifies the saved results.

class colfi.models_mdn.PredictOBMDN(path='ann', randn_num='0.123')[source]

Bases: OneBranchMDN, Loader

Repredict cosmological parameters using the saved networks.

Parameters:
  • path (str) – The path of the results saved. Default: ‘ann’

  • randn_num (str or int) – A random number that identifies the saved results.

colfi.models_g

class colfi.models_g.MultiBranchMLP_G(train_set, param_names, vali_set=[None, None], obs_errors=None, cov_matrix=None, params_dict=None, branch_hiddenLayer=1, trunk_hiddenLayer=2, activation_func='Softplus', noise_type='multiNormal', factor_sigma=0.2, multi_noise=5)[source]

Bases: MultiBranchMLP

Predict cosmological parameters with multibranch MNN for multiple sets of datasets.

This is just a special case of MultiBranchMLP_MG with one component (comp_n=1).

Parameters:
  • train_set (list) – The training set that contains simulated observations (measurements) which is a list observations with shape [(N,obs_length_1), (N,obs_length_2), …] and simulated parameters of a specific cosmological (or theoretical) model. i.e. [observations, parameters]

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • vali_set (list, optional) – The validation set that contains simulated observations (measurements) which is a list observations with shape [(N,obs_length_1), (N,obs_length_2), …] and simulated parameters of a specific cosmological (or theoretical) model. The validation set can also be set to None. i.e. [observations, parameters] or [None, None]. Default: [None, None]

  • obs_errors (None or list, optional) – Observational errors, it is a list of errors with shape [(obs_length_1,), (obs_length_2,), …]. If cov_matrix is set to None, the observational errors should be given. Default: None

  • cov_matrix (None or list, optional) – A list of covariance matrix with shape [(obs_length_1, obs_length_1), (obs_length_2, obs_length_2), …]. If there is no covariance for some observations, the covariance matrix should be set to None. e.g. [cov_matrix_1, None, cov_matrix_3]. If a covariance matrix is given, obs_errors will be ignored. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

  • branch_hiddenLayer (int, optional) – The number of the hidden layer for the branch part of the network. Default: 1

  • trunk_hiddenLayer (int, optional) – The number of the hidden layer for the trunk part of the network. Default: 2

  • activation_func (str, optional) – Activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’ (see activation()). Default: ‘Softplus’

  • noise_type (str, optional) – The type of Gaussian noise added to the training set, which can be ‘singleNormal’ or ‘multiNormal’. Default: ‘multiNormal’

  • factor_sigma (float, optional) – For the case of noise_type = ‘singleNormal’, factor_sigma should be set to 1. For the case of noise_type = ‘multiNormal’, it is the standard deviation of the coefficient of the observational error (standard deviation). Default: 0.2

  • multi_noise (int, optional) – The number of realization of noise added to the measurement in one epoch. Default: 5

Variables:
  • obs_base (array-like, optional) – The base value of observations that is used for data normalization when training the network to ensure that the scaled observations are ~ 1., it is suggested to set the mean of the simulated observations. The default is the mean of the simulated observations.

  • params_base (array-like, optional) – The base value of parameters that is used for data normalization when training the network to ensure that the scaled parameters are ~ 1., it is suggested to set the mean of the posterior distribution (or the simulated parameters). The default is the mean of the simulated parameters.

  • params_space (array-like) – The parameter space with the shape of (n, 2), where n is the number of parameters. For each parameter, it is: [lower_limit, upper_limit].

  • lr (float, optional) – The learning rate setting of the network. Default: 1e-2

  • lr_branch (float, optional) – The learning rate setting of the branch part. Default: 1e-2

  • lr_min (float, optional) – The minimum of the learning rate. Default: 1e-8

  • batch_size (int, optional) – The batch size setting of the network. Default: 1250

  • auto_batchSize (bool, optional) – If True, the batch size will be set automatically in the training process, otherwise, use the setting of batch_size. Default: False

  • epoch (int, optional) – The number of epoch of the training process. Default: 2000

  • epoch_branch (int, optional) – The number of epoch for the branch part. This only works when training the branch part. Default: 2000

  • base_epoch (int, optional) – The base number (or the minimum number) of epoch. Default: 1000

  • auto_epoch (bool, optional) – If True, the epoch will be set automatically in the training process, otherwise, use the setting of epoch. Default: False

  • print_info (bool, optional) – If True, will print the information of the network. Default: False

  • scale_obs (bool, optional) – If True, the input data (measurements) will be scaled based on the base values of the data. Default: True

  • scale_params (bool, optional) – If True, the target data (cosmological parameters) will be scaled based on the base values of parameters. See DataPreprocessing. Default: True

  • norm_obs (bool, optional) – If True, the input data (measurements) of the network will be normalized. Default: True

  • norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized. Default: True

  • independent_norm_obs (bool, optional) – If True, the measurements will be normalized independently. This only works when norm_obs=True. Default: False

  • independent_norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized independently. This only works when norm_params=True. Default: True

  • norm_type (str, optional) – The method of normalization, which can be ‘z_score’, ‘minmax’, or ‘mean’ (see Normalize). Default: ‘z_score’

  • spaceSigma_min (int, optional) – The minimum parameter space to be learned, e.g. for spaceSigma_min=5, the parameter space to be learned is \([-5\sigma, +5\sigma]\). Default: 5

  • burnInEnd (bool, optional) – If True, it is the end of the burn-in phase, which means the ANN chain has reached a stable state. Default: False

  • burnInEnd_step (None or int, optional) – The burn-in end step. If None, it means the burn-in phase not end. Default: None

  • transfer_learning (bool, optional) – If True, the network will be initialized using the well-trained network of the previous step. Default: False

  • randn_num (float or str, optional) – A random number that identifies the saved results. Default: float

  • nde_type (str, optional) – A string that indicate which NDE is used, which should be ‘MNN’.

  • file_identity_str (str, optional) – A string that identifies the files saved to the disk, which is useful to identify the saved files. Default: ‘’

train(repeat_n=3, showEpoch_n=100, train_branch=False, parallel=True, train_trunk=False, fix_lr=0.0001, reduce_fix_lr=False, fast_training=False)[source]

Train the network.

Parameters:
  • repeat_n (int, optional) – The number of repeat feed to the network for each batch size data, which will increase the number of iterations in each epoch. Default: 3

  • showEpoch_n (int, optional) – The number of epoch that show the training information. Default: 100

  • fast_training (bool, optional) – If True, the batch size will be set to batch_size*multi_noise and the network will be trained fast. If False, the network will be slowly trained to get better. Default: False

Returns:

  • object – The network object.

  • array-like – The losses of training set and validation set.

class colfi.models_g.OneBranchMLP_G(train_set, param_names, vali_set=[None, None], obs_errors=None, cov_matrix=None, params_dict=None, hidden_layer=3, activation_func='Softplus', noise_type='multiNormal', factor_sigma=0.2, multi_noise=5)[source]

Bases: OneBranchMLP

Predict cosmological parameters with mixture neural network (MNN) for one set of datasets.

This is just a special case of OneBranchMLP_MG with one component (comp_n=1).

Parameters:
  • train_set (list) – The training set that contains simulated observations (measurements) with shape (N, obs_length) and simulated parameters of a specific cosmological (or theoretical) model. i.e. [observations, parameters]

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • vali_set (list, optional) – The validation set that contains simulated observations (measurements) with shape (N, obs_length) and simulated parameters of a specific cosmological (or theoretical) model, i.e. [observations, parameters]. The validation set can also be set to None, i.e. [None, None]. Default: [None, None]

  • obs_errors (None or array-like, optional) – Observational errors with shape (obs_length,). If cov_matrix is set to None, the observational errors should be given. Default: None

  • cov_matrix (None or array-like, optional) – Covariance matrix of the observational data. If a covariance matrix is given, obs_errors will be ignored. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

  • hidden_layer (int, optional) – The number of the hidden layer of the network. Default: 3

  • activation_func (str, optional) – Activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’ (see activation()). Default: ‘Softplus’

  • noise_type (str, optional) – The type of Gaussian noise added to the training set, which can be ‘singleNormal’ or ‘multiNormal’. Default: ‘multiNormal’

  • factor_sigma (float, optional) – For the case of noise_type = ‘singleNormal’, factor_sigma should be set to 1. For the case of noise_type = ‘multiNormal’, it is the standard deviation of the coefficient of the observational error (standard deviation). Default: 0.2

  • multi_noise (int, optional) – The number of realization of noise added to the measurement in one epoch. Default: 5

Variables:
  • obs_base (array-like, optional) – The base value of observations that is used for data normalization when training the network to ensure that the scaled observations are ~ 1., it is suggested to set the mean of the simulated observations. The default is the mean of the simulated observations.

  • params_base (array-like, optional) – The base value of parameters that is used for data normalization when training the network to ensure that the scaled parameters are ~ 1., it is suggested to set the mean of the posterior distribution (or the simulated parameters). The default is the mean of the simulated parameters.

  • params_space (array-like) – The parameter space with the shape of (n, 2), where n is the number of parameters. For each parameter, it is: [lower_limit, upper_limit].

  • lr (float, optional) – The learning rate setting of the network. Default: 1e-2

  • lr_min (float, optional) – The minimum of the learning rate. Default: 1e-8

  • batch_size (int, optional) – The batch size setting of the network. Default: 1250

  • auto_batchSize (bool, optional) – If True, the batch size will be set automatically in the training process, otherwise, use the setting of batch_size. Default: False

  • epoch (int, optional) – The number of epoch of the training process. Default: 2000

  • base_epoch (int, optional) – The base number (or the minimum number) of epoch. Default: 1000

  • auto_epoch (bool, optional) – If True, the epoch will be set automatically in the training process, otherwise, use the setting of epoch. Default: False

  • print_info (bool, optional) – If True, will print the information of the network. Default: False

  • scale_obs (bool, optional) – If True, the input data (measurements) will be scaled based on the base values of the data. Default: False

  • scale_params (bool, optional) – If True, the target data (cosmological parameters) will be scaled based on the base values of parameters. See DataPreprocessing. Default: True

  • norm_obs (bool, optional) – If True, the input data (measurements) of the network will be normalized. Default: True

  • norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized. Default: True

  • independent_norm_obs (bool, optional) – If True, the measurements will be normalized independently. This only works when norm_obs=True. Default: False

  • independent_norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized independently. This only works when norm_params=True. Default: True

  • norm_type (str, optional) – The method of normalization, which can be ‘z_score’, ‘minmax’, or ‘mean’ (see Normalize). Default: ‘z_score’

  • spaceSigma_min (int, optional) – The minimum parameter space to be learned, e.g. for spaceSigma_min=5, the parameter space to be learned is \([-5\sigma, +5\sigma]\). Default: 5

  • burnInEnd (bool, optional) – If True, it is the end of the burn-in phase, which means the ANN chain has reached a stable state. Default: False

  • burnInEnd_step (None or int, optional) – The burn-in end step. If None, it means the burn-in phase not end. Default: None

  • transfer_learning (bool, optional) – If True, the network will be initialized using the well-trained network of the previous step. Default: False

  • randn_num (float or str, optional) – A random number that identifies the saved results. Default: float

  • nde_type (str, optional) – A string that indicate which NDE is used, which should be ‘MNN’.

  • file_identity_str (str, optional) – A string that identifies the files saved to the disk, which is useful to identify the saved files. Default: ‘’

train(repeat_n=3, showEpoch_n=100, fast_training=False)[source]

Train the network.

Parameters:
  • repeat_n (int, optional) – The number of repeat feed to the network for each batch size data, which will increase the number of iterations in each epoch. Default: 3

  • showEpoch_n (int, optional) – The number of epoch that show the training information. Default: 100

  • fast_training (bool, optional) – If True, the batch size will be set to batch_size*multi_noise and the network will be trained fast. If False, the network will be slowly trained to get better. Default: False

Returns:

  • object – The network object.

  • array-like – The losses of training set and validation set.

train_AvgMultiNoise(repeat_n=3, showEpoch_n=100, fast_training=True)[source]
class colfi.models_g.OptimizeMLP_G(sim_data, obs_data, param_names, cov_matrix=None, params_dict=None)[source]

Bases: OptimizeMLP

Train MNNs and predict cosmological parameters using the given simulated data.

Parameters:
  • sim_data (array-like or list) – The simulated data.

  • obs_data (array-like or list) – The observational data.

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • cov_matrix (array-like, list, or None, optional) – Covariance matrix of the observational data. It should be an array with shape (obs_length, obs_length), or a list of covariance matrix with shape [(obs_length_1, obs_length_1), (obs_length_2, obs_length_2), …]. If there is no covariance for some observations, the covariance matrix should be set to None. e.g. [cov_matrix_1, None, cov_matrix_3]. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

Variables:

chain_leng (int, optional) – The length of each ANN chain. Default: 10000

Note

A lot of MNNs can be trained using the given simulated data, therefore, this class can be used to test the effect of hyperparameters of the MNN.

class colfi.models_g.PredictMBMLP_G(path='ann', randn_num='0.123')[source]

Bases: MultiBranchMLP_G, Loader

Repredict cosmological parameters using the saved networks.

Parameters:
  • path (str) – The path of the results saved. Default: ‘ann’

  • randn_num (str or int) – A random number that identifies the saved results.

class colfi.models_g.PredictOBMLP_G(path='ann', randn_num='0.123')[source]

Bases: OneBranchMLP_G, Loader

Repredict cosmological parameters using the saved networks.

Parameters:
  • path (str) – The path of the results saved. Default: ‘ann’

  • randn_num (str or int) – A random number that identifies the saved results.

colfi.models_mg

class colfi.models_mg.MultiBranchMLP_MG(train_set, param_names, vali_set=[None, None], obs_errors=None, cov_matrix=None, params_dict=None, comp_type='Gaussian', comp_n=3, branch_hiddenLayer=1, trunk_hiddenLayer=2, activation_func='Softplus', noise_type='multiNormal', factor_sigma=0.2, multi_noise=5)[source]

Bases: MultiBranchMDN

Predict cosmological parameters with multibranch MNN for multiple sets of datasets.

Parameters:
  • train_set (list) – The training set that contains simulated observations (measurements) which is a list observations with shape [(N,obs_length_1), (N,obs_length_2), …] and simulated parameters of a specific cosmological (or theoretical) model. i.e. [observations, parameters]

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • vali_set (list, optional) – The validation set that contains simulated observations (measurements) which is a list observations with shape [(N,obs_length_1), (N,obs_length_2), …] and simulated parameters of a specific cosmological (or theoretical) model. The validation set can also be set to None. i.e. [observations, parameters] or [None, None]. Default: [None, None]

  • obs_errors (None or list, optional) – Observational errors, it is a list of errors with shape [(obs_length_1,), (obs_length_2,), …]. If cov_matrix is set to None, the observational errors should be given. Default: None

  • cov_matrix (None or list, optional) – A list of covariance matrix with shape [(obs_length_1, obs_length_1), (obs_length_2, obs_length_2), …]. If there is no covariance for some observations, the covariance matrix should be set to None. e.g. [cov_matrix_1, None, cov_matrix_3]. If a covariance matrix is given, obs_errors will be ignored. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

  • comp_type (str, optional) – The name of component used in the MDN method, which should be ‘Gaussian’. Since the loss function of MNN is similar to that of MDN with Gaussian mixture model, we are using the loss function of MDN. Default: ‘Gaussian’

  • comp_n (int, optional) – The number of components used in the MNN method. Default: 3

  • branch_hiddenLayer (int, optional) – The number of the hidden layer for the branch part of the network. Default: 1

  • trunk_hiddenLayer (int, optional) – The number of the hidden layer for the trunk part of the network. Default: 2

  • activation_func (str, optional) – Activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’ (see activation()). Default: ‘Softplus’

  • noise_type (str, optional) – The type of Gaussian noise added to the training set, which can be ‘singleNormal’ or ‘multiNormal’. Default: ‘multiNormal’

  • factor_sigma (float, optional) – For the case of noise_type = ‘singleNormal’, factor_sigma should be set to 1. For the case of noise_type = ‘multiNormal’, it is the standard deviation of the coefficient of the observational error (standard deviation). Default: 0.2

  • multi_noise (int, optional) – The number of realization of noise added to the measurement in one epoch. Default: 5

Variables:
  • obs_base (array-like, optional) – The base value of observations that is used for data normalization when training the network to ensure that the scaled observations are ~ 1., it is suggested to set the mean of the simulated observations. The default is the mean of the simulated observations.

  • params_base (array-like, optional) – The base value of parameters that is used for data normalization when training the network to ensure that the scaled parameters are ~ 1., it is suggested to set the mean of the posterior distribution (or the simulated parameters). The default is the mean of the simulated parameters.

  • params_space (array-like) – The parameter space with the shape of (n, 2), where n is the number of parameters. For each parameter, it is: [lower_limit, upper_limit].

  • lr (float, optional) – The learning rate setting of the network. Default: 1e-2

  • lr_branch (float, optional) – The learning rate setting of the branch part. Default: 1e-2

  • lr_min (float, optional) – The minimum of the learning rate. Default: 1e-8

  • batch_size (int, optional) – The batch size setting of the network. Default: 1250

  • auto_batchSize (bool, optional) – If True, the batch size will be set automatically in the training process, otherwise, use the setting of batch_size. Default: False

  • epoch (int, optional) – The number of epoch of the training process. Default: 2000

  • epoch_branch (int, optional) – The number of epoch for the branch part. This only works when training the branch part. Default: 2000

  • base_epoch (int, optional) – The base number (or the minimum number) of epoch. Default: 1000

  • auto_epoch (bool, optional) – If True, the epoch will be set automatically in the training process, otherwise, use the setting of epoch. Default: False

  • print_info (bool, optional) – If True, will print the information of the network. Default: False

  • scale_obs (bool, optional) – If True, the input data (measurements) will be scaled based on the base values of the data. Default: True

  • scale_params (bool, optional) – If True, the target data (cosmological parameters) will be scaled based on the base values of parameters. See DataPreprocessing. Default: True

  • norm_obs (bool, optional) – If True, the input data (measurements) of the network will be normalized. Default: True

  • norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized. Default: True

  • independent_norm_obs (bool, optional) – If True, the measurements will be normalized independently. This only works when norm_obs=True. Default: False

  • independent_norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized independently. This only works when norm_params=True. Default: True

  • norm_type (str, optional) – The method of normalization, which can be ‘z_score’, ‘minmax’, or ‘mean’ (see Normalize). Default: ‘z_score’

  • spaceSigma_min (int, optional) – The minimum parameter space to be learned, e.g. for spaceSigma_min=5, the parameter space to be learned is \([-5\sigma, +5\sigma]\). Default: 5

  • burnInEnd (bool, optional) – If True, it is the end of the burn-in phase, which means the ANN chain has reached a stable state. Default: False

  • burnInEnd_step (None or int, optional) – The burn-in end step. If None, it means the burn-in phase not end. Default: None

  • transfer_learning (bool, optional) – If True, the network will be initialized using the well-trained network of the previous step. Default: False

  • randn_num (float or str, optional) – A random number that identifies the saved results. Default: float

  • nde_type (str, optional) – A string that indicate which NDE is used, which should be ‘MNN’.

  • file_identity_str (str, optional) – A string that identifies the files saved to the disk, which is useful to identify the saved files. Default: ‘’

predict_chain(obs_data, cov_matrix=None, chain_leng=10000)[source]
property sampler
class colfi.models_mg.OneBranchMLP_MG(train_set, param_names, vali_set=[None, None], obs_errors=None, cov_matrix=None, params_dict=None, comp_type='Gaussian', comp_n=3, hidden_layer=3, activation_func='Softplus', noise_type='multiNormal', factor_sigma=0.2, multi_noise=5)[source]

Bases: OneBranchMDN

Predict cosmological parameters with mixture neural network (MNN) for one set of datasets.

Parameters:
  • train_set (list) – The training set that contains simulated observations (measurements) with shape (N, obs_length) and simulated parameters of a specific cosmological (or theoretical) model. i.e. [observations, parameters]

  • param_names (list) – A list which contains the parameter names, e.g. [‘H0’,’ombh2’,’omch2’].

  • vali_set (list, optional) – The validation set that contains simulated observations (measurements) with shape (N, obs_length) and simulated parameters of a specific cosmological (or theoretical) model, i.e. [observations, parameters]. The validation set can also be set to None, i.e. [None, None]. Default: [None, None]

  • obs_errors (None or array-like, optional) – Observational errors with shape (obs_length,). If cov_matrix is set to None, the observational errors should be given. Default: None

  • cov_matrix (None or array-like, optional) – Covariance matrix of the observational data. If a covariance matrix is given, obs_errors will be ignored. Default: None

  • params_dict (dict or None, optional) – Information of cosmological parameters that include the labels, the minimum values, and the maximum values. See params_dict_zoo(). Default: None

  • comp_type (str, optional) – The name of component used in the MDN method, which should be ‘Gaussian’. Since the loss function of MNN is similar to that of MDN with Gaussian mixture model, we are using the loss function of MDN. Default: ‘Gaussian’

  • comp_n (int, optional) – The number of components used in the MNN method. Default: 3

  • hidden_layer (int, optional) – The number of the hidden layer of the network. Default: 3

  • activation_func (str, optional) – Activation function, which can be ‘ReLU’, ‘LeakyReLU’, ‘PReLU’, ‘RReLU’, ‘ReLU6’, ‘ELU’, ‘CELU’, ‘SELU’, ‘SiLU’, ‘Sigmoid’, ‘LogSigmoid’, ‘Tanh’, ‘Tanhshrink’, ‘Softsign’, or ‘Softplus’ (see activation()). Default: ‘Softplus’

  • noise_type (str, optional) – The type of Gaussian noise added to the training set, which can be ‘singleNormal’ or ‘multiNormal’. Default: ‘multiNormal’

  • factor_sigma (float, optional) – For the case of noise_type = ‘singleNormal’, factor_sigma should be set to 1. For the case of noise_type = ‘multiNormal’, it is the standard deviation of the coefficient of the observational error (standard deviation). Default: 0.2

  • multi_noise (int, optional) – The number of realization of noise added to the measurement in one epoch. Default: 5

Variables:
  • obs_base (array-like, optional) – The base value of observations that is used for data normalization when training the network to ensure that the scaled observations are ~ 1., it is suggested to set the mean of the simulated observations. The default is the mean of the simulated observations.

  • params_base (array-like, optional) – The base value of parameters that is used for data normalization when training the network to ensure that the scaled parameters are ~ 1., it is suggested to set the mean of the posterior distribution (or the simulated parameters). The default is the mean of the simulated parameters.

  • params_space (array-like) – The parameter space with the shape of (n, 2), where n is the number of parameters. For each parameter, it is: [lower_limit, upper_limit].

  • lr (float, optional) – The learning rate setting of the network. Default: 1e-2

  • lr_min (float, optional) – The minimum of the learning rate. Default: 1e-8

  • batch_size (int, optional) – The batch size setting of the network. Default: 1250

  • auto_batchSize (bool, optional) – If True, the batch size will be set automatically in the training process, otherwise, use the setting of batch_size. Default: False

  • epoch (int, optional) – The number of epoch of the training process. Default: 2000

  • base_epoch (int, optional) – The base number (or the minimum number) of epoch. Default: 1000

  • auto_epoch (bool, optional) – If True, the epoch will be set automatically in the training process, otherwise, use the setting of epoch. Default: False

  • print_info (bool, optional) – If True, will print the information of the network. Default: False

  • scale_obs (bool, optional) – If True, the input data (measurements) will be scaled based on the base values of the data. Default: False

  • scale_params (bool, optional) – If True, the target data (cosmological parameters) will be scaled based on the base values of parameters. See DataPreprocessing. Default: True

  • norm_obs (bool, optional) – If True, the input data (measurements) of the network will be normalized. Default: True

  • norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized. Default: True

  • independent_norm_obs (bool, optional) – If True, the measurements will be normalized independently. This only works when norm_obs=True. Default: False

  • independent_norm_params (bool, optional) – If True, the target data (cosmological parameters) will be normalized independently. This only works when norm_params=True. Default: True

  • norm_type (str, optional) – The method of normalization, which can be ‘z_score’, ‘minmax’, or ‘mean’ (see Normalize). Default: ‘z_score’

  • spaceSigma_min (int, optional) – The minimum parameter space to be learned, e.g. for spaceSigma_min=5, the parameter space to be learned is \([-5\sigma, +5\sigma]\). Default: 5

  • burnInEnd (bool, optional) – If True, it is the end of the burn-in phase, which means the ANN chain has reached a stable state. Default: False

  • burnInEnd_step (None or int, optional) – The burn-in end step. If None, it means the burn-in phase not end. Default: None

  • transfer_learning (bool, optional) – If True, the network will be initialized using the well-trained network of the previous step. Default: False

  • randn_num (float or str, optional) – A random number that identifies the saved results. Default: float

  • nde_type (str, optional) – A string that indicate which NDE is used, which should be ‘MNN’.

  • file_identity_str (str, optional) – A string that identifies the files saved to the disk, which is useful to identify the saved files. Default: ‘’

predict_chain(obs_data, cov_matrix=None, chain_leng=10000)[source]
property sampler
class colfi.models_mg.PredictMBMLP_MG(path='ann', randn_num='0.123')[source]

Bases: MultiBranchMLP_MG, Loader

Repredict cosmological parameters using the saved networks.

Parameters:
  • path (str) – The path of the results saved. Default: ‘ann’

  • randn_num (str or int) – A random number that identifies the saved results.

class colfi.models_mg.PredictOBMLP_MG(path='ann', randn_num='0.123')[source]

Bases: OneBranchMLP_MG, Loader

Repredict cosmological parameters using the saved networks.

Parameters:
  • path (str) – The path of the results saved. Default: ‘ann’

  • randn_num (str or int) – A random number that identifies the saved results.

colfi.models_mg.gaussian_sampler(omega, params, _sigma)[source]
colfi.models_mg.multivariateGaussian_sampler(omega, params, _cholesky_f)[source]
colfi.models_mg.samplers(params_n)[source]

..colfi.models_annmc ..——————

…. automodule:: colfi.models_annmc .. :members: .. :undoc-members: .. :show-inheritance: