Top |
GStrv | fmap | Read / Write |
NcmObjArray * | model-array | Read / Write / Construct |
gboolean | valid-map | Read / Write |
#define | NCM_TYPE_MSET |
#define | NCM_MSET_MAX_STACKSIZE |
#define | NCM_MSET_INIT_MARRAY |
struct | NcmMSetModelDesc |
struct | NcmMSetClass |
#define | NCM_MSET_MODEL_MAIN |
NcmMSet |
A NcmMSet is a set of different NcmModel objects. It is used to represent a set of models that can be used to fit a data set.
When the model class is created the class method ncm_mset_model_register_id()
must be used to register the model class. This function must be used once
and only once in the model class definition. Any subclasse of the model
class will inherit the model id. The same compilation unit must call the macro
NCM_MSET_MODEL_REGISTER_ID()
for each model class that will be used in the NcmMSet.
It should also include NCM_MSET_MODEL_DECLARE_ID()
in the header file.
Models can be stackable or not. If a model is stackable, the NcmMSet can contain more than one instance of the same model. If a model is not stackable, the NcmMSet can contain only one instance of the model.
The model can be a submodel of another model. In this case, the
model class must set the main_model_id field to the model id of the
parent model. If it is the main model, the main_model_id must be
set to NCM_MSET_MODEL_MAIN()
.
The NcmMSet can be created empty or with a list of models. The stackable models can
be added to the NcmMSet using the function ncm_mset_push()
to add the model to the
end of the list or using ncm_mset_set_pos()
to add the model in a specific position.
The non-stackable models can be added using ncm_mset_set()
. For both
ncm_mset_set_pos()
and ncm_mset_set()
if there is already a model in the position
it will be replaced.
void ncm_mset_model_register_id (NcmModelClass *model_class
,const gchar *ns
,const gchar *desc
,const gchar *long_desc
,gboolean can_stack
,NcmModelID main_model_id
);
Register a model class in the NcmMSet. This function must be used once and only
once in the model class definition. Any subclasse of the model class will inherit
the model id. The same compilation unit must call the macro
NCM_MSET_MODEL_REGISTER_ID()
for each model class that will be used in the NcmMSet.
It should also include NCM_MSET_MODEL_DECLARE_ID()
in the header file.
If can_stack
is TRUE, the models can stack in a NcmMSet. If can_stack
is FALSE,
the NcmMSet can contain only one instance of the model class or any of its
subclasses.
If main_model_id
is NCM_MSET_MODEL_MAIN()
, this is a main model. If main_model_id
is not NCM_MSET_MODEL_MAIN()
, this must be the id of the main model. This is used
to define an hierarchy of models. For example, the model class NcHIPrim is a
submodel of NcHICosmo. The main model of NcHIPrim is NcHICosmo. Thus, each
instance of NcHICosmo can contain one instance of NcHIPrim.
[skip]
model_class |
||
ns |
model namespace |
|
desc |
short description |
|
long_desc |
long description |
|
can_stack |
whether the models can stack in a NcmMSet |
|
main_model_id |
main model id, use -1 if this is a main model |
#define NCM_MSET_MODEL_ID_FUNC(model_ns) model_ns ## _id
Defines a function to get the model id from the model namespace.
#define NCM_MSET_MODEL_DECLARE_ID(model_ns) NcmModelID NCM_MSET_MODEL_ID_FUNC (model_ns) (void) G_GNUC_CONST
Declares a function to get the model id from the model namespace. This macro should be used in the header file of the model.
#define NCM_MSET_MODEL_REGISTER_ID(model_ns, typemacro)
Defines the function to get the model id from the model namespace. This macro should be used in the source file of the model.
model_ns |
model namespace in snake case |
|
typemacro |
macro that returns the GType of the model |
NcmMSetPIndex * ncm_mset_pindex_new (NcmModelID mid
,guint pid
);
Creates a new NcmMSetPIndex.
NcmMSetPIndex *
ncm_mset_pindex_dup (NcmMSetPIndex *pi
);
Duplicate a NcmMSetPIndex.
gboolean ncm_mset_split_full_name (const gchar *fullname
,gchar **model_ns
,guint *stackpos_id
,gchar **pname
);
Splits the fullname
into model_ns
, stackpos_id
and pname
. The fullname
should be specified with the parameter full name "model:parameter_name"
or "model:stackposition:parameter_name".
NcmMSet * ncm_mset_new (gpointer model0
,...
);
Creates a new NcmMSet with the models passed as arguments.
NcmMSet * ncm_mset_newv (gpointer model0
,va_list ap
);
Creates a new NcmMSet with the models passed as arguments.
NcmMSet *
ncm_mset_new_array (GPtrArray *model_array
);
Creates a new NcmMSet with the models passed as arguments.
NcmMSet *
ncm_mset_ref (NcmMSet *mset
);
Increases the reference count of mset
by one.
NcmMSet * ncm_mset_dup (NcmMSet *mset
,NcmSerialize *ser
);
Duplicate a NcmMSet using a NcmSerialize object.
NcmMSet *
ncm_mset_shallow_copy (NcmMSet *mset
);
Creates a new NcmMSet with the same models of mset
.
void
ncm_mset_free (NcmMSet *mset
);
Atomically decreases the reference count of mset
by one. If the reference count drops to 0,
all memory allocated by mset
is released.
void
ncm_mset_clear (NcmMSet **mset
);
If *mse
is not NULL, decreases the reference count of mset
by one. If the
reference count drops to 0, all memory allocated by mset
is released and *mset
is
set to NULL.
NcmModel * ncm_mset_peek_pos (NcmMSet *mset
,NcmModelID base_mid
,guint stackpos_id
);
Peeks a NcmModel from the NcmMSet using the model id base_mid
and stack position
stackpos_id
. This function is useful when the model is stackable.
NcmModel * ncm_mset_peek_array_pos (NcmMSet *mset
,guint i
);
Peeks a NcmModel from the NcmMSet using the array position i
.
The array position is not guaranteed to be the same for different
NcmMSet objects. This function is useful to iterate over the models
in the NcmMSet.
NcmModel * ncm_mset_peek_by_name (NcmMSet *mset
,const gchar *name
);
Peeks a NcmModel from the NcmMSet using the model namespace name
.
The name may be specified with the parameter full name "model:stackposition".
If the stack position is not specified, the first model with the model namespace
name
will be returned.
NcmModelID ncm_mset_get_mid_array_pos (NcmMSet *mset
,guint i
);
Gets the model id of the model in the array position i
.
The array position is not guaranteed to be the same for different
NcmMSet objects. This function is useful to iterate over the models
in the NcmMSet.
void ncm_mset_remove (NcmMSet *mset
,NcmModelID mid
);
Removes a NcmModel from the NcmMSet using the model id mid
.
void ncm_mset_set (NcmMSet *mset
,NcmModel *model
);
Sets a NcmModel in the NcmMSet. If there is already a model with the same model id, it will be replaced. If it is a stackable model, it will be added to the first position.
void ncm_mset_push (NcmMSet *mset
,NcmModel *model
);
Pushes a NcmModel to the end of the NcmMSet. If the model is not stackable, it will be added to the first position, if there is already a model with the same model id an error will be raised.
void ncm_mset_set_pos (NcmMSet *mset
,NcmModel *model
,guint stackpos_id
);
Sets a NcmModel in the NcmMSet in the stack position stackpos_id
.
If there is already a model with the same model id, it will be replaced.
If it is a stackable model, it will be added to the position stackpos_id
.
If stackpos_id
is 0, it will be added to the first position.
If the model
is not stackable, it will raise an error if stackpos_id
is
different from 0.
gboolean ncm_mset_exists_pos (NcmMSet *mset
,NcmModel *model
,guint stackpos_id
);
Checks whether a NcmModel with the same id as model
and stack position
stackpos_id
exists in the NcmMSet.
gboolean ncm_mset_is_subset (NcmMSet *mset
,NcmMSet *sub_mset
);
Checks whether sub_mset
is a subset of mset
, that is,
whether all models in sub_mset
are also in mset
.
gint ncm_mset_cmp_all (NcmMSet *mset0
,NcmMSet *mset1
);
Compares two NcmMSet objects. It returns 0 if they contain the same
models, with the same number of parameters, in the same order. It
returns -1 if mset0
has fewer models than mset1
, or if they have
the same number of models but mset0
has a model with fewer
parameters than the corresponding model in mset1
. It returns 1 if
mset0
has more models than mset1
, or if they have the same number
of models but mset0
has a model with more parameters than the
corresponding model in mset1
.
NcmModelID
ncm_mset_get_id_by_type (GType model_type
);
Gets the model id for a model type in the GObject type system.
NcmModelID
ncm_mset_get_id_by_ns (const gchar *ns
);
Gets the model id for a model namespace.
void ncm_mset_set_fmap (NcmMSet *mset
,const gchar * const *fmap
,gboolean update_models
);
Sets the free parameters map for mset
. This function must be called
before any other function that uses the free parameters map. The fmap
array must be zero-terminated and contain the full names of the free
parameters in mset
.
mset |
a NcmMSet |
|
fmap |
an array of strings. |
[in][array zero-terminated=1][element-type utf8] |
update_models |
a boolean |
gchar **
ncm_mset_get_fmap (NcmMSet *mset
);
Gets the free parameters map for mset
. The returned array must be
freed with g_strfreev()
. It contains the full names of the free
parameters in mset
.
void
ncm_mset_prepare_fparam_map (NcmMSet *mset
);
Computes the free parameters map for mset
. This function must be
called before any other function that uses the free parameters map.
gboolean
ncm_mset_fparam_map_valid (NcmMSet *mset
);
Checks whether the free parameters map for mset
is valid.
guint
ncm_mset_total_len (NcmMSet *mset
);
Gets the total number of parameters in mset
(including fixed and
free parameters).
guint
ncm_mset_fparam_len (NcmMSet *mset
);
Gets the number of free parameters in mset
.
guint
ncm_mset_max_param_name (NcmMSet *mset
);
Gets the maximum length of the parameter names in mset
.
This function is useful to print the parameters in a pretty way.
guint
ncm_mset_max_fparam_name (NcmMSet *mset
);
Gets the maximum length of the free parameter names in mset
.
This function is useful to print the parameters in a pretty way.
guint
ncm_mset_max_model_nick (NcmMSet *mset
);
Gets the maximum length of the model nick in mset
.
This function is useful to print the models in a pretty way.
void
ncm_mset_pretty_log (NcmMSet *mset
);
This function prints the contents of mset
. It prints the model
nick and parameters' names and their values indicating if they are
fixed or free.
void ncm_mset_params_pretty_print (NcmMSet *mset
,FILE *out
,const gchar *header
);
This function print the command line (first line, commented), the model nick and parameters' names (second line, commented) and their values indicating if they are fixed or free.
void
ncm_mset_params_log_vals (NcmMSet *mset
);
Logs the values of the parameters in mset
.
void ncm_mset_params_print_vals (NcmMSet *mset
,FILE *out
);
Prints the values of the parameters in mset
in
the file out
.
void ncm_mset_fparams_log_covar (NcmMSet *mset
,NcmMatrix *covar
);
Logs the covariance matrix of the free parameters in mset
.
The covariance matrix is assumed to be in the same order as
the free parameters in mset
and must be square and with
the same size as the number of free parameters ncm_mset_fparam_len()
.
gboolean
ncm_mset_params_valid (NcmMSet *mset
);
Check whenever all models in mset
have valid parameters.
gboolean
ncm_mset_params_valid_bounds (NcmMSet *mset
);
Check whenever the parameters respect the bounds.
gboolean ncm_mset_cmp (NcmMSet *mset0
,NcmMSet *mset1
,gboolean cmp_model
);
Compares mset0
and mset1
and returns TRUE if both contains the same models types.
If cmp_model
is TRUE compare also if the models correspond to the same objects types.
void ncm_mset_param_set (NcmMSet *mset
,NcmModelID mid
,guint pid
,const gdouble x
);
Sets the value of the parameter pid
in the model mid
to x
.
This function updates the model parameters.
void ncm_mset_param_set0 (NcmMSet *mset
,NcmModelID mid
,guint pid
,const gdouble x
);
Sets the value of the parameter pid
in the model mid
to x
.
This function does not update the model parameters. It is useful
when the parameters are being updated in a loop and the model
parameters are updated only once, after the loop.
gdouble ncm_mset_param_get (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the value of the parameter pid
in the model mid
.
gdouble ncm_mset_orig_param_get (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the value of the original parameter pid
in the model mid
.
That is the value of the parameter before any reparametrization.
const gchar * ncm_mset_param_name (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the name of the parameter pid
in the model mid
.
const gchar * ncm_mset_param_symbol (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the symbol of the parameter pid
in the model mid
. The
parameter symbol is a string that represents the parameter
using LaTeX symbols.
void ncm_mset_param_set_ftype (NcmMSet *mset
,NcmModelID mid
,guint pid
,NcmParamType ftype
);
Sets the type of the parameter pid
in the model mid
to ftype
.
The parameter type can be fixed (NCM_PARAM_TYPE_FIXED) or free (NCM_PARAM_TYPE_FREE).
void ncm_mset_param_set_all_ftype (NcmMSet *mset
,NcmParamType ftype
);
Set all parameters of all models to ftype
.
void ncm_mset_param_set_mid_ftype (NcmMSet *mset
,NcmModelID mid
,NcmParamType ftype
);
Set all parameters of mid
model to ftype
.
void ncm_mset_param_set_all_but_mid_ftype (NcmMSet *mset
,NcmModelID mid
,NcmParamType ftype
);
Set all parameters of all models but mid
to ftype
.
void
ncm_mset_param_set_ftype_from_fmap (NcmMSet *mset
);
Set all parameters of all models inside mset
in order
to reflect the current fmap.
void ncm_mset_param_set_vector (NcmMSet *mset
,NcmVector *params
);
Sets the models parameters using values from the NcmVector params
.
void ncm_mset_param_get_vector (NcmMSet *mset
,NcmVector *params
);
Sets the compontents of params
using the models parameters.
void ncm_mset_param_set_mset (NcmMSet *mset_dest
,NcmMSet *mset_src
);
Copy parameters from mset_src
to mset_dest
, both NcmMSet must
be compatible.
gdouble ncm_mset_param_get_scale (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the scale of the parameter pid
in the model mid
.
This scale is a value that is used as a starting guess
for the variation of the parameter in a statistical
analysis.
gdouble ncm_mset_param_get_lower_bound (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the lower bound of the parameter pid
in the model mid
.
gdouble ncm_mset_param_get_upper_bound (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the upper bound of the parameter pid
in the model mid
.
gdouble ncm_mset_param_get_abstol (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the absolute tolerance of the parameter pid
in the model mid
.
NcmParamType ncm_mset_param_get_ftype (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the type NcmParamType of the parameter pid
in the model mid
.
void ncm_mset_param_set_scale (NcmMSet *mset
,NcmModelID mid
,guint pid
,gdouble scale
);
Sets the scale of the parameter pid
in the model mid
to scale
.
This scale is a value that is used as a starting guess
for the variation of the parameter in a statistical
analysis.
void ncm_mset_param_set_pi (NcmMSet *mset
,NcmMSetPIndex *pi
,const gdouble *x
,guint n
);
Sets the values of the parameters in mset
using the values in x
.
The parameters are identified by the NcmMSetPIndex pi
. This array
and x
must have the same size n
.
mset |
a NcmMSet |
|
pi |
a NcmMSetPIndex array. |
[array length=n][element-type NcmMSetPIndex] |
x |
values to be set. |
[array length=n][element-type double] |
n |
number of parameters to set |
void ncm_mset_param_get_pi (NcmMSet *mset
,NcmMSetPIndex *pi
,gdouble *x
,guint n
);
Gets the values of the parameters in mset
and stores them in x
.
The parameters are identified by the NcmMSetPIndex pi
. This array
and x
must have the same size n
.
mset |
a NcmMSet |
|
pi |
a NcmMSetPIndex array. |
[array length=n][element-type NcmMSetPIndex] |
x |
array to store the values. |
[array length=n][element-type double] |
n |
number of parameters to get |
void ncm_mset_fparams_get_vector (NcmMSet *mset
,NcmVector *x
);
Gets the free parameters of mset
and stores them in x
.
The size of x
must be equal to the number of free parameters
in mset
ncm_mset_fparams_len()
.
void ncm_mset_fparams_get_vector_offset (NcmMSet *mset
,NcmVector *x
,guint offset
);
Gets the free parameters of mset
and stores them in x
starting
at offset
. The size of x
must be equal to the number of free
parameters in mset
ncm_mset_fparams_len()
plus offset
.
void ncm_mset_fparams_set_vector (NcmMSet *mset
,const NcmVector *x
);
Sets the free parameters of mset
using the values of x
.
The size of x
must be equal to the number of free parameters
in mset
ncm_mset_fparams_len()
.
void ncm_mset_fparams_set_vector_offset (NcmMSet *mset
,const NcmVector *x
,guint offset
);
Set the free parameters of mset
using the values of x
starting
at offset
.
void ncm_mset_fparams_set_array (NcmMSet *mset
,const gdouble *x
);
Sets the free parameters of mset
using the values of x
.
The size of x
must be equal to the number of free parameters
in mset
ncm_mset_fparams_len()
. Otherwise the behaviour is
undefined.
void ncm_mset_fparams_set_gsl_vector (NcmMSet *mset
,const gsl_vector *x
);
Sets the free parameters of mset
using the values of x
.
The size of x
must be equal to the number of free parameters
in mset
ncm_mset_fparams_len()
.
[skip]
guint
ncm_mset_fparams_len (NcmMSet *mset
);
Gets the number of free parameters in mset
.
const gchar * ncm_mset_fparam_name (NcmMSet *mset
,guint n
);
Gets the name of the n
-th free parameter.
const gchar * ncm_mset_fparam_symbol (NcmMSet *mset
,guint n
);
Gets the symbol of the n
-th free parameter.
const gchar * ncm_mset_fparam_full_name (NcmMSet *mset
,guint n
);
Gets the full name of the n
-th free parameter. That is
the name of the model, the stack position and the parameter
name.
NcmMSetPIndex * ncm_mset_param_get_by_full_name (NcmMSet *mset
,const gchar *fullname
);
Gets the NcmMSetPIndex of the parameter identified by fullname
.
The fullname
must be in the form "model:stackpos:param_name" when
the model has a stack or "model:param_name" when the model has no
stack.
gdouble ncm_mset_fparam_get_scale (NcmMSet *mset
,guint n
);
Gets the scale of the n
-th free parameter.
gdouble ncm_mset_fparam_get_lower_bound (NcmMSet *mset
,guint n
);
Gets the lower bound of the n
-th free parameter.
gdouble ncm_mset_fparam_get_upper_bound (NcmMSet *mset
,guint n
);
Gets the upper bound of the n
-th free parameter.
NcmMatrix *
ncm_mset_fparam_get_bound_matrix (NcmMSet *mset
);
Gets a matrix with the lower and upper bounds of all free parameters.
The returned matrix has two columns, the first column contains the
lower bounds and the second column contains the upper bounds.
The number of rows is equal to the number of free parameters in mset
.
gdouble ncm_mset_fparam_get_abstol (NcmMSet *mset
,guint n
);
Gets the absolute tolerance of the n
-th free parameter.
void ncm_mset_fparam_set_scale (NcmMSet *mset
,guint n
,gdouble scale
);
Sets the scale of the n
-th free parameter to scale
.
gboolean ncm_mset_fparam_valid_bounds (NcmMSet *mset
,NcmVector *theta
);
Checks if the values of theta
respect the parameter bounds.
gboolean ncm_mset_fparam_valid_bounds_offset (NcmMSet *mset
,NcmVector *theta
,guint offset
);
Checks if the values of theta
respect the parameter bounds.
The values are checked starting at offset
.
gboolean ncm_mset_fparam_validate_all (NcmMSet *mset
,NcmVector *theta
);
Checks if the values of theta
respect all requirements.
gdouble ncm_mset_fparam_get (NcmMSet *mset
,guint n
);
Gets the value of the n
-th free parameter.
void ncm_mset_fparam_set (NcmMSet *mset
,guint n
,const gdouble x
);
Sets the value of the n
-th free parameter to x
.
const NcmMSetPIndex * ncm_mset_fparam_get_pi (NcmMSet *mset
,guint n
);
Gets the NcmMSetPIndex of the n
-th free parameter.
gint ncm_mset_fparam_get_fpi (NcmMSet *mset
,NcmModelID mid
,guint pid
);
Gets the free parameter index of the parameter pid
in the model mid
.
const NcmMSetPIndex * ncm_mset_fparam_get_pi_by_name (NcmMSet *mset
,const gchar *name
);
Gets the NcmMSetPIndex of the parameter identified by name
.
The name can be the parameter name or the full name.
void ncm_mset_save (NcmMSet *mset
,NcmSerialize *ser
,const gchar *filename
,gboolean save_comment
);
NcmMSet * ncm_mset_load (const gchar *filename
,NcmSerialize *ser
);
Loads a NcmMSet from a configuration file using the NcmSerialize
object ser
. The file must be in the same format as the one
generated by ncm_mset_save()
.
[constructor]
#define NCM_MSET_MODEL_MAIN (-1)
Id of a main model. Used to identify the main model in hierarchy of models.
“model-array”
property“model-array” NcmObjArray *
NcmModel array.
Owner: NcmMSet
Flags: Read / Write / Construct
“valid-map”
property“valid-map” gboolean
Valid properties map.
Owner: NcmMSet
Flags: Read / Write
Default value: FALSE