I want to implement a probability space with a density wrt R^n as follows:
typedef struct _ProbabilitySpace {
int dim;
double (*density)(double *first, double *last);
/** more stuff **/
} ProbabilitySpace;
Now, with this implementation, how would it be possible to implement a family of density functions? Lets say, I want to implement the gaussian family, then I could write a function
double gaussian(struct vec mu, struct mat sigma, double *first, double *last){
/** gaussian density function here */
}
As you see, this density depends not only on the arguments *first and *last, but also on mu and sigma. I want to give the user the possibility, to specify mu and sigma once (probably at runtime), without having to pass it around all the time. Also, this function might be used for different combinations of (mu, sigma) in different ProbabilitySpace objects.
A solution in C++ would be to create another class like this:
class _Density{
public:
double evaluate(double* first, double* last);
private:
/** any private parameters **/
};
Any family of probability distributions could inherit from this class and define private parameters, which the user must initialize in the constructor. The evaluate member function could then access these private parameters.
But in C, I don't see any way to specify parameters other than in the parameter-list for any function, as they cannot access other member variables.
Maybe someone can suggest a solution?