Package weka.estimators

Examples of weka.estimators.UnivariateDensityEstimator


   * @exception Exception if the estimator can't be computed
   */
  protected UnivariateDensityEstimator getDensityEstimator(Instance instance, boolean print) throws Exception {

    // Initialize estimator
    UnivariateDensityEstimator e;
   
    if (m_estimatorType == ESTIMATOR_KERNEL) {
      e = new UnivariateKernelEstimator();
    } else if (m_estimatorType == ESTIMATOR_NORMAL) {
      e = new UnivariateNormalEstimator();
    } else {
      e = new UnivariateEqualFrequencyHistogramEstimator();

      // Set the number of bins appropriately
      ((UnivariateEqualFrequencyHistogramEstimator)e).setNumBins(getNumBins());

      // Initialize boundaries of equal frequency estimator
      for (int i = 0; i < m_OriginalTargetValues.length; i++) {
        e.addValue(m_OriginalTargetValues[i], 1.0);
      }
     
      // Construct estimator, then initialize statistics, so that only boundaries will be kept
      ((UnivariateEqualFrequencyHistogramEstimator)e).initializeStatistics();

      // Now that boundaries have been determined, we only need to update the bin weights
      ((UnivariateEqualFrequencyHistogramEstimator)e).setUpdateWeightsOnly(true);     
    }

    // Make sure structure of class attribute correct
    Instance newInstance = (Instance)instance.copy();
    newInstance.setDataset(m_DiscretizedHeader);
    double [] probs = m_Classifier.distributionForInstance(newInstance);

    // Add values to estimator
    for (int i = 0; i < m_OriginalTargetValues.length; i++) {
      e.addValue(m_OriginalTargetValues[i], probs[m_NewTargetValues[i]] *
                 m_OriginalTargetValues.length / m_ClassCounts[m_NewTargetValues[i]]);
    }

    // Return estimator
    return e;
View Full Code Here


   * @exception Exception if the intervals can't be computed
   */
  public double logDensity(Instance instance, double value) throws Exception {
   
    // Get density estimator
    UnivariateDensityEstimator e = getDensityEstimator(instance, true);

    // Return estimate
    return e.logDensity(value);
  }
View Full Code Here

TOP

Related Classes of weka.estimators.UnivariateDensityEstimator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.