ConditionalEstimator.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 3k
Category:

Windows Develop

Development Platform:

Java

  1. /*
  2.  *    This program is free software; you can redistribute it and/or modify
  3.  *    it under the terms of the GNU General Public License as published by
  4.  *    the Free Software Foundation; either version 2 of the License, or
  5.  *    (at your option) any later version.
  6.  *
  7.  *    This program is distributed in the hope that it will be useful,
  8.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  *    GNU General Public License for more details.
  11.  *
  12.  *    You should have received a copy of the GNU General Public License
  13.  *    along with this program; if not, write to the Free Software
  14.  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.  */
  16. /*
  17.  *    ConditionalEstimator.java
  18.  *    Copyright (C) 1999 Len Trigg
  19.  *
  20.  */
  21. package weka.estimators;
  22. import java.util.*;
  23. /** 
  24.  * Interface for conditional probability estimators. Example code: <p>
  25.  *
  26.  * <code> <pre>
  27.  *   NNConditionalEstimator newEst = new NNConditionalEstimator();
  28.  *
  29.  *   // Create 50 random points and add them
  30.  *   Random r = new Random(seed);
  31.  *   for(int i = 0; i < 50; i++) {
  32.  *     int x = Math.abs(r.nextInt() % 100);
  33.  *     int y = Math.abs(r.nextInt() % 100);
  34.  *     System.out.println("# " + x + "  " + y);
  35.  *     newEst.addValue(x, y, 1);
  36.  *   }
  37.  *
  38.  *   // Pick a random conditional value
  39.  *   int cond = Math.abs(r.nextInt() % 100);
  40.  *   System.out.println("## Conditional = " + cond);
  41.  *
  42.  *   // Print the probabilities conditional on that value
  43.  *   Estimator result = newEst.getEstimator(cond);
  44.  *   for(int i = 0; i <= 100; i+= 5) {
  45.  *     System.out.println(" " + i + "  " + result.getProbability(i));
  46.  *   }
  47.  * </pre> </code>
  48.  *
  49.  * @author Len Trigg (trigg@cs.waikato.ac.nz)
  50.  * @version $Revision: 1.4 $
  51.  */
  52. public interface ConditionalEstimator {
  53.   /**
  54.    * Add a new data value to the current estimator.
  55.    *
  56.    * @param data the new data value 
  57.    * @param given the new value that data is conditional upon 
  58.    * @param weight the weight assigned to the data value 
  59.    */
  60.   void addValue(double data, double given, double weight);
  61.   /**
  62.    * Get a probability estimator for a value
  63.    *
  64.    * @param given the new value that data is conditional upon 
  65.    * @return the estimator for the supplied value given the condition
  66.    */
  67.   Estimator getEstimator(double given);
  68.   /**
  69.    * Get a probability for a value conditional on another value
  70.    *
  71.    * @param data the value to estimate the probability of
  72.    * @param given the new value that data is conditional upon 
  73.    * @return the estimator for the supplied value given the condition
  74.    */
  75.   double getProbability(double data, double given);
  76. }