/* * gen_dirch_mix.cc generating random vectors * from a mixture Dirichlet densities * Copyright (C) 2000,2005 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 source file for a random number generator * that generates probability vectors according to a * mixture of Dirichlet distributions. * * Kevin Karplus * 7 Nov 2000 * * The functions here are made to look as much like a C++ class as * is possible in ANSI C. */ #include "gen_dirch_mix.h" #include #include "Utilities/Random.h" typedef gen_dirch* gen_dirch_p; void gen_dirch_mix::initialize( int alphabet_size, int num_components, const double *mix, const double **comps) // alpha values are in comps[c][0..alphabet_size-1] { double sum=0.; num_comp = num_components; mix_coeff_cum = new double[num_components]; comp = new gen_dirch_p[num_components]; for (int c=0; c=0); mix_coeff_cum[c] = sum; comp[c] = new gen_dirch(alphabet_size, comps[c]); } assert(sum>0); for (int c=0; c=0); mix_coeff_cum[c] = sum; comp[c] = new gen_dirch(alphabet_size, comps[c]); } assert(sum>0); for (int c=0; c // Wed Jul 20 16:01:20 PDT 2005 Kevin Karplus // converted to c++ // Thu Jul 21 08:45:01 PDT 2005 Kevin Karplus // No longer use awkward indexing starting at 1 for components. // Thu Jan 26 15:33:20 PST 2006 Kevin Karplus // Changed (gen_dirch*) in new arrays to gen_dirch_p