01: /*
02: * This program is free software; you can redistribute it and/or modify
03: * it under the terms of the GNU General Public License as published by
04: * the Free Software Foundation; either version 2 of the License, or
05: * (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * 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: /*
18: * ConditionalEstimator.java
19: * Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
20: *
21: */
22:
23: package weka.estimators;
24:
25: /**
26: * Interface for conditional probability estimators. Example code: <p>
27: *
28: * <code> <pre>
29: * NNConditionalEstimator newEst = new NNConditionalEstimator();
30: *
31: * // Create 50 random points and add them
32: * Random r = new Random(seed);
33: * for(int i = 0; i < 50; i++) {
34: * int x = Math.abs(r.nextInt() % 100);
35: * int y = Math.abs(r.nextInt() % 100);
36: * System.out.println("# " + x + " " + y);
37: * newEst.addValue(x, y, 1);
38: * }
39: *
40: * // Pick a random conditional value
41: * int cond = Math.abs(r.nextInt() % 100);
42: * System.out.println("## Conditional = " + cond);
43: *
44: * // Print the probabilities conditional on that value
45: * Estimator result = newEst.getEstimator(cond);
46: * for(int i = 0; i <= 100; i+= 5) {
47: * System.out.println(" " + i + " " + result.getProbability(i));
48: * }
49: * </pre> </code>
50: *
51: * @author Len Trigg (trigg@cs.waikato.ac.nz)
52: * @version $Revision: 1.6 $
53: */
54: public interface ConditionalEstimator {
55:
56: /**
57: * Add a new data value to the current estimator.
58: *
59: * @param data the new data value
60: * @param given the new value that data is conditional upon
61: * @param weight the weight assigned to the data value
62: */
63: void addValue(double data, double given, double weight);
64:
65: /**
66: * Get a probability estimator for a value
67: *
68: * @param given the new value that data is conditional upon
69: * @return the estimator for the supplied value given the condition
70: */
71: Estimator getEstimator(double given);
72:
73: /**
74: * Get a probability for a value conditional on another value
75: *
76: * @param data the value to estimate the probability of
77: * @param given the new value that data is conditional upon
78: * @return the estimator for the supplied value given the condition
79: */
80: double getProbability(double data, double given);
81:
82: }
|