![]() |
|
Go to the source code of this file.
| double apop_linear_constraint | ( | gsl_vector * | beta, | |
| apop_data * | constraint, | |||
| double | margin | |||
| ) |
This is designed to be called from within your own constraint function. Just write the constraint vector+matrix and this will do the rest.
| beta | The proposed vector about to be tested. (No default, must not be NULL) | |
| constraint | The constraints. See apop_f_test on writing (Default: each elements is greater than zero) contrasts. To give a quick example, say your constraint is $3 < 2x + 4y - 7z$; then the first row of your data->vector element would be 3, and the first row of the data->matrix element would be [2 4 -7]. | |
| margin | If zero, then this is a >= constraint, otherwise I will return a point this amount within the borders. You could try GSL_DBL_EPSILON, which is the smallest value a double can hold, or something like 1e-3. (Default = 0.) |
beta is shifted by margin (Euclidian distance) to meet the constraints.This function uses the Designated initializers syntax for inputs.
| 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.
As well as a pointer to the model whose parameters are to be fixed, I need two sets of data.
For the fixed parameters, I need to know the values at which they'll be fixed. Send me an apop_data set that has the same shape as the parameters of your model; at the positions of the fixed parameters, give the values to which they will be fixed. For the free parameters, I (mostly) don't care what value they have. This set of parameters can be either set as the model_in->parameters element, or as an argument to the model. [If you give me both, I will use the one explicitly sent in rather than the one attached to the input model.]
I also need to know which parameters to fix, which requires a mask that I can hold over the paramete set. Again, the mask is an apop_data set of the same size and shape as your data. Where there is a nonzero marker, I will fix the parameter.
You again have two options for giving me this information. You can use the parameter matrix as the mask: just set parameters to be left free to a nonzero value (including GSL_NAN). Or, you can explicitly send in a mask, with ones at params to be fixed and zero elsewhere. Again, I will try the explicit mask first.
You also need to input the base model, which I will copy (along with its settings groups) to form the new model.
The output is an apop_model that can be estimated, Bayesian updated, et cetera.
estimate method always uses an MLE, and it never calls the base model's estimate method.estimate method. Otherwise, I'll set my own.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(){ gsl_rng *r = apop_rng_alloc(10); size_t i, ct = 1e4; apop_data *d = apop_data_alloc(0,ct,2); double draws[2]; apop_data *params = apop_data_alloc(2,2,2); apop_data_fill(params, 8, 1, 0.5, 2, 0.5, 1); apop_model *pvm = apop_model_copy(apop_multivariate_normal); pvm->parameters = apop_data_copy(params); for(i=0; i< ct; i++){ apop_draw(draws, r, pvm); apop_data_set(d, i, 0, draws[0]); apop_data_set(d, i, 1, draws[1]); } gsl_vector_set_all(pvm->parameters->vector, GSL_NAN); apop_model *mep1 = apop_model_fix_params(pvm); apop_model *e1 = apop_estimate(d, *mep1); printf("original params: "); apop_vector_show(params->vector); printf("estimated params: "); apop_vector_show(e1->parameters->vector); return 0; }
| model_in | The base model |
| apop_data* apop_model_hessian | ( | apop_data * | data, | |
| apop_model * | model, | |||
| double | delta | |||
| ) |
Numerically estimate the matrix of second derivatives of the parameter values. The math is simply a series of re-evaluations at small differential steps. [Therefore, it may be expensive to do this for a very computationally-intensive model.]
| data | The data at which the model was estimated | |
| model | The model, with parameters already estimated | |
| delta | the step size for the differentials. The current default is around 1e-3. |
This function uses the Designated initializers syntax for inputs.
| apop_data* apop_model_numerical_covariance | ( | apop_data * | data, | |
| apop_model * | model, | |||
| double | delta | |||
| ) |
Produce the covariance matrix for the parameters of an estimated model via the derivative of the score function at the parameter. I.e., I find the second derivative via apop_model_hessian , and take the negation of the inverse.
I follow Efron and Hinkley in using the estimated information matrix---the value of the information matrix at the estimated value of the score---not the expected information matrix that is the integral over all possible data. See Pawitan 2001 (who cribbed a little off of Efron and Hinkley) or Klemens 2008 (who directly cribbed off of both) for further details.
| data | The data by which your model was estimated | |
| model | A model whose parameters have been estimated. | |
| delta | The differential by which to step for sampling changes. (default currently = 1e-3) |
model->covariance != NULL, I'll set it to the result as well.This function uses the Designated initializers syntax for inputs.