Esempio n. 1
0
        public static double EvaluateLn <DistributionType, DomainType>(DistributionArray <DistributionType> darray, DomainType[,] array)
            where DistributionType : CanGetLogProb <DomainType>,
        ICloneable,
        SettableTo <DistributionType>,
        SettableToUniform,
        Diffable,
        SettableToProduct <DistributionType>,
        SettableToRatio <DistributionType>,
        SettableToPower <DistributionType>,
        SettableToWeightedSum <DistributionType>,
        CanGetLogAverageOf <DistributionType>,
        CanGetAverageLog <DistributionType>
        {
            if (darray.array2D == null)
            {
                throw new ArgumentException("DistributionArray has rank " + darray.array.Rank + ", point has rank " + array.Rank);
            }
            if (darray.array2D.GetLength(0) != array.GetLength(0))
            {
                throw new ArgumentException("DistributionArray lengths (" +
                                            StringUtil.CollectionToString(darray.GetLengths(), ",") + ") do not match array lengths (" +
                                            StringUtil.CollectionToString(StringUtil.ArrayDimensions(array), ",") + ")");
            }
            double sum = 0.0;

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    sum += darray[i, j].GetLogProb(array[i, j]);
                }
            }
            return(sum);
        }
Esempio n. 2
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="that"></param>
 public DistributionArray(DistributionArray <T> that)
     : this(that.GetLengths())
 {
     InitializeTo(that);
 }