コード例 #1
0
        public ProbabilityTable(double[] vals, params RandomVariable[] vars)
        {
            if (null == vals)
            {
                throw new ArgumentException("Values must be specified");
            }
            if (vals.Length != ProbUtil.expectedSizeOfProbabilityTable(vars))
            {
                throw new ArgumentException("ProbabilityTable of Length "
                                            + values.Length + " is not the correct size, should be "
                                            + ProbUtil.expectedSizeOfProbabilityTable(vars)
                                            + " in order to represent all possible combinations.");
            }
            if (null != vars)
            {
                foreach (RandomVariable rv in vars)
                {
                    // Track index information relevant to each variable.
                    randomVarInfo.Add(rv, new RVInfo(rv));
                }
            }

            values = new double[vals.Length];
            Array.Copy(vals, 0, values, 0, vals.Length);

            radices = createRadixs(randomVarInfo);

            if (radices.Length > 0)
            {
                queryMRN = new MixedRadixNumber(0, radices);
            }
        }
コード例 #2
0
ファイル: ProbUtil.cs プロジェクト: claudiu04/AIMA.Net
        /**
         * Calculate the indexes for X[i] into a vector representing the enumeration
         * of the value assignments for the variables X and their corresponding
         * assignment in x. For example the Random Variables:<br>
         * Q::{true, false}, R::{'A', 'B','C'}, and T::{true, false}, would be
         * enumerated in a Vector as follows:
         *
         * <pre>
         * Index  Q      R  T
         * -----  -      -  -
         * 00:    true,  A, true
         * 01:    true,  A, false
         * 02:    true,  B, true
         * 03:    true,  B, false
         * 04:    true,  C, true
         * 05:    true,  C, false
         * 06:    false, A, true
         * 07:    false, A, false
         * 08:    false, B, true
         * 09:    false, B, false
         * 10:    false, C, true
         * 11:    false, C, false
         * </pre>
         *
         * if X[i] = R and x = {..., R='C', ...} then the indexes returned would be
         * [4, 5, 10, 11].
         *
         * @param X
         *            a list of the Random Variables that would comprise the vector.
         * @param idx
         *            the index into X for the Random Variable whose assignment we
         *            wish to retrieve its indexes for.
         * @param x
         *            an assignment for the Random Variables in X.
         * @return the indexes into a vector that would represent the enumeration of
         *         the values for X[i] in x.
         */

        public static int[] indexesOfValue(RandomVariable[] X, int idx,
                                           Map <RandomVariable, Object> x)
        {
            int csize = ProbUtil.expectedSizeOfCategoricalDistribution(X);

            FiniteDomain fd       = (FiniteDomain)X[idx].getDomain();
            int          vdoffset = fd.getOffset(x.get(X[idx]));
            int          vdosize  = fd.size();

            int[] indexes = new int[csize / vdosize];

            int blocksize = csize;

            for (int i = 0; i < X.length; i++)
            {
                blocksize = blocksize / X[i].getDomain().size();
                if (i == idx)
                {
                    break;
                }
            }

            for (int i = 0; i < indexes.Length; i += blocksize)
            {
                int offset = ((i / blocksize) * vdosize * blocksize)
                             + (blocksize * vdoffset);
                for (int b = 0; b < blocksize; b++)
                {
                    indexes[i + b] = offset + b;
                }
            }

            return(indexes);
        }
コード例 #3
0
ファイル: RandVar.cs プロジェクト: claudiu04/AIMA.Net
        public RandVar(String name, IDomain domain)
        {
            ProbUtil.checkValidRandomVariableName(name);
            if (null == domain)
            {
                throw new ArgumentException(
                          "Domain of RandomVariable must be specified.");
            }

            this.name   = name;
            this.domain = domain;
            this.scope.add(this);
        }
コード例 #4
0
 public ProbabilityTable(params RandomVariable[] vars)
     : this(new double[ProbUtil.expectedSizeOfProbabilityTable(vars)], vars)
 {
     ;
 }