X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=abstractrandomforest.cpp;fp=abstractrandomforest.cpp;h=ae60b773742c25e0af85f811167003641e4646a4;hb=035f86272c776e1cccaa47021e26782e49cd41e7;hp=0000000000000000000000000000000000000000;hpb=96dbe925073caefaed6e6db85659c144a806aeb1;p=mothur.git diff --git a/abstractrandomforest.cpp b/abstractrandomforest.cpp new file mode 100644 index 0000000..ae60b77 --- /dev/null +++ b/abstractrandomforest.cpp @@ -0,0 +1,58 @@ +// +// abstractrandomforest.cpp +// Mothur +// +// Created by Sarah Westcott on 10/1/12. +// Copyright (c) 2012 Schloss Lab. All rights reserved. +// + +#include "abstractrandomforest.hpp" + +/***********************************************************************/ +AbstractRandomForest::AbstractRandomForest(const std::vector < std::vector > dataSet, + const int numDecisionTrees, + const string treeSplitCriterion = "informationGain") +: dataSet(dataSet), +numDecisionTrees(numDecisionTrees), +numSamples((int)dataSet.size()), +numFeatures((int)(dataSet[0].size() - 1)), +globalDiscardedFeatureIndices(getGlobalDiscardedFeatureIndices()), +globalVariableImportanceList(numFeatures, 0), +treeSplitCriterion(treeSplitCriterion) { + m = MothurOut::getInstance(); + // TODO: double check if the implemenatation of 'globalOutOfBagEstimates' is correct +} + +/***********************************************************************/ + +vector AbstractRandomForest::getGlobalDiscardedFeatureIndices() { + try { + vector globalDiscardedFeatureIndices; + + // calculate feature vectors + vector< vector > featureVectors(numFeatures, vector(numSamples, 0)); + for (int i = 0; i < numSamples; i++) { + if (m->control_pressed) { return globalDiscardedFeatureIndices; } + for (int j = 0; j < numFeatures; j++) { featureVectors[j][i] = dataSet[i][j]; } + } + + for (int i = 0; i < featureVectors.size(); i++) { + if (m->control_pressed) { return globalDiscardedFeatureIndices; } + double standardDeviation = m->getStandardDeviation(featureVectors[i]); + if (standardDeviation <= 0){ globalDiscardedFeatureIndices.push_back(i); } + } + + if (m->debug) { + m->mothurOut("number of global discarded features: " + toString(globalDiscardedFeatureIndices.size())+ "\n"); + m->mothurOut("total features: " + toString(featureVectors.size())+ "\n"); + } + + return globalDiscardedFeatureIndices; + } + catch(exception& e) { + m->errorOut(e, "AbstractRandomForest", "getGlobalDiscardedFeatureIndices"); + exit(1); + } +} + +/***********************************************************************/ \ No newline at end of file