Go to the documentation of this file.00001 #include "MultipleModels.hh"
00002 #include "NeuralNetwork.hh"
00003 #include "DecisionTree.hh"
00004 #include "StochDecisionTree.hh"
00005 #include "KNN.hh"
00006
00007
00008 const bool MM_DEBUG = false;
00009
00010
00011 MultipleModels::MultipleModels(int id, int nIn, int nOut, int modeltype, Random rng):
00012 id(id), nInput(nIn), nOutput(nOut), type(modeltype), rng(rng)
00013 {
00014
00015
00016 if (MM_DEBUG)
00017 cout << "nIn: " << nInput << " nOut: " << nOutput << endl;
00018
00019
00020 createModels();
00021
00022 if (MM_DEBUG)
00023 cout << "multiple models created." << endl;
00024
00025 }
00026
00027 MultipleModels::~MultipleModels() {}
00028
00029
00030
00031 bool MultipleModels::trainInstance(std::vector<float> input,
00032 std::vector<float> targetOutput){
00033 if (MM_DEBUG) cout << "Multimodel trainInstance()" << endl;
00034 bool modelChanged = false;
00035
00036
00037 for (int i = 0; i < nOutput; i++){
00038
00039 std::vector<float> output;
00040 output.push_back(targetOutput[i]);
00041
00042
00043 bool singleChange = models[i]->trainInstance(input, output);
00044 if (singleChange)
00045 modelChanged = true;
00046 }
00047
00048 return modelChanged;
00049
00050 }
00051
00052
00053
00054
00055
00056 std::vector<float> MultipleModels::testInstance(std::vector<float> input){
00057 if (MM_DEBUG) cout << "Multimodel testInstance()" << endl;
00058
00059 std::vector<float> outputs;
00060 outputs.resize(nOutput);
00061
00062
00063 for (int i = 0; i < nOutput; i++){
00064
00065
00066 outputs[i] = models[i]->testInstance(input)[0];
00067
00068 }
00069
00070 return outputs;
00071
00072 }
00073
00074 void MultipleModels::createModels(){
00075 if (MM_DEBUG) cout << "createModels" << endl;
00076
00077
00078 models.resize(nOutput);
00079
00080 for (int i = 0; i < nOutput; i++){
00081
00082
00083 if (type == 0){
00084
00085
00086 }
00087
00088
00089 else if (type == 1){
00090 if (MM_DEBUG) cout << "Creating DT for output " << i << endl;
00091 models[i] = new DecisionTree(id*nOutput + i, 1, 1000, rng);
00092
00093 }
00094
00095
00096 else {
00097 if (MM_DEBUG) cout << "Creating KNN for output " << i
00098 << " with k " << id+1 << endl;
00099 models[i] = new KNN(id*nOutput + i, id+2, rng);
00100
00101 }
00102
00103
00104 }
00105 }
00106
00107
00108