Source Code Cross Referenced for FromFile.java in  » Science » weka » weka » classifiers » bayes » net » search » fixed » 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.classifiers.bayes.net.search.fixed 
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:         * FromFile.java
019:         * Copyright (C) 2004 University of Waikato, Hamilton, New Zealand
020:         * 
021:         */
022:        package weka.classifiers.bayes.net.search.fixed;
023:
024:        import weka.classifiers.bayes.BayesNet;
025:        import weka.classifiers.bayes.net.BIFReader;
026:        import weka.classifiers.bayes.net.ParentSet;
027:        import weka.classifiers.bayes.net.search.SearchAlgorithm;
028:        import weka.core.Instances;
029:        import weka.core.Option;
030:        import weka.core.Utils;
031:
032:        import java.util.Enumeration;
033:        import java.util.Vector;
034:
035:        /** 
036:         <!-- globalinfo-start -->
037:         * The FromFile reads the structure of a Bayes net from a file in BIFF format.
038:         * <p/>
039:         <!-- globalinfo-end -->
040:         *
041:         <!-- options-start -->
042:         * Valid options are: <p/>
043:         * 
044:         * <pre> -B &lt;BIF File&gt;
045:         *  Name of file containing network structure in BIF format
046:         * </pre>
047:         * 
048:         <!-- options-end -->
049:         * 
050:         * @author Remco Bouckaert
051:         * @version $Revision: 1.7 $
052:         */
053:        public class FromFile extends SearchAlgorithm {
054:
055:            /** for serialization */
056:            static final long serialVersionUID = 7334358169507619525L;
057:
058:            /** name of file to read structure from **/
059:            String m_sBIFFile = "";
060:
061:            /**
062:             * Returns a string describing this object
063:             * @return a description of the classifier suitable for
064:             * displaying in the explorer/experimenter gui
065:             */
066:            public String globalInfo() {
067:                return "The FromFile reads the structure of a Bayes net from a file "
068:                        + "in BIFF format.";
069:            }
070:
071:            /**
072:             * 
073:             * @param bayesNet
074:             * @param instances the instances to work with
075:             * @throws Exception if attribute from BIF file could not be found
076:             */
077:            public void buildStructure(BayesNet bayesNet, Instances instances)
078:                    throws Exception {
079:                // read network structure in BIF format
080:                BIFReader bifReader = new BIFReader();
081:                bifReader.processFile(m_sBIFFile);
082:                // copy parent sets
083:                for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
084:                    int iBIFAttribute = bifReader.getNode(bayesNet
085:                            .getNodeName(iAttribute));
086:                    ParentSet bifParentSet = bifReader
087:                            .getParentSet(iBIFAttribute);
088:                    for (int iBIFParent = 0; iBIFParent < bifParentSet
089:                            .getNrOfParents(); iBIFParent++) {
090:                        String sParent = bifReader.getNodeName(bifParentSet
091:                                .getParent(iBIFParent));
092:                        int iParent = 0;
093:                        while (iParent < instances.numAttributes()
094:                                && !bayesNet.getNodeName(iParent).equals(
095:                                        sParent)) {
096:                            iParent++;
097:                        }
098:                        if (iParent >= instances.numAttributes()) {
099:                            throw new Exception("Could not find attribute "
100:                                    + sParent + " from BIF file in data");
101:                        }
102:                        bayesNet.getParentSet(iAttribute).addParent(iParent,
103:                                instances);
104:                    }
105:                }
106:            } // buildStructure
107:
108:            /**
109:             * Set name of network in BIF file to read structure from
110:             * 
111:             * @param sBIFFile the name of the BIF file
112:             */
113:            public void setBIFFile(String sBIFFile) {
114:                m_sBIFFile = sBIFFile;
115:            }
116:
117:            /**
118:             * Get name of network in BIF file to read structure from
119:             * @return BIF file name
120:             */
121:            public String getBIFFile() {
122:                return m_sBIFFile;
123:            }
124:
125:            /**
126:             * Returns an enumeration describing the available options.
127:             *
128:             * @return an enumeration of all the available options.
129:             */
130:            public Enumeration listOptions() {
131:                Vector newVector = new Vector();
132:
133:                newVector
134:                        .addElement(new Option(
135:                                "\tName of file containing network structure in BIF format\n",
136:                                "B", 1, "-B <BIF File>"));
137:
138:                Enumeration en = super .listOptions();
139:                while (en.hasMoreElements())
140:                    newVector.addElement(en.nextElement());
141:
142:                return newVector.elements();
143:            }
144:
145:            /**
146:             * Parses a given list of options. <p/>
147:             *
148:             <!-- options-start -->
149:             * Valid options are: <p/>
150:             * 
151:             * <pre> -B &lt;BIF File&gt;
152:             *  Name of file containing network structure in BIF format
153:             * </pre>
154:             * 
155:             <!-- options-end -->
156:             *
157:             * @param options the list of options as an array of strings
158:             * @throws Exception if an option is not supported
159:             */
160:            public void setOptions(String[] options) throws Exception {
161:                setBIFFile(Utils.getOption('B', options));
162:
163:                super .setOptions(options);
164:            }
165:
166:            /**
167:             * Gets the current settings of the search algorithm.
168:             *
169:             * @return an array of strings suitable for passing to setOptions
170:             */
171:            public String[] getOptions() {
172:                String[] super Options = super .getOptions();
173:                String[] options = new String[2 + super Options.length];
174:                int current = 0;
175:
176:                options[current++] = "-B";
177:                options[current++] = "" + getBIFFile();
178:
179:                // insert options from parent class
180:                for (int iOption = 0; iOption < super Options.length; iOption++) {
181:                    options[current++] = super Options[iOption];
182:                }
183:
184:                // Fill up rest with empty strings, not nulls!
185:                while (current < options.length) {
186:                    options[current++] = "";
187:                }
188:                return options;
189:            }
190:
191:        } // class FromFile
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.