コード例 #1
0
  private static ProbabilityDistribution getPriorProbabilities(Target target) {
    ProbabilityDistribution result = new ProbabilityDistribution();

    List<TargetValue> values = target.getTargetValues();
    for (TargetValue value : values) {

      // "The defaultValue attribute is used only if the optype of the field is continuous"
      if (value.getDefaultValue() != null) {
        throw new InvalidFeatureException(value);
      }

      String targetCategory = value.getValue();
      Double probability = value.getPriorProbability();

      if (targetCategory == null || probability == null) {
        continue;
      }

      result.put(targetCategory, probability);
    }

    if (result.isEmpty()) {
      return null;
    }

    return result;
  }
コード例 #2
0
 protected void assertPDF(
     final double[] z, final double[] x, final ProbabilityDistribution<Double> dist) {
   assertPDFWithNull(dist);
   for (int i = 0; i < z.length; i++) {
     assertEquals(dist.getPDF(x[i]), z[i], EPS);
   }
 }
コード例 #3
0
 protected void assertCDFWithNull(final ProbabilityDistribution<Double> dist) {
   try {
     dist.getCDF(null);
     Assert.fail();
   } catch (final IllegalArgumentException e) {
     // Expected
   }
 }
コード例 #4
0
ファイル: TimeValue.java プロジェクト: saem/JaamSim
  public double getExpectedValueForTime(double time) {
    if (!Double.isNaN(dVal)) return currentValue;

    if (monthVal != null) return currentValue;

    if (probVal != null) return probVal.getExpectedValue();
    return monthProbVal.get(Clock.getMonthIndex(time)).getExpectedValue();
  }
コード例 #5
0
ファイル: TimeValue.java プロジェクト: saem/JaamSim
  public String toString() {
    if (!Double.isNaN(dVal)) return Double.toString(dVal);

    if (monthVal != null) return monthVal.toString();

    if (probVal != null) return probVal.toString();
    return monthProbVal.toString();
  }
 @Test
 public void test() {
   double x;
   final double eps = 1e-5;
   for (int i = 0; i < 100; i++) {
     x = RANDOM.nextDouble();
     assertEquals(x, F.evaluate(T.getCDF(x)), eps);
   }
 }
コード例 #7
0
 protected void assertInverseCDF(final double[] x, final ProbabilityDistribution<Double> dist) {
   assertInverseCDFWithNull(dist);
   for (final double d : x) {
     assertEquals(dist.getInverseCDF(dist.getCDF(d)), d, EPS);
   }
   try {
     dist.getInverseCDF(3.4);
     Assert.fail();
   } catch (final IllegalArgumentException e) {
     // Expected
   }
   try {
     dist.getInverseCDF(-0.2);
     Assert.fail();
   } catch (final IllegalArgumentException e) {
     // Expected
   }
 }
コード例 #8
0
ファイル: TimeValue.java プロジェクト: saem/JaamSim
  public void initialize() {

    if (probVal != null) {
      probVal.initialize();
    }
    if (monthProbVal != null) {
      for (ProbabilityDistribution each : monthProbVal) {
        each.initialize();
      }
    }

    // Initialize the current value
    if (!Double.isNaN(dVal)) currentValue = dVal;

    if (monthVal != null) currentValue = monthVal.get(Clock.getMonthIndex(0));

    if (probVal != null) currentValue = probVal.getExpectedValue();
  }
コード例 #9
0
ファイル: TimeValue.java プロジェクト: saem/JaamSim
  public double getNextValueForTime(double time) {

    if (!Double.isNaN(dVal)) currentValue = dVal;

    if (monthVal != null) currentValue = monthVal.get(Clock.getMonthIndex(time));

    if (probVal != null) currentValue = probVal.nextValue();

    if (monthProbVal != null)
      currentValue = monthProbVal.get(Clock.getMonthIndex(time)).nextValue();

    return currentValue;
  }
コード例 #10
0
 /**
  * @param className ProbabilityDistribution class name
  * @param props
  * @param keyPrefix prefix to use for looking up keys in props
  * @param minid
  * @param maxid
  * @return
  */
 private static AccessDistribution tryDynamicLoad(
     String className,
     Properties props,
     String keyPrefix,
     long minid,
     long maxid,
     DistributionType kind) {
   try {
     Logger logger = Logger.getLogger(ConfigUtil.LINKBENCH_LOGGER);
     logger.debug(
         "Using ProbabilityDistribution class "
             + className
             + " for "
             + kind.toString().toLowerCase());
     ProbabilityDistribution pDist =
         ClassUtil.newInstance(className, ProbabilityDistribution.class);
     pDist.init(minid, maxid, props, keyPrefix);
     InvertibleShuffler shuffler = RealDistribution.getShuffler(kind, maxid - minid);
     return new ProbAccessDistribution(pDist, shuffler);
   } catch (ClassNotFoundException e) {
     throw new LinkBenchConfigError(
         "Access distribution class " + className + " not successfully loaded: " + e.getMessage());
   }
 }
コード例 #11
0
ファイル: BayesNetNode.java プロジェクト: bonnyfone/BayesBox
 /**
  * Ritorna la probabilità della configurazione di eventi passata come parametro.
  *
  * @param conditions configurazione di nodi
  * @return probabilità della configurazione
  */
 public double probabilityOf(Map<String, Boolean> conditions) {
   return distribution.probabilityOf(conditions);
 }
コード例 #12
0
ファイル: BayesNetNode.java プロジェクト: bonnyfone/BayesBox
 /**
  * Imposta la probabilità dell'evento del nodo. Il valore dello stato identifica la configurazione
  * dei padri.</i>
  *
  * @param bi configurazione dei padri
  * @param d probabilità
  */
 public void setProbability(double d, boolean... pi) {
   distribution.set(d, pi);
 }
コード例 #13
0
ファイル: BayesNetNode.java プロジェクト: bonnyfone/BayesBox
 /**
  * Imposta la probabilità dell'evento del nodo. <i>NB:Se il nodo è radice, si considera l'evento
  * atomico. Se il nodo ha delle dipendenze, il valore dello stato identifica la configurazione del
  * padre.</i>
  *
  * @param b stato
  * @param d probabilità
  */
 public void setProbability(boolean b, double d) {
   distribution.set(d, b);
   if (isRoot()) {
     distribution.set(1.0 - d, !b);
   }
 }
コード例 #14
0
 /**
  * @param x The parameters for the function, $(x, y, \rho$, with $-1 \geq \rho \geq 1$, not null
  * @return The cdf
  */
 @Override
 public double getCDF(final double[] x) {
   Validate.notNull(x);
   Validate.isTrue(x.length == 3, "Need a, b and rho values");
   Validate.isTrue(x[2] >= -1 && x[2] <= 1, "Correlation must be >= -1 and <= 1");
   final double a = x[0];
   double b = x[1];
   final double rho = x[2];
   if (a == Double.POSITIVE_INFINITY || b == Double.POSITIVE_INFINITY) {
     return 1;
   }
   if (a == Double.NEGATIVE_INFINITY || b == Double.NEGATIVE_INFINITY) {
     return 0;
   }
   final double sumSq = (a * a + b * b) / 2.;
   double rho1, rho2, rho3, ab, absDiff, h5, c, d, mult = 0, rho3Sq, eab, e, result;
   if (Math.abs(rho) >= 0.7) {
     rho1 = 1 - rho * rho;
     rho2 = Math.sqrt(rho1);
     if (rho < 0) {
       b *= -1;
     }
     ab = a * b;
     eab = Math.exp(-ab / 2.);
     if (Math.abs(rho) < 1) {
       absDiff = Math.abs(a - b);
       h5 = absDiff * absDiff / 2.;
       absDiff = absDiff / rho2;
       c = 0.5 - ab / 8.;
       d = 3. - 2. * c * h5;
       mult =
           0.13298076 * absDiff * d * (1 - NORMAL.getCDF(absDiff))
               - Math.exp(-h5 / rho1) * (d + c * rho1) * 0.053051647;
       for (int i = 0; i < 5; i++) {
         rho3 = rho2 * X[i];
         rho3Sq = rho3 * rho3;
         rho1 = Math.sqrt(1 - rho3Sq);
         if (eab == 0) {
           e = 0;
         } else {
           e = Math.exp(-ab / (1 + rho1)) / rho1 / eab;
         }
         mult = mult - Y[i] * Math.exp(-h5 / rho3Sq) * (e - 1 - c * rho3Sq);
       }
     }
     final double corr = Double.isNaN(mult) ? 0. : mult * rho2 * eab;
     result = corr + NORMAL.getCDF(Math.min(a, b));
     if (rho < 0) {
       result = NORMAL.getCDF(a) - result;
     }
     return result;
   }
   ab = a * b;
   if (rho != 0) {
     for (int i = 0; i < 5; i++) {
       rho3 = rho * X[i];
       rho1 = 1 - rho3 * rho3;
       mult = mult + Y[i] * Math.exp((rho3 * ab - sumSq) / rho1) / Math.sqrt(rho1);
     }
   }
   final double corr = Double.isNaN(mult) ? 0. : rho * mult;
   return NORMAL.getCDF(a) * NORMAL.getCDF(b) + corr;
 }
コード例 #15
0
 @Override
 public long nextID(Random rng, long previousId) {
   return dist.choose(rng);
 }