/** * Get a probability estimator for a value * * @param given the new value that data is conditional upon * @return the estimator for the supplied value given the condition */ @Override public Estimator getEstimator(double given) { if (m_Covariance == null) { calculateCovariance(); } Estimator result = new MahalanobisEstimator(m_Covariance, given - m_CondMean, m_ValueMean); return result; }
/** * Get a probability estimate for a value * * @param data the value to estimate the probability of * @param given the new value that data is conditional upon * @return the estimated probability of the supplied value */ @Override public double getProbability(double data, double given) { return getEstimator(given).getProbability(data); }
seed = Integer.parseInt(argv[0]); NNConditionalEstimator newEst = new NNConditionalEstimator(); int y = Math.abs(r.nextInt() % 100); System.out.println("# " + x + " " + y); newEst.addValue(x, y, 1); Estimator result = newEst.getEstimator(cond); for (int i = 0; i <= 100; i += 5) { System.out.println(" " + i + " " + result.getProbability(i));
/** * Add a new data value to the current estimator. * * @param data the new data value * @param given the new value that data is conditional upon * @param weight the weight assigned to the data value */ @Override public void addValue(double data, double given, double weight) { int insertIndex = findNearestPair(given, data); if ((m_Values.size() <= insertIndex) || (m_CondValues.elementAt(insertIndex).doubleValue() != given) || (m_Values.elementAt(insertIndex).doubleValue() != data)) { m_CondValues.insertElementAt(new Double(given), insertIndex); m_Values.insertElementAt(new Double(data), insertIndex); m_Weights.insertElementAt(new Double(weight), insertIndex); if (weight != 1) { } } else { double newWeight = m_Weights.elementAt(insertIndex).doubleValue(); newWeight += weight; m_Weights.setElementAt(new Double(newWeight), insertIndex); } m_SumOfWeights += weight; // Invalidate any previously calculated covariance matrix m_Covariance = null; }
seed = Integer.parseInt(argv[0]); NNConditionalEstimator newEst = new NNConditionalEstimator(); int y = Math.abs(r.nextInt() % 100); System.out.println("# " + x + " " + y); newEst.addValue(x, y, 1); Estimator result = newEst.getEstimator(cond); for (int i = 0; i <= 100; i += 5) { System.out.println(" " + i + " " + result.getProbability(i));
/** * Add a new data value to the current estimator. * * @param data the new data value * @param given the new value that data is conditional upon * @param weight the weight assigned to the data value */ @Override public void addValue(double data, double given, double weight) { int insertIndex = findNearestPair(given, data); if ((m_Values.size() <= insertIndex) || (m_CondValues.elementAt(insertIndex).doubleValue() != given) || (m_Values.elementAt(insertIndex).doubleValue() != data)) { m_CondValues.insertElementAt(new Double(given), insertIndex); m_Values.insertElementAt(new Double(data), insertIndex); m_Weights.insertElementAt(new Double(weight), insertIndex); if (weight != 1) { } } else { double newWeight = m_Weights.elementAt(insertIndex).doubleValue(); newWeight += weight; m_Weights.setElementAt(new Double(newWeight), insertIndex); } m_SumOfWeights += weight; // Invalidate any previously calculated covariance matrix m_Covariance = null; }
/** * Get a probability estimator for a value * * @param given the new value that data is conditional upon * @return the estimator for the supplied value given the condition */ @Override public Estimator getEstimator(double given) { if (m_Covariance == null) { calculateCovariance(); } Estimator result = new MahalanobisEstimator(m_Covariance, given - m_CondMean, m_ValueMean); return result; }
/** * Get a probability estimate for a value * * @param data the value to estimate the probability of * @param given the new value that data is conditional upon * @return the estimated probability of the supplied value */ @Override public double getProbability(double data, double given) { return getEstimator(given).getProbability(data); }
/** Display a representation of this estimator */ @Override public String toString() { if (m_Covariance == null) { calculateCovariance(); } String result = "NN Conditional Estimator. " + m_CondValues.size() + " data points. Mean = " + Utils.doubleToString(m_ValueMean, 4, 2) + " Conditional mean = " + Utils.doubleToString(m_CondMean, 4, 2); result += " Covariance Matrix: \n" + m_Covariance; return result; }
/** Display a representation of this estimator */ @Override public String toString() { if (m_Covariance == null) { calculateCovariance(); } String result = "NN Conditional Estimator. " + m_CondValues.size() + " data points. Mean = " + Utils.doubleToString(m_ValueMean, 4, 2) + " Conditional mean = " + Utils.doubleToString(m_CondMean, 4, 2); result += " Covariance Matrix: \n" + m_Covariance; return result; }