Patterns in static

Apophenia

Data Structures | Macros | Functions
apop_fix_params.c File Reference

Data Structures

struct  apop_fix_params_settings
 

Macros

#define cut_if_missing(method)   if (!model_in->method) model_out->method = NULL;
 

Functions

 Apop_settings_init (Apop_settings_copy(apop_fix_params, Apop_assert(in.base_model,"I can't fix a NULL model's parameters.");)
 
void set_starting_point (apop_data *in_params, apop_model *model_out, double *start, apop_data *predict_tab)
 
apop_modelapop_model_fix_params (apop_model *model_in)
 
apop_modelapop_model_fix_params_get_base (apop_model *fixed_model)
 

Detailed Description

Set some of the parameters of a model to fixed values.

Function Documentation

apop_model* apop_model_fix_params ( apop_model model_in)

Produce a model based on another model, but with some of the parameters fixed at a given value.

You will send me the model whose parameters you want fixed, with the parameters element set as follows. For the fixed parameters, simply give the values to which they will be fixed. Set the free parameters to NaN.

For example, here is a Binomial distribution with a fixed $n=30$ but $p_1$ allowed to float freely:

1 apop_model *bi30 = apop_model_fix_params(apop_model_set_parameters(apop_binomial, 30, GSL_NAN));
2 Apop_model_add_group(bi30, apop_mle, .starting_pt=(double[]){.5}); // The Binomial doesn't like the default
3  // starting point of 1.
4 apop_model *out = apop_estimate(your_data, bi30);

The output is an apop_model that can be estimated, Bayesian updated, et cetera.

  • Rather than using this model, you may simply want a now-filled-in copy of the original model. Use apop_model_fix_params_get_base to retrieve the original model's parameters.
  • The estimate method always uses an MLE, and it never calls the base model's estimate method.
  • If the input model has MLE-style settings attached, I'll use them for the estimate method. Otherwise, I'll set my own.
  • If the parameter input has non-NaN values at the free parameters, then I'll use those as the starting point for any MLE search; the defaults for the variables without fixed values starts from 1 as usual.
  • I do check the more pointer of the parameters for additional pages and NaNs on those pages.

Here is a sample program. It produces a few thousand draws from a Multivariate Normal distribution, and then tries to recover the means given a var/covar matrix fixed at the correct variance.

#include <apop.h>
int main(){
size_t ct = 5e4;
//set up the model & params
apop_data *params = apop_data_alloc(2,2,2);
apop_data_fill(params, 8, 1, 0.5,
2, 0.5, 1);
pvm->parameters = apop_data_copy(params);
pvm->dsize = 2;
apop_data *d = apop_model_draws(pvm, ct);
//set up and estimate a model with fixed covariance matrix but free means
gsl_vector_set_all(pvm->parameters->vector, GSL_NAN);
apop_model *e1 = apop_estimate(d, mep1);
//compare results, via assert for the test suite, or on-screen for human use.
#ifdef Testing
assert(apop_vector_distance(params->vector, e1->parameters->vector)<1e-2);
#else
printf("original params: ");
apop_vector_show(params->vector);
printf("estimated params: ");
#endif
}
Parameters
model_inThe base model
Returns
a model that can be used like any other, with the given params fixed or free.
apop_model* apop_model_fix_params_get_base ( apop_model fixed_model)

The apop_model_fix_params function produces a model that has only the non-fixed parameters of the model. After estimation of the fixed-parameter model, this function fills the parameters element of the base model and returns a pointer to the base model.

Autogenerated by doxygen on Wed Oct 15 2014 (Debian 0.999b+ds3-2).