Source Code Cross Referenced for KDConditionalEstimator.java in  » Science » weka » weka » estimators » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » weka » weka.estimators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    This program is free software; you can redistribute it and/or modify
003:         *    it under the terms of the GNU General Public License as published by
004:         *    the Free Software Foundation; either version 2 of the License, or
005:         *    (at your option) any later version.
006:         *
007:         *    This program is distributed in the hope that it will be useful,
008:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *    GNU General Public License for more details.
011:         *
012:         *    You should have received a copy of the GNU General Public License
013:         *    along with this program; if not, write to the Free Software
014:         *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015:         */
016:
017:        /*
018:         *    KDConditionalEstimator.java
019:         *    Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
020:         *
021:         */
022:
023:        package weka.estimators;
024:
025:        /** 
026:         * Conditional probability estimator for a numeric domain conditional upon
027:         * a discrete domain (utilises separate kernel estimators for each discrete
028:         * conditioning value).
029:         *
030:         * @author Len Trigg (trigg@cs.waikato.ac.nz)
031:         * @version $Revision: 1.7 $
032:         */
033:        public class KDConditionalEstimator implements  ConditionalEstimator {
034:
035:            /** Hold the sub-estimators */
036:            private KernelEstimator[] m_Estimators;
037:
038:            /**
039:             * Constructor
040:             *
041:             * @param numCondSymbols the number of conditioning symbols 
042:             * @param precision the  precision to which numeric values are given. For
043:             * example, if the precision is stated to be 0.1, the values in the
044:             * interval (0.25,0.35] are all treated as 0.3. 
045:             */
046:            public KDConditionalEstimator(int numCondSymbols, double precision) {
047:
048:                m_Estimators = new KernelEstimator[numCondSymbols];
049:                for (int i = 0; i < numCondSymbols; i++) {
050:                    m_Estimators[i] = new KernelEstimator(precision);
051:                }
052:            }
053:
054:            /**
055:             * Add a new data value to the current estimator.
056:             *
057:             * @param data the new data value 
058:             * @param given the new value that data is conditional upon 
059:             * @param weight the weight assigned to the data value 
060:             */
061:            public void addValue(double data, double given, double weight) {
062:
063:                m_Estimators[(int) given].addValue(data, weight);
064:            }
065:
066:            /**
067:             * Get a probability estimator for a value
068:             *
069:             * @param given the new value that data is conditional upon 
070:             * @return the estimator for the supplied value given the condition
071:             */
072:            public Estimator getEstimator(double given) {
073:
074:                return m_Estimators[(int) given];
075:            }
076:
077:            /**
078:             * Get a probability estimate for a value
079:             *
080:             * @param data the value to estimate the probability of
081:             * @param given the new value that data is conditional upon 
082:             * @return the estimated probability of the supplied value
083:             */
084:            public double getProbability(double data, double given) {
085:
086:                return getEstimator(given).getProbability(data);
087:            }
088:
089:            /** Display a representation of this estimator */
090:            public String toString() {
091:
092:                String result = "KD Conditional Estimator. "
093:                        + m_Estimators.length + " sub-estimators:\n";
094:                for (int i = 0; i < m_Estimators.length; i++) {
095:                    result += "Sub-estimator " + i + ": " + m_Estimators[i];
096:                }
097:                return result;
098:            }
099:
100:            /**
101:             * Main method for testing this class.
102:             *
103:             * @param argv should contain a sequence of pairs of integers which
104:             * will be treated as numeric, symbolic.
105:             */
106:            public static void main(String[] argv) {
107:
108:                try {
109:                    if (argv.length == 0) {
110:                        System.out
111:                                .println("Please specify a set of instances.");
112:                        return;
113:                    }
114:                    int currentA = Integer.parseInt(argv[0]);
115:                    int maxA = currentA;
116:                    int currentB = Integer.parseInt(argv[1]);
117:                    int maxB = currentB;
118:                    for (int i = 2; i < argv.length - 1; i += 2) {
119:                        currentA = Integer.parseInt(argv[i]);
120:                        currentB = Integer.parseInt(argv[i + 1]);
121:                        if (currentA > maxA) {
122:                            maxA = currentA;
123:                        }
124:                        if (currentB > maxB) {
125:                            maxB = currentB;
126:                        }
127:                    }
128:                    KDConditionalEstimator newEst = new KDConditionalEstimator(
129:                            maxB + 1, 1);
130:                    for (int i = 0; i < argv.length - 1; i += 2) {
131:                        currentA = Integer.parseInt(argv[i]);
132:                        currentB = Integer.parseInt(argv[i + 1]);
133:                        System.out.println(newEst);
134:                        System.out.println("Prediction for " + currentA + '|'
135:                                + currentB + " = "
136:                                + newEst.getProbability(currentA, currentB));
137:                        newEst.addValue(currentA, currentB, 1);
138:                    }
139:                } catch (Exception e) {
140:                    System.out.println(e.getMessage());
141:                }
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.