Top | ![]() |
![]() |
![]() |
![]() |
Functions
Properties
guint64 | implementation | Read |
gchar * | name | Read |
gchar * | nick | Read |
GArray * | params-types | Read |
NcmReparam * | reparam | Read / Write |
guint | scalar-params-len | Read |
guint | vector-params-len | Read |
Object Hierarchy
GObject ╰── NcmModel ├── NcClusterMass ├── NcClusterRedshift ├── NcClusterPseudoCounts ├── NcHICosmo ├── NcHICosmoQSplineContPrior ├── NcHIPrim ├── NcPlanckFI ├── NcSNIADistCov ╰── NcXcorLimber
Description
The NcmModel abstract class represents a general model. This object serves for two general objectives. First, all the numerical properties (doubles), i.e., parameters, are implemented by the class functions described below, this allows the implementation of a general statistical analyses based on these models. Second, each child of NcmModel can register itself as a model type. This allows multiples models types to be used simultaneously.
For example, in a problem where one must describe some physical model and some model for the measurement tool, lets say FooPhysical model and FooTool both defined in the Foo namespace.
The FooPhysical and FooTools define virtual functions called respectively foo_physical_value and foo_tool_value which calculates some quantities needed to compare the model with data. Note that both models do not implement anything thay just define which virtual functions must be implemented in order to define a model of each type.
Here is an example of the definition of the FooPhysical model type, note that most of it is just the usual GObject framework boilerplate code.
Implementing a NcmModel (header: foo_physical.h).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include <glib.h> #include <numcosmo/numcosmo.h> // Including NumCosmo headers #define FOO_TYPE_PHYSICAL (foo_physical_get_type ()) #define FOO_PHYSICAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOO_TYPE_PHYSICAL, FooPhysical)) #define FOO_PHYSICAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOO_TYPE_PHYSICAL, FooPhysicalClass)) #define FOO_IS_PHYSICAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOO_TYPE_PHYSICAL)) #define FOO_IS_PHYSICAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOO_TYPE_PHYSICAL)) #define FOO_PHYSICAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NCM_TYPE_PHYSICAL, FooPhysicalClass)) // The lines above are just the basic GObject definition macros typedef struct _FooPhysicalClass FooPhysicalClass; typedef struct _FooPhysical FooPhysical; // To avoid a gtkdoc bug always declare the instance struct before the class // struct struct _FooPhysical { NcmModel parent_instance; ... }; struct _FooPhysicalClass { NcmModelClass parent_class; gdouble (*value) (NcmModel *model); // Virtual function. ... }; ... GType foo_physical_get_type (void) G_GNUC_CONST; NCM_MSET_MODEL_DECLARE_ID (foo_physical); // The last line above is part of the model type registry. gdouble foo_physical_value (FooPhysical *phys); // The virtual function caller. |
Implementing a NcmModel (source: foo_physical.c).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
#include "foo_physical.h" G_DEFINE_ABSTRACT_TYPE (FooPhysical, foo_physical, NCM_TYPE_MODEL); static void foo_physical_init (FooPhysical *object) { ... // Some basic initialization for an instance. } static void _foo_physical_finalize (GObject *object) { ... // Instance finalization, must deallocate all memory and release all references. // Chain up : end G_OBJECT_CLASS (foo_physical_parent_class)->finalize (object); } static gboolean _foo_physical_valid (NcmModel *model); // Define if the model is valid NCM_MSET_MODEL_REGISTER_ID (foo_physical, FOO_TYPE_PHYSICAL); // Second part of the model type registry. static void foo_physical_class_init (FooPhysicalClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); NcmModelClass *model_class = NCM_MODEL_CLASS (klass); object_class->finalize = &_foo_physical_finalize; // It is a base model type definition so no parameters. ncm_model_class_add_params (model_class, 0, 0, 1); // Define its id short and long description. ncm_mset_model_register_id (model_class, "FooPhysical", "Some brief description.", "Some long description."); // Checks if everything is consistent. ncm_model_class_check_params_info (model_class); // Sets the "valid" function. model_class->valid = &_foo_physical_valid; } static gboolean _foo_physical_valid (NcmModel *model) { if (!NCM_MODEL_CLASS (foo_physical_parent_class)->valid (model)) return FALSE; // Chain up : start ... // returns TRUE if value and FALSE if not. } ... // Virtual function accessor. G_INLINE_FUNC gdouble foo_physical_value (FooPhysical *phys) \ { return FOO_PHYSICAL_GET_CLASS (m)->value (NCM_MODEL (phys)); \ } ... |
Now it is possible to give different implementations of each model, e.g., FooPhysicalSimple could be a simple implementation of the physical model taking into account only the main effects and containing only a few parameters. Then, FooPhysicalComplex a more complex implementation including several effects and usually containing several parameters. Suppose that the same applies to FooToolSimple and FooToolComplex.
Here an example of a FooPhysical implementation:
Implementing a FooPhysical (header: foo_physical_simple.h).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <glib.h> #include <numcosmo/numcosmo.h> // Including NumCosmo headers #include "foo_physical.h" #define NCM_TYPE_PHYSICAL_SIMPLE (foo_physical_simple_get_type ()) #define FOO_PHYSICAL_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NCM_TYPE_PHYSICAL_SIMPLE, FooPhysicalSimple)) #define FOO_PHYSICAL_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NCM_TYPE_PHYSICAL_SIMPLE, FooPhysicalSimpleClass)) #define FOO_IS_PHYSICAL_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NCM_TYPE_PHYSICAL_SIMPLE)) #define FOO_IS_PHYSICAL_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NCM_TYPE_PHYSICAL_SIMPLE)) #define FOO_PHYSICAL_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NCM_TYPE_PHYSICAL_SIMPLE, FooPhysicalSimpleClass)) // The lines above are just the basic GObject definition macros typedef struct _FooPhysicalSimpleClass FooPhysicalSimpleClass; typedef struct _FooPhysicalSimple FooPhysicalSimple; // To avoid a gtkdoc bug always declare the instance struct before the class // struct struct _FooPhysicalSimple { FooPhysical parent_instance; // Note that it is now a child of FooPhysical ... }; struct _FooPhysicalSimpleClass { FooPhysicalClass parent_class; // Note that it is now a child of FooPhysical ... }; ... GType foo_physical_simple_get_type (void) G_GNUC_CONST; // Note that we do not registry FooPhysicalSimple as it is of FooPhysical type. |
Implementing a FooPhysical (source: foo_physical_simple.c).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#include "foo_physical_simple.h" G_DEFINE_ABSTRACT_TYPE (FooPhysicalSimple, foo_physical_simple, NCM_TYPE_PHYSICAL); static void foo_physical_simple_init (FooPhysicalSimple *object) { ... // Some basic initialization for an instance. } static void _foo_physical_simple_finalize (GObject *object) { ... // Instance finalization, must deallocate all memory and release all references. // Chain up : end G_OBJECT_CLASS (foo_physical_simple_parent_class)->finalize (object); } // Again, we do not need to register this model. // Here we need to define what FooPhysicalSimple actually calculates. gdouble _foo_physical_simple_value (NcmModel *model); static void foo_physical_simple_class_init (FooPhysicalSimpleClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); NcmModelClass *model_class = NCM_MODEL_CLASS (klass); FooPhysicalClass *physical_class = FOO_PHYSICAL_CLASS (klass); object_class->finalize = &_foo_physical_finalize; physical_class->value = &_foo_physical_simple_value; // It is simple model so lets say is has one (01) scalar parameter and // zero vector parameters. ncm_model_class_add_params (model_class, 1, 0, 1); // Now we set the name and nick for our model. ncm_model_class_set_name_nick (model_class, "Physical simple model", "PSimple"); // Our parameter number 0 is p0 with its symbol being p_0, it can varies // from -10.0 to 10.0 and its natural varying scale is 0.1 // its absolute tolerance is 0 (no absolute tolerance) and its default // value is 2.0 and by default it should be set free in statistical // analysis. ncm_model_class_set_sparam (model_class, 0, "p_0", "p0", -10.0, 10.0, 0.1, 0.0, 1.0, NCM_PARAM_TYPE_FREE); // Checks if everything is consistent. ncm_model_class_check_params_info (model_class); } ... // The virtual function implementation. gdouble _foo_physical_simple_value (NcmModel *model) { const gdouble p0 = ncm_vector_get (model->params, 0); // Get the value of the parameter p0 to perform calculations. ... return ...; // Return the "value". } ... |
Note that, we can now build a NcmData to compare data with these models (FooPhysical and FooTool), in this way NcmData will only depend on these two classes and not on their implementations, i.e., inside NcmData we only call foo_physical_value and foo_tool_value which are independent of their implementations. We can then build a NcmMSet using any combination of FooPhysicalSimple or FooPhysicalComplex and FooToolSimple or FooToolComplex, to find their bestfit or make other statistical analysis (see NcmFit and related objects).
Functions
ncm_model_class_add_params ()
void ncm_model_class_add_params (NcmModelClass *model_class
,guint sparam_len
,guint vparam_len
,guint nonparam_prop_len
);
FIXME
ncm_model_class_set_name_nick ()
void ncm_model_class_set_name_nick (NcmModelClass *model_class
,const gchar *name
,const gchar *nick
);
Attributes name
and nick
, respectively, as the name and nickname of the model.
ncm_model_class_set_sparam ()
void ncm_model_class_set_sparam (NcmModelClass *model_class
,guint sparam_id
,const gchar *symbol
,const gchar *name
,gdouble lower_bound
,gdouble upper_bound
,gdouble scale
,gdouble abstol
,gdouble default_value
,NcmParamType ppt
);
FIXME
ncm_model_class_set_vparam ()
void ncm_model_class_set_vparam (NcmModelClass *model_class
,guint vparam_id
,guint default_length
,const gchar *symbol
,const gchar *name
,gdouble lower_bound
,gdouble upper_bound
,gdouble scale
,gdouble abstol
,gdouble default_value
,NcmParamType ppt
);
FIXME
ncm_model_class_check_params_info ()
void
ncm_model_class_check_params_info (NcmModelClass *model_class
);
FIXME
ncm_model_dup ()
NcmModel * ncm_model_dup (NcmModel *model
,NcmSerialize *ser
);
Duplicates model
by serializing and deserializing it.
ncm_model_free ()
void
ncm_model_free (NcmModel *model
);
Atomically decrements the reference count of model
by one. If the reference count drops to 0,
all memory allocated by model
is released.
ncm_model_clear ()
void
ncm_model_clear (NcmModel **model
);
Atomically decrements the reference count of model
by one. If the reference count drops to 0,
all memory allocated by model
is released. Set pointer to NULL.
ncm_model_is_equal ()
gboolean ncm_model_is_equal (NcmModel *model1
,NcmModel *model2
);
Compares if model1 and model2 are the same, with same dimension and reparametrization.
ncm_model_params_update ()
void
ncm_model_params_update (NcmModel *model
);
Force the parameters to the update its internal flags and update the original parameters if necessary.
ncm_model_orig_params_update ()
void
ncm_model_orig_params_update (NcmModel *model
);
Update the new parameters. It causes an error to call this function with a model without reparametrization.
ncm_model_orig_params_peek_vector ()
NcmVector *
ncm_model_orig_params_peek_vector (NcmModel *model
);
Peeks the original parameters vector. This functions is provided for reparametrization implementations, do not use it in other contexts.
ncm_model_orig_param_set ()
void ncm_model_orig_param_set (NcmModel *model
,guint n
,gdouble val
);
FIXME
ncm_model_orig_vparam_set ()
void ncm_model_orig_vparam_set (NcmModel *model
,guint n
,guint i
,gdouble val
);
ncm_model_orig_vparam_set_vector ()
void ncm_model_orig_vparam_set_vector (NcmModel *model
,guint n
,NcmVector *val
);
FIXME
ncm_model_param_peek_desc ()
NcmSParam * ncm_model_param_peek_desc (NcmModel *model
,guint n
);
Peeks the n
-th parameter description.
ncm_model_orig_vparam_get_vector ()
NcmVector * ncm_model_orig_vparam_get_vector (NcmModel *model
,guint n
);
FIXME
ncm_model_params_copyto ()
void ncm_model_params_copyto (NcmModel *model
,NcmModel *model_dest
);
FIXME
ncm_model_params_set_all_data ()
void ncm_model_params_set_all_data (NcmModel *model
,gdouble *data
);
FIXME
ncm_model_params_set_vector ()
void ncm_model_params_set_vector (NcmModel *model
,NcmVector *v
);
FIXME
ncm_model_params_set_model ()
void ncm_model_params_set_model (NcmModel *model
,NcmModel *model_src
);
FIXME
ncm_model_params_print_all ()
void ncm_model_params_print_all (NcmModel *model
,FILE *out
);
FIXME
[skip]
ncm_model_params_valid_bounds ()
gboolean
ncm_model_params_valid_bounds (NcmModel *model
);
Check whenever the paremeters respect the bounds.
ncm_model_orig_param_index_from_name ()
gboolean ncm_model_orig_param_index_from_name (NcmModel *model
,const gchar *param_name
,guint *i
);
Looks for parameter named param_name
in the original parameters of model
and puts its index in i
and returns TRUE if found.
ncm_model_param_index_from_name ()
gboolean ncm_model_param_index_from_name (NcmModel *model
,const gchar *param_name
,guint *i
);
Looks for parameter named param_name
in model
and puts its index in i
and returns TRUE if found.
ncm_model_orig_param_symbol ()
const gchar * ncm_model_orig_param_symbol (NcmModel *model
,guint n
);
ncm_model_param_set_by_name ()
void ncm_model_param_set_by_name (NcmModel *model
,const gchar *param_name
,gdouble val
);
Sets the parameter value val
by param_name
.
ncm_model_orig_param_set_by_name ()
void ncm_model_orig_param_set_by_name (NcmModel *model
,const gchar *param_name
,gdouble val
);
Sets the parameter value val
by param_name
.
ncm_model_param_get_by_name ()
gdouble ncm_model_param_get_by_name (NcmModel *model
,const gchar *param_name
);
Gets the parameter value by param_name
ncm_model_orig_param_get_by_name ()
gdouble ncm_model_orig_param_get_by_name (NcmModel *model
,const gchar *param_name
);
Gets the original parameter value by param_name
.
ncm_model_orig_param_get_scale ()
gdouble ncm_model_orig_param_get_scale (NcmModel *model
,guint n
);
Gets the scale of the original n
-th parameter.
ncm_model_orig_param_get_lower_bound ()
gdouble ncm_model_orig_param_get_lower_bound (NcmModel *model
,guint n
);
Gets the lower bound of the original n
-th parameter.
ncm_model_orig_param_get_upper_bound ()
gdouble ncm_model_orig_param_get_upper_bound (NcmModel *model
,guint n
);
Gets the upper bound of the original n
-th parameter.
ncm_model_orig_param_get_abstol ()
gdouble ncm_model_orig_param_get_abstol (NcmModel *model
,guint n
);
Gets the absolute tolerance of the original n
-th parameter.
ncm_model_param_get_scale ()
gdouble ncm_model_param_get_scale (NcmModel *model
,guint n
);
Gets the scale of the n
-th parameter.
ncm_model_param_get_lower_bound ()
gdouble ncm_model_param_get_lower_bound (NcmModel *model
,guint n
);
Gets the lower bound of the n
-th parameter.
ncm_model_param_get_upper_bound ()
gdouble ncm_model_param_get_upper_bound (NcmModel *model
,guint n
);
Gets the upper bound of the n
-th parameter.
ncm_model_param_get_abstol ()
gdouble ncm_model_param_get_abstol (NcmModel *model
,guint n
);
Gets the absolute tolerance of the n
-th parameter.
ncm_model_param_get_ftype ()
NcmParamType ncm_model_param_get_ftype (NcmModel *model
,guint n
);
Gets the fitting type of the n
-th parameter.
ncm_model_param_set_scale ()
void ncm_model_param_set_scale (NcmModel *model
,guint n
,const gdouble scale
);
FIXME
ncm_model_param_set_lower_bound ()
void ncm_model_param_set_lower_bound (NcmModel *model
,guint n
,const gdouble lb
);
Sets lb
as the lower-bound value of the n
-th parameter.
ncm_model_param_set_upper_bound ()
void ncm_model_param_set_upper_bound (NcmModel *model
,guint n
,const gdouble ub
);
Sets ub
as the lower-bound value of the n
-th parameter.
ncm_model_param_set_abstol ()
void ncm_model_param_set_abstol (NcmModel *model
,guint n
,const gdouble abstol
);
FIXME
ncm_model_param_set_ftype ()
void ncm_model_param_set_ftype (NcmModel *model
,guint n
,const NcmParamType ptype
);
Sets ptype
as NcmParamType of the n
-th parameter.
ncm_model_reparam_df ()
void ncm_model_reparam_df (NcmModel *model
,NcmVector *fv
,NcmVector *v
);
FIXME
ncm_model_reparam_J ()
void ncm_model_reparam_J (NcmModel *model
,NcmMatrix *fJ
,NcmMatrix *J
);
FIXME
Property Details
The “implementation”
property
“implementation” guint64
Bitwise specification of functions implementation.
Flags: Read
Default value: 0
The “scalar-params-len”
property
“scalar-params-len” guint
Number of scalar parameters.
Flags: Read
Default value: 0
The “vector-params-len”
property
“vector-params-len” guint
Number of vector parameters.
Flags: Read
Default value: 0