Exemple #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);
        }
Exemple #2
0
        public static DistributionArray <T> CloneElementsOf(Array array)
        {
            DistributionArray <T> result = new DistributionArray <T>(StringUtil.ArrayDimensions(array));

            result.ModifyAll(array, delegate(T item, T aItem)
            {
                return((T)aItem.Clone());
            });
            return(result);
        }
Exemple #3
0
 public ArrayAsList(Array array)
 {
     this.array = array;
     if (array.Rank == 1)
     {
         array1D = (T[])array;
     }
     else if (array.Rank == 2)
     {
         array2D = (T[, ])array;
     }
     else
     {
         strides = StringUtil.ArrayStrides(StringUtil.ArrayDimensions(array));
     }
 }
Exemple #4
0
 public static MultiRange ArrayIndices(Array array)
 {
     return(new MultiRange(StringUtil.ArrayLowerBounds(array), StringUtil.ArrayDimensions(array)));
 }
Exemple #5
0
 public int[] GetLengths()
 {
     return(StringUtil.ArrayDimensions(array));
 }