Java Code Examples for weka.core.Utils#smOrEq()
The following examples show how to use
weka.core.Utils#smOrEq() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PruneableClassifierTree.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * Prunes a tree. * * @throws Exception if tree can't be pruned successfully */ public void prune() throws Exception { if (!m_isLeaf) { // Prune all subtrees. for (int i = 0; i < m_sons.length; i++) son(i).prune(); // Decide if leaf is best choice. if (Utils.smOrEq(errorsForLeaf(),errorsForTree())) { // Free son Trees m_sons = null; m_isLeaf = true; // Get NoSplit Model for node. m_localModel = new NoSplit(localModel().distribution()); } } }
Example 2
Source File: BinC45Split.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * Returns index of subset instance is assigned to. * Returns -1 if instance is assigned to more than one subset. * * @exception Exception if something goes wrong */ public final int whichSubset(Instance instance) throws Exception { if (instance.isMissing(m_attIndex)) return -1; else{ if (instance.attribute(m_attIndex).isNominal()){ if ((int)m_splitPoint == (int)instance.value(m_attIndex)) return 0; else return 1; }else if (Utils.smOrEq(instance.value(m_attIndex),m_splitPoint)) return 0; else return 1; } }
Example 3
Source File: C45Split.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * Returns index of subset instance is assigned to. * Returns -1 if instance is assigned to more than one subset. * * @exception Exception if something goes wrong */ public final int whichSubset(Instance instance) throws Exception { if (instance.isMissing(m_attIndex)) return -1; else{ if (instance.attribute(m_attIndex).isNominal()) return (int)instance.value(m_attIndex); else if (Utils.smOrEq(instance.value(m_attIndex),m_splitPoint)) return 0; else return 1; } }
Example 4
Source File: ResidualSplit.java From tsml with GNU General Public License v3.0 | 5 votes |
public final int whichSubset(Instance instance) throws Exception { if (instance.isMissing(m_attIndex)) return -1; else{ if (instance.attribute(m_attIndex).isNominal()) return (int)instance.value(m_attIndex); else if (Utils.smOrEq(instance.value(m_attIndex),m_splitPoint)) return 0; else return 1; } }
Example 5
Source File: PruneableDecList.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * Prunes the end of the rule. */ protected void pruneEnd() throws Exception { double errorsLeaf, errorsTree; errorsTree = errorsForTree(); errorsLeaf = errorsForLeaf(); if (Utils.smOrEq(errorsLeaf,errorsTree)){ m_isLeaf = true; m_sons = null; m_localModel = new NoSplit(localModel().distribution()); } }
Example 6
Source File: C45PruneableDecList.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * Prunes the end of the rule. */ protected void pruneEnd() { double errorsLeaf, errorsTree; errorsTree = getEstimatedErrorsForTree(); errorsLeaf = getEstimatedErrorsForLeaf(); if (Utils.smOrEq(errorsLeaf,errorsTree+0.1)) { // +0.1 as in C4.5 m_isLeaf = true; m_sons = null; m_localModel = new NoSplit(localModel().distribution()); } }
Example 7
Source File: ClassifierDecList.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * Method for choosing a subset to expand. */ public final int chooseIndex() { int minIndex = -1; double estimated, min = Double.MAX_VALUE; int i, j; for (i = 0; i < m_sons.length; i++) if (son(i) == null) { if (Utils.sm(localModel().distribution().perBag(i), (double)m_minNumObj)) estimated = Double.MAX_VALUE; else{ estimated = 0; for (j = 0; j < localModel().distribution().numClasses(); j++) estimated -= m_splitCrit.logFunc(localModel().distribution(). perClassPerBag(i,j)); estimated += m_splitCrit.logFunc(localModel().distribution(). perBag(i)); estimated /= localModel().distribution().perBag(i); } if (Utils.smOrEq(estimated,0)) return i; if (Utils.sm(estimated,min)) { min = estimated; minIndex = i; } } return minIndex; }
Example 8
Source File: C45PruneableClassifierTreeG.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Prunes a tree using C4.5's pruning procedure. * * @throws Exception if something goes wrong */ public void prune() throws Exception { double errorsLargestBranch; double errorsLeaf; double errorsTree; int indexOfLargestBranch; C45PruneableClassifierTreeG largestBranch; int i; if (!m_isLeaf){ // Prune all subtrees. for (i=0;i<m_sons.length;i++) son(i).prune(); // Compute error for largest branch indexOfLargestBranch = localModel().distribution().maxBag(); if (m_subtreeRaising) { errorsLargestBranch = son(indexOfLargestBranch). getEstimatedErrorsForBranch((Instances)m_train); } else { errorsLargestBranch = Double.MAX_VALUE; } // Compute error if this Tree would be leaf errorsLeaf = getEstimatedErrorsForDistribution(localModel().distribution()); // Compute error for the whole subtree errorsTree = getEstimatedErrors(); // Decide if leaf is best choice. if (Utils.smOrEq(errorsLeaf,errorsTree+0.1) && Utils.smOrEq(errorsLeaf,errorsLargestBranch+0.1)){ // Free son Trees m_sons = null; m_isLeaf = true; // Get NoSplit Model for node. m_localModel = new NoSplit(localModel().distribution()); return; } // Decide if largest branch is better choice // than whole subtree. if (Utils.smOrEq(errorsLargestBranch,errorsTree+0.1)){ largestBranch = son(indexOfLargestBranch); m_sons = largestBranch.m_sons; m_localModel = largestBranch.localModel(); m_isLeaf = largestBranch.m_isLeaf; newDistribution(m_train); prune(); } } }
Example 9
Source File: C45PruneableClassifierTree.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Prunes a tree using C4.5's pruning procedure. * * @throws Exception if something goes wrong */ public void prune() throws Exception { double errorsLargestBranch; double errorsLeaf; double errorsTree; int indexOfLargestBranch; C45PruneableClassifierTree largestBranch; int i; if (!m_isLeaf){ // Prune all subtrees. for (i=0;i<m_sons.length;i++) son(i).prune(); // Compute error for largest branch indexOfLargestBranch = localModel().distribution().maxBag(); if (m_subtreeRaising) { errorsLargestBranch = son(indexOfLargestBranch). getEstimatedErrorsForBranch((Instances)m_train); } else { errorsLargestBranch = Double.MAX_VALUE; } // Compute error if this Tree would be leaf errorsLeaf = getEstimatedErrorsForDistribution(localModel().distribution()); // Compute error for the whole subtree errorsTree = getEstimatedErrors(); // Decide if leaf is best choice. if (Utils.smOrEq(errorsLeaf,errorsTree+0.1) && Utils.smOrEq(errorsLeaf,errorsLargestBranch+0.1)){ // Free son Trees m_sons = null; m_isLeaf = true; // Get NoSplit Model for node. m_localModel = new NoSplit(localModel().distribution()); return; } // Decide if largest branch is better choice // than whole subtree. if (Utils.smOrEq(errorsLargestBranch,errorsTree+0.1)){ largestBranch = son(indexOfLargestBranch); m_sons = largestBranch.m_sons; m_localModel = largestBranch.localModel(); m_isLeaf = largestBranch.m_isLeaf; newDistribution(m_train); prune(); } } }
Example 10
Source File: FTNode.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Method for prunning a tree using C4.5 pruning procedure. * * @exception Exception if something goes wrong */ public double prune() throws Exception { double errorsLeaf; double errorsTree; double errorsConstModel; double treeError=0; int i; double probBranch; // Compute error if this Tree would be leaf without contructor errorsLeaf = getEstimatedErrorsForDistribution(m_localModel.distribution()); if (m_isLeaf ) { return errorsLeaf; } else { //Computes da error of the constructor model errorsConstModel = getEtimateConstModel(m_localModel.distribution()); errorsTree=0; for (i = 0; i < m_sons.length; i++) { probBranch = m_localModel.distribution().perBag(i) / m_localModel.distribution().total(); errorsTree += probBranch* m_sons[i].prune(); } // Decide if leaf is best choice. if (Utils.smOrEq(errorsLeaf, errorsTree) && Utils.smOrEq(errorsLeaf, errorsConstModel)) { // Free son Trees m_sons = null; m_isLeaf = true; m_hasConstr=false; m_leafclass=m_localModel.distribution().maxClass(); // Get NoSplit Model for node. m_localModel = new NoSplit(m_localModel.distribution()); treeError=errorsLeaf; }else{ // Decide if Constructor is best choice. if (Utils.smOrEq(errorsConstModel, errorsTree)) { // Free son Trees m_sons = null; m_isLeaf = true; m_hasConstr =true; // Get NoSplit Model for node. m_localModel = new NoSplit(m_localModel.distribution()); treeError=errorsConstModel; } else treeError=errorsTree; } } return treeError; }
Example 11
Source File: FTLeavesNode.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Prunes a tree using C4.5 pruning procedure. * * @exception Exception if something goes wrong */ public double prune() throws Exception { double errorsLeaf; double errorsTree; double errorsConstModel; double treeError=0; int i; double probBranch; // Compute error if this Tree would be leaf without contructor errorsLeaf = getEstimatedErrorsForDistribution(m_localModel.distribution()); if (m_isLeaf ) { return errorsLeaf; } else { //Computes da error of the constructor model errorsConstModel = getEtimateConstModel(m_localModel.distribution()); errorsTree=0; for (i = 0; i < m_sons.length; i++) { probBranch = m_localModel.distribution().perBag(i) / m_localModel.distribution().total(); errorsTree += probBranch* m_sons[i].prune(); } // Decide if leaf is best choice. if (Utils.smOrEq(errorsLeaf, errorsTree) && Utils.smOrEq(errorsLeaf, errorsConstModel)) { // Free son Trees m_sons = null; m_isLeaf = true; m_hasConstr=false; m_leafclass=m_localModel.distribution().maxClass(); // Get NoSplit Model for node. m_localModel = new NoSplit(m_localModel.distribution()); treeError=errorsLeaf; }else{ // Decide if Constructor is best choice. if (Utils.smOrEq(errorsConstModel, errorsTree)) { // Free son Trees m_sons = null; m_isLeaf = true; m_hasConstr =true; // Get NoSplit Model for node. m_localModel = new NoSplit(m_localModel.distribution()); treeError=errorsConstModel; } else treeError=errorsTree; } } return treeError; }
Example 12
Source File: FTInnerNode.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Prunes a tree using C4.5 pruning procedure. * * @exception Exception if something goes wrong */ public double prune() throws Exception { double errorsLeaf; double errorsTree; double errorsConstModel; double treeError=0; int i; double probBranch; // Compute error if this Tree would be leaf without contructor errorsLeaf = getEstimatedErrorsForDistribution(m_localModel.distribution()); if (m_isLeaf ) { return errorsLeaf; } else { //Computes da error of the constructor model errorsConstModel = getEtimateConstModel(m_localModel.distribution()); errorsTree=0; for (i = 0; i < m_sons.length; i++) { probBranch = m_localModel.distribution().perBag(i) / m_localModel.distribution().total(); errorsTree += probBranch* m_sons[i].prune(); } // Decide if leaf is best choice. if (Utils.smOrEq(errorsLeaf, errorsTree)) { // Free son Trees m_sons = null; m_isLeaf = true; m_hasConstr=false; m_leafclass=m_localModel.distribution().maxClass(); // Get NoSplit Model for node. m_localModel = new NoSplit(m_localModel.distribution()); treeError=errorsLeaf; } else{ treeError=errorsTree; } } return treeError; }
Example 13
Source File: ConjunctiveRule.java From tsml with GNU General Public License v3.0 | 2 votes |
/** * Function used to calculate the weighted mean squared error, * i.e., sum[x-avg(x)]^2 based on the given elements of the formula: * meanSquaredError = sum(Wi*Xi^2) - (sum(WiXi))^2/sum(Wi) * * @param weightedSq sum(Wi*Xi^2) * @param weightedValue sum(WiXi) * @param sum sum of weights * @return the weighted mean-squared error */ protected double wtMeanSqErr(double weightedSq, double weightedValue, double sum){ if(Utils.smOrEq(sum, 1.0E-6)) return 0; return (weightedSq - (weightedValue * weightedValue) / sum); }