![]() |
|
This implements a one-d histogram representing an empirical distribution. It is primarily a wrapper for the GSL's comparable functions in the standard apop_model form, for easy comparison with other models.
| apop_histogram_settings* apop_histogram_settings_alloc | ( | apop_data * | data, | |
| int | bins | |||
| ) |
Allocate the parameters for the apop_histogram model.
| data | The input data. I'll use all data in both the the matrix and vector element of the apop_data set, and the matrix can have any dimensions ( , , ...). | |
| bins | How many bins should the PDF have? |
| apop_histogram_settings* apop_kernel_density_settings_alloc | ( | apop_data * | data, | |
| apop_model * | histobase, | |||
| apop_model * | kernelbase, | |||
| void(*)(double, apop_model *) | set_params | |||
| ) |
Allocate and fill a kernel density, which is a smoothed histogram.
You may either provide a histogram and a NULL data set, or a NULL histogram and a real data set, in which case I will convert the data set into a histogram and use the histogram thus created.
| data | a data set, which, if not NULL and !histobase , will be converted to a histogram. | |
| histobase | This is the preferred format for input data. It is the histogram to be smoothed. | |
| kernelbase | The kernel to use for smoothing, with all parameters set and a p method. Popular favorites are apop_normal and apop_uniform. | |
| set_params | A function that takes in a single number and the model, and sets the parameters accordingly. The function will call this for every point in the data set. Below is the default, which is used if this is NULL. It simply sets the first element of the model's parameter vector to the input number; this is appropriate for a Normal distribution, where we want to center the distribution on each data point in turn. |
void apop_set_first_params(double in, apop_model *m){ m->parameters->vector->data[0] = in; }
The histogram model.
This is an empirical distribution. If you have a data set from which you want to make random draws, this is overkill; instead just use something like
gsl_rng *r = apop_rng_alloc(27); gsl_vector *my_data = [gather data here.]; gsl_vector_get(my_data, gsl_rng_uniform(r)*my_data->size);
But this can be used anywhere a model is needed, such as the inputs and outputs to apop_update.
The model is unlike most other models in that there are no parameters of any sort (beyond the data itself), so there is no estimate method; instead all the work of producing the histogram is done in apop_histogram_settings_alloc. [Actually, there is an estimate method, but it is just an alias for the histogram_alloc function.]
The apop_kernel_density model.
A Kernel density is simply a smoothing of a histogram. At each point along the histogram, put a distribution (default: Normal(0,1)) on top of the point. Sum all of these distributions to form the output histogram.
The output is a histogram that behaves exactly like the gsl_histogram, except the histobase and kernelbase elements are set.