úÎhªdkL      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKportable experimentalfelipe.lessa@gmail.com Safe-Infered  A matrix. Size of the matrix. Element at position. 3A matrix where all elements are of the same value. /A matrix where all rows are of the same value. 8Creates a matrix from a vector of vectors. It *is not* 2 verified that the vectors have the right length. <Creates a matrix from a vector of vectors. The vectors are  transposed, so  fromVectorT is the same as  transpose  . fromVector-. It *is* verified that the vectors have the  right length. O(rows)) Rows of the matrix. Each element takes O(1) time and  storage. O(1) m !!! i is the i-th row of the matrix.  O(rows*cols), Columns of the matrix. Each element takes  O(rows) time and storage. O(rows) m  i is the i-th column of the matrix. rzipWith f m n- is a matrix with the same number of rows as  m. The i -th row is obtained by applying f to the i-th  rows of m and n.     portable experimentalfelipe.lessa@gmail.com Safe-Infered4Logarithm of the beta function applied to a vector. Infinity, currently defined as 1e100. Used mainly as the  initial cost. portable experimentalfelipe.lessa@gmail.com Safe-InferedResult of a deriviation. $Reason why the derivation was over. Number of iterations spent. Last difference between costs. )Last cost (i.e. the cost of the result). !Result obtained. "$Reason why the derivation was over. #!CG_DESCENT returned this result,  which brought the derivation  process to a halt. $!The maximum number of iterations ! was reached while the delta was ' still greater than the minimum delta. %The difference between # applications of the cost function " dropped below the minimum delta.  In other words, it coverged. &7Predicate specifying when the training should be over. (Maximum number of iterations. )%Minimum delta to continue iterating.  This is invariant of  deltaSteps, which  means that if  deltaSteps is 2 then * minDelta will be considered twice bigger  to account for the different  deltaSteps. *)How many estimation steps should be done % before recalculating the delta. If   deltaSteps is 1 then it will be  recalculated on every step. + Maximum number of iterations on  each weight step. ,%Used only when calculating mixtures. ( When the delta drops below this cutoff ) the computation changes from estimating ( the alphas to estimatating the weights ) and vice-versa. Should be greater than  minDelta. -6Maximum difference between costs to consider that the  process converged. .;Usually denoted by lowercase greek letter eta (·), size of > each step in the gradient. Should be greater than zero and  much less than one. 0<A vector of training vectors. This is the only vector that ' is not unboxed (for obvious reasons). 19A vector used for deriving the parameters of a Dirichlet  density or mixture.  !"#$%&'()*+,-./01L !"#$%&'()*+,-./0110./-&'()*+,"%$# ! !"%$#&'()*+,-./01Lportable experimentalfelipe.lessa@gmail.com Safe-Infered2A Dirichlet density. 5 empty n x is an "empty" Dirichlet density with size  n and all alphas set to x. 6 fromList xs/ constructs a Dirichlet density from a list of  alpha values. 7toList d/ deconstructs a Dirichlet density to a list of  alpha values. 8=Derive a Dirichlet density using a maximum likelihood method < as described by Karplus et al (equation 26). All training : vectors should have the same length, however this is not  verified. 99Cost function for deriving a Dirichlet density (equation % 18). This function is minimized by 8. 23456789MNO2345678923456789 23456789MNOportable experimentalfelipe.lessa@gmail.com Safe-Infered:$Pre-processed training vectors (see H). ;=A list representation of a component of a Dirichlet mixture.  Used by E and F only. <A Dirichlet mixture. >Weights of each density. ?1Values of all parameters of all densities. This  matrix has length dmWeights rows. @-Number of components in a dirichlet mixture. A)Number of parameters each component has. BSeparated list of densities. Cdm !!! i is the i%-th density. No bounding checks are  made. D empty q n x is an "empty" Dirichlet mixture with q  components and n& parameters. Each component has size n, ? weight inversely proportional to its index and all alphas set  to x. E fromList xs' constructs a Dirichlet mixture from a @ non-empty list of components. Each component has a weight and ? a list of alpha values. The weights sum to 1, all lists must 9 have the same number of values and every number must be : non-negative. None of these preconditions are verified. F toList dm is the inverse of fromList, constructs a list = of components from a Dirichlet mixture. There are no error  conditions and toList . fromList == id. G7Constructs a Dirichlet mixture of one component from a  Dirichlet density. H7Prepares training vectors to be used as training data. 7 Anything that depends only on the training vectors is  precalculated here. ;We also try to find columns where all training vectors are > zero. Those columns are removed from the derivation process @ and every component will have zero value on that column. Note 8 that at least one column should have non-zero training  vectors. I9Cost function for deriving a Dirichlet mixture (equation % 18). This function is minimized by K. Calculated  using (17) and (54). J-Derivative of the cost function with respect w_{i,j}, < defined by Equation (22). The result is given in the same  size and order as the  dmDensitites vector. K=Derive a Dirichlet mixture using a maximum likelihood method > as described by Karplus et al (equation 25) using CG_DESCENT  method by Hager and Zhang (see  ,Numeric.Optimization.Algorithms.HagerZhang05). All training : vectors should have the same length, however this is not  verified. :;<=>?@ABCDEFGHIJKPQR:;<=>?@ABCDEFGHIJK<=>?@ABCD;EFG:HKIJ:;<=>?@ABCDEFGHIJKPQRportable experimentalfelipe.lessa@gmail.com Safe-Infered# !"#$%&'()*+,-./01:;<=>?DEFHIK#<=>?D;EF10./-&'()*+,"%$# !:HKIS      !""#$%&'()*+,-./012+3456789:;<=>?@ABCDEFG:;<HI>J=KLMNOPQRstatistics-dirichlet-0.6 Math.Statistics.Dirichlet.MatrixMath.Statistics.Dirichlet.Util!Math.Statistics.Dirichlet.Options!Math.Statistics.Dirichlet.Density!Math.Statistics.Dirichlet.MixtureMath.Statistics.DirichletMatrixMmRowsmColsmDatasize! replicate replicateRows fromVector fromVectorTrows!!!colscolumapmapimaprowmapirowmapuzipWithzipWithizipWithrzipWith transposelogBetainfinityResultreasoniters lastDeltalastCostresultReasonCGMaxIterDelta PredicatePredmaxIterminDelta deltaSteps maxWeightIter jumpDeltaStepSizeStepTrainingVectorsTrainingVectorDirichletDensityDDunDDemptyfromListtoListderivecost TrainingData ComponentDirichletMixtureDM dmWeights dmDensities dmComponents dmParameters dmDensitiesLfromDDprepareTraining del_cost_w$fNFDataResult$fNFDataDirichletDensity$fReadDirichletDensity$fShowDirichletDensity$fNFDataDirichletMixture$fReadDirichletMixture$fShowDirichletMixture