All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.classifiers.bayes.net.search.fixed.FromFile Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This version represents the developer version, the "bleeding edge" of development, you could say. New functionality gets added to this version.

There is a newer version: 3.9.6
Show newest version
/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 * FromFile.java
 * Copyright (C) 2004-2012 University of Waikato, Hamilton, New Zealand
 * 
 */
package weka.classifiers.bayes.net.search.fixed;

import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;

import weka.classifiers.bayes.BayesNet;
import weka.classifiers.bayes.net.BIFReader;
import weka.classifiers.bayes.net.ParentSet;
import weka.classifiers.bayes.net.search.SearchAlgorithm;
import weka.core.Instances;
import weka.core.Option;
import weka.core.RevisionUtils;
import weka.core.Utils;

/**
 *  The FromFile reads the structure of a Bayes net
 * from a file in BIFF format.
 * 

* * * Valid options are: *

* *

 * -B <BIF File>
 *  Name of file containing network structure in BIF format
 * 
* * * * @author Remco Bouckaert * @version $Revision: 10154 $ */ public class FromFile extends SearchAlgorithm { /** for serialization */ static final long serialVersionUID = 7334358169507619525L; /** name of file to read structure from **/ String m_sBIFFile = ""; /** * Returns a string describing this object * * @return a description of the classifier suitable for displaying in the * explorer/experimenter gui */ public String globalInfo() { return "The FromFile reads the structure of a Bayes net from a file " + "in BIFF format."; } /** * * @param bayesNet * @param instances the instances to work with * @throws Exception if attribute from BIF file could not be found */ @Override public void buildStructure(BayesNet bayesNet, Instances instances) throws Exception { // read network structure in BIF format BIFReader bifReader = new BIFReader(); bifReader.processFile(m_sBIFFile); // copy parent sets for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) { int iBIFAttribute = bifReader.getNode(bayesNet.getNodeName(iAttribute)); ParentSet bifParentSet = bifReader.getParentSet(iBIFAttribute); for (int iBIFParent = 0; iBIFParent < bifParentSet.getNrOfParents(); iBIFParent++) { String sParent = bifReader.getNodeName(bifParentSet .getParent(iBIFParent)); int iParent = 0; while (iParent < instances.numAttributes() && !bayesNet.getNodeName(iParent).equals(sParent)) { iParent++; } if (iParent >= instances.numAttributes()) { throw new Exception("Could not find attribute " + sParent + " from BIF file in data"); } bayesNet.getParentSet(iAttribute).addParent(iParent, instances); } } } // buildStructure /** * Set name of network in BIF file to read structure from * * @param sBIFFile the name of the BIF file */ public void setBIFFile(String sBIFFile) { m_sBIFFile = sBIFFile; } /** * Get name of network in BIF file to read structure from * * @return BIF file name */ public String getBIFFile() { return m_sBIFFile; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration




© 2015 - 2024 Weber Informatics LLC | Privacy Policy