getValues() public method

public getValues ( ) : double[]
return double[]
Ejemplo n.º 1
0
        public ProbabilityTable pointwiseProductPOS(
            ProbabilityTable multiplier, params RandomVariable[] prodVarOrder)
        {
            ProbabilityTable product = new ProbabilityTable(prodVarOrder);

            if (!product.randomVarInfo.keySet().Equals(
                    SetOps.union(new List <RandomVariable>(randomVarInfo.keySet()),
                                 new List <RandomVariable>(multiplier.randomVarInfo
                                                           .keySet()))))
            {
                if (1 == product.getValues().Length)
                {
                    product.getValues()[0] = getValues()[0] * multiplier.getValues()[0];
                }
                else
                {
                    // Otherwise need to iterate through the product
                    // to calculate its values based on the terms.
                    Object[] term1Values = new Object[randomVarInfo.size()];
                    Object[] term2Values = new Object[multiplier.randomVarInfo
                                                      .size()];
                    //ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {
                    //    private int idx = 0;

                    //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                    //            double probability) {
                    //        int term1Idx = termIdx(term1Values, ProbabilityTable.this,
                    //                possibleWorld);
                    //        int term2Idx = termIdx(term2Values, multiplier,
                    //                possibleWorld);

                    //        product.getValues()[idx] = getValues()[term1Idx]
                    //                * multiplier.getValues()[term2Idx];

                    //        idx++;
                    //    }

                    //    private int termIdx(Object[] termValues, ProbabilityTable d,
                    //            Map<RandomVariable, Object> possibleWorld) {
                    //        if (0 == termValues.Length) {
                    //            // The term has no variables so always position 0.
                    //            return 0;
                    //        }

                    //        int i = 0;
                    //        for (RandomVariable rv : d.randomVarInfo.keySet()) {
                    //            termValues[i] = possibleWorld.get(rv);
                    //            i++;
                    //        }

                    //        return d.getIndex(termValues);
                    //    }
                    //};
                    //product.iterateOverTable(di);
                    // TODO
                }
            }
            return(product);
        }
Ejemplo n.º 2
0
        public ProbabilityTable sumOut(params RandomVariable[] vars)
        {
            Set <RandomVariable> soutVars = new Set <RandomVariable>(
                this.randomVarInfo.keySet());

            foreach (RandomVariable rv in vars)
            {
                soutVars.remove(rv);
            }
            ProbabilityTable summedOut = new ProbabilityTable(soutVars);

            if (1 == summedOut.getValues().Length)
            {
                summedOut.getValues()[0] = getSum();
            }
            else
            {
                // Otherwise need to iterate through this distribution
                // to calculate the summed out distribution.
                Object[] termValues = new Object[summedOut.randomVarInfo
                                                 .size()];
                //ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {
                //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                //            double probability) {

                //        int i = 0;
                //        foreach (RandomVariable rv in summedOut.randomVarInfo.keySet()) {
                //            termValues[i] = possibleWorld.get(rv);
                //            i++;
                //        }
                //        summedOut.getValues()[summedOut.getIndex(termValues)] += probability;
                //    }
                //};
                //iterateOverTable(di);
                //TODO:
            }

            return(summedOut);
        }
Ejemplo n.º 3
0
        public ProbabilityTable divideBy(ProbabilityTable divisor)
        {
            if (!randomVarInfo.keySet().containsAll(divisor.randomVarInfo.keySet()))
            {
                throw new IllegalArgumentException(
                          "Divisor must be a subset of the dividend.");
            }

            ProbabilityTable quotient = new ProbabilityTable(new List <RandomVariable>(randomVarInfo.Keys));

            if (1 == divisor.getValues().Length)
            {
                double d = divisor.getValues()[0];
                for (int i = 0; i < quotient.getValues().Length; i++)
                {
                    if (0 == d)
                    {
                        quotient.getValues()[i] = 0;
                    }
                    else
                    {
                        quotient.getValues()[i] = getValues()[i] / d;
                    }
                }
            }
            else
            {
                Set <RandomVariable> dividendDivisorDiff = SetOps
                                                           .difference(new List <RVInfo>(randomVarInfo.keySet()),
                                                                       new List <RVInfo>(randomVarInfo.keySet()));
                Map <RandomVariable, RVInfo> tdiff = null;
                MixedRadixNumber             tdMRN = null;
                if (dividendDivisorDiff.size() > 0)
                {
                    tdiff = new LinkedHashMap <RandomVariable, RVInfo>();
                    foreach (RandomVariable rv in dividendDivisorDiff)
                    {
                        tdiff.put(rv, new RVInfo(rv));
                    }
                    tdMRN = new MixedRadixNumber(0, createRadixs(tdiff));
                }
                Map <RandomVariable, RVInfo> diff = tdiff;
                MixedRadixNumber             dMRN = tdMRN;
                int[]            qRVs             = new int[quotient.radices.Length];
                MixedRadixNumber qMRN             = new MixedRadixNumber(0,
                                                                         quotient.radices);
                //ProbabilityTable.Iterator divisorIterator = new ProbabilityTable.Iterator() {
                //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                //            double probability) {
                //        foreach (RandomVariable rv in possibleWorld.keySet()) {
                //            RVInfo rvInfo = quotient.randomVarInfo.get(rv);
                //            qRVs[rvInfo.getRadixIdx()] = rvInfo
                //                    .getIdxForDomain(possibleWorld.get(rv));
                //        }
                //        if (null != diff) {
                //            // Start from 0 off the diff
                //            dMRN.setCurrentValueFor(new int[diff.size()]);
                //            do {
                //                for (RandomVariable rv : diff.keySet()) {
                //                    RVInfo drvInfo = diff.get(rv);
                //                    RVInfo qrvInfo = quotient.randomVarInfo.get(rv);
                //                    qRVs[qrvInfo.getRadixIdx()] = dMRN
                //                            .getCurrentNumeralValue(drvInfo
                //                                    .getRadixIdx());
                //                }
                //                updateQuotient(probability);
                //            } while (dMRN.increment());
                //        } else {
                //            updateQuotient(probability);
                //        }
                //    }

                //    //
                //
                //private void updateQuotient(double probability) {
                //    int offset = (int) qMRN.getCurrentValueFor(qRVs);
                //    if (0 == probability) {
                //        quotient.getValues()[offset] = 0;
                //    } else {
                //        quotient.getValues()[offset] += getValues()[offset]
                //                / probability;
                //    }
                //}
                //////  };

                //	divisor.iterateOverTable(divisorIterator);
                // TODO
            }

            return(quotient);
        }
Ejemplo n.º 4
0
        public ProbabilityTable pointwiseProductPOS(
            ProbabilityTable multiplier, params RandomVariable[] prodVarOrder)
        {
            ProbabilityTable product = new ProbabilityTable(prodVarOrder);
            if (!product.randomVarInfo.keySet().Equals(
                SetOps.union(new List<RandomVariable>(randomVarInfo.keySet()),
                                                      new List<RandomVariable>(multiplier.randomVarInfo
                                                                                   .keySet()))))
            {
                if (1 == product.getValues().Length)
                {
                    product.getValues()[0] = getValues()[0]*multiplier.getValues()[0];
                }
                else
                {
                    // Otherwise need to iterate through the product
                    // to calculate its values based on the terms.
                    Object[] term1Values = new Object[randomVarInfo.size()];
                    Object[] term2Values = new Object[multiplier.randomVarInfo
                        .size()];
                    //ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {
                    //    private int idx = 0;

                    //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                    //            double probability) {
                    //        int term1Idx = termIdx(term1Values, ProbabilityTable.this,
                    //                possibleWorld);
                    //        int term2Idx = termIdx(term2Values, multiplier,
                    //                possibleWorld);

                    //        product.getValues()[idx] = getValues()[term1Idx]
                    //                * multiplier.getValues()[term2Idx];

                    //        idx++;
                    //    }

                    //    private int termIdx(Object[] termValues, ProbabilityTable d,
                    //            Map<RandomVariable, Object> possibleWorld) {
                    //        if (0 == termValues.Length) {
                    //            // The term has no variables so always position 0.
                    //            return 0;
                    //        }

                    //        int i = 0;
                    //        for (RandomVariable rv : d.randomVarInfo.keySet()) {
                    //            termValues[i] = possibleWorld.get(rv);
                    //            i++;
                    //        }

                    //        return d.getIndex(termValues);
                    //    }
                    //};
                    //product.iterateOverTable(di);
                    // TODO		
                }
            }
            return product;
        }
Ejemplo n.º 5
0
        public ProbabilityTable divideBy(ProbabilityTable divisor)
        {
            if (!randomVarInfo.keySet().containsAll(divisor.randomVarInfo.keySet()))
            {
                throw new IllegalArgumentException(
                    "Divisor must be a subset of the dividend.");
            }

            ProbabilityTable quotient = new ProbabilityTable(new List<RandomVariable>(randomVarInfo.Keys));

            if (1 == divisor.getValues().Length)
            {
                double d = divisor.getValues()[0];
                for (int i = 0; i < quotient.getValues().Length; i++)
                {
                    if (0 == d)
                    {
                        quotient.getValues()[i] = 0;
                    }
                    else
                    {
                        quotient.getValues()[i] = getValues()[i]/d;
                    }
                }
            }
            else
            {
                Set<RandomVariable> dividendDivisorDiff = SetOps
                    .difference(new List<RVInfo>(randomVarInfo.keySet()),
                                new List<RVInfo>(randomVarInfo.keySet()));
                Map<RandomVariable, RVInfo> tdiff = null;
                MixedRadixNumber tdMRN = null;
                if (dividendDivisorDiff.size() > 0)
                {
                    tdiff = new LinkedHashMap<RandomVariable, RVInfo>();
                    foreach (RandomVariable rv in dividendDivisorDiff)
                    {
                        tdiff.put(rv, new RVInfo(rv));
                    }
                    tdMRN = new MixedRadixNumber(0, createRadixs(tdiff));
                }
                Map<RandomVariable, RVInfo> diff = tdiff;
                MixedRadixNumber dMRN = tdMRN;
                int[] qRVs = new int[quotient.radices.Length];
                MixedRadixNumber qMRN = new MixedRadixNumber(0,
                                                             quotient.radices);
                //ProbabilityTable.Iterator divisorIterator = new ProbabilityTable.Iterator() {
                //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                //            double probability) {
                //        foreach (RandomVariable rv in possibleWorld.keySet()) {
                //            RVInfo rvInfo = quotient.randomVarInfo.get(rv);
                //            qRVs[rvInfo.getRadixIdx()] = rvInfo
                //                    .getIdxForDomain(possibleWorld.get(rv));
                //        }
                //        if (null != diff) {
                //            // Start from 0 off the diff
                //            dMRN.setCurrentValueFor(new int[diff.size()]);
                //            do {
                //                for (RandomVariable rv : diff.keySet()) {
                //                    RVInfo drvInfo = diff.get(rv);
                //                    RVInfo qrvInfo = quotient.randomVarInfo.get(rv);
                //                    qRVs[qrvInfo.getRadixIdx()] = dMRN
                //                            .getCurrentNumeralValue(drvInfo
                //                                    .getRadixIdx());
                //                }
                //                updateQuotient(probability);
                //            } while (dMRN.increment());
                //        } else {
                //            updateQuotient(probability);
                //        }
                //    }

                //    //
                //
                //private void updateQuotient(double probability) {
                //    int offset = (int) qMRN.getCurrentValueFor(qRVs);
                //    if (0 == probability) {
                //        quotient.getValues()[offset] = 0;
                //    } else {
                //        quotient.getValues()[offset] += getValues()[offset]
                //                / probability;
                //    }
                //}
                ////// 	};

                //	divisor.iterateOverTable(divisorIterator);
                // TODO
            }

            return quotient;
        }
Ejemplo n.º 6
0
        public ProbabilityTable sumOut(params RandomVariable[] vars)
        {
            Set<RandomVariable> soutVars = new Set<RandomVariable>(
                this.randomVarInfo.keySet());
            foreach (RandomVariable rv in vars)
            {
                soutVars.remove(rv);
            }
            ProbabilityTable summedOut = new ProbabilityTable(soutVars);
            if (1 == summedOut.getValues().Length)
            {
                summedOut.getValues()[0] = getSum();
            }
            else
            {
                // Otherwise need to iterate through this distribution
                // to calculate the summed out distribution.
                Object[] termValues = new Object[summedOut.randomVarInfo
                    .size()];
                //ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {
                //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                //            double probability) {

                //        int i = 0;
                //        foreach (RandomVariable rv in summedOut.randomVarInfo.keySet()) {
                //            termValues[i] = possibleWorld.get(rv);
                //            i++;
                //        }
                //        summedOut.getValues()[summedOut.getIndex(termValues)] += probability;
                //    }
                //};
                //iterateOverTable(di);
                //TODO:
            }

            return summedOut;
        }