/* * gen_dirch.h generating Dirichlet-distributed random vectors * Copyright (C) 2000 Kevin Karplus * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * See http://www.gnu.org/copyleft/lesser.html for the license details, * or write to the Free Software Foundation, Inc., 59 Temple Place, Suite * 330, Boston, MA 02111-1307 USA */ /* This is a header file for a random number generator * that generates probability vectors according to a Dirichlet distribution. * * Kevin Karplus * 6 Nov 2000 * * The functions here are made to look as much like a C++ class as * is possible in ANSI C. */ #ifndef GENDIRCHH #define GENDIRCHH #include "gen_beta.h" // The sample from a Dirichlet distribution is generated by a tree of // beta generators, each of which splits the probability passed down // from above. // // The leaves of the tree are the num_dim places in the output // probability vector (0..num_dim-1). // // The internal nodes of the tree are indicated by indexes >=num_dim. // class gen_dirch { private: int num_dim; // number of dimensions of probability vector double* alpha; // 2*num_dim-1 alpha values // First the leaves, then the internal nodes. int root_index; gen_beta *betas; // num_dim-1 internal nodes int *left, *right; // indexes of subtrees for internal nodes // store the alpha values and build a beta_tree for the generator void initialize(int numd, const double *alp); void initialize(int numd, const float *alp); // Generate the probabilities for a subtree of the whole beta-tree // that defines the Dirichlet distribution, with the sum of the // subtree being total_prob. void subtree(double *probs, double total_prob, int root) const; public: gen_dirch(int numd, const double*alp) {initialize(numd,alp);} gen_dirch(int numd, const float*alp) {initialize(numd,alp);} ~gen_dirch(void) { delete [] right; delete [] left; delete [] betas; delete [] alpha; } // generate a probability vector according to the distribution and // store it in probs void generate(double *probs) const; }; #endif // CHANGE LOG: // Fri Dec 14 11:44:30 PST 2007 Kevin Karplus // Mark Diekhans removed extraneous gen_dirch:: qualifier