diff --git a/Modules/Classification/CLImportanceWeighting/include/mitkGeneralizedLinearModel.h b/Modules/Classification/CLImportanceWeighting/include/mitkGeneralizedLinearModel.h index 6adc3b2fc3..4cca9ad9c7 100644 --- a/Modules/Classification/CLImportanceWeighting/include/mitkGeneralizedLinearModel.h +++ b/Modules/Classification/CLImportanceWeighting/include/mitkGeneralizedLinearModel.h @@ -1,104 +1,107 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkGeneralizedLinearModel_h #define mitkGeneralizedLinearModel_h #include #include #include namespace mitk { /** * \brief Generalized Linear Model that allows linear models for non-gaussian data * * Generalized linear models are an extension of standard linear models that allow * a different apperance of the data. This is for example usefull to calculate * Logistic regressions. */ class MITKCLIMPORTANCEWEIGHTING_EXPORT GeneralizedLinearModel { public: /** * \brief Initialization of the GLM. The parameters needs to be passed at the beginning. * * Constructor for a GLM. During the creation process the glm model parameter * are guessed. * * @param xData The input data matrix. * @param yData The output data matrix. The values of y must meet the requirements of the link and distribution. * @param addConstantColumn Default=True. If True an constant value is added to each row allowing a constant factor in the model. */ GeneralizedLinearModel (const vnl_matrix &xData, const vnl_vector &yData, bool addConstantColumn=true); /** * \brief Predicts the value corresponding to the given vector. * * From the learned data a guess is given depending on the provided input vector. The * value depend on the b-values of the learned model as well as on the chosen link and * distribution. * * No input validation is done. The data and the learned model might not match! * * @paaram c Column for which the data is guessed. */ double Predict(const vnl_vector &c); /** * \brief Predicts the value corresponding to the given matrix. * * From the learned data a guess is given depending on the provided input matrix. The * value depend on the b-values of the learned model as well as on the chosen link and * distribution. * * No input validation is done. The data and the learned model might not match! * * @paaram x Matrix for which the data is guessed. */ vnl_vector Predict(const vnl_matrix &x); /** * \brief Estimation of the exponential factor for a given function * * Gives the exponential part of a link function. Only suitable for log-it models. This * is especially usefull for calculating the weights for transfer learning since it * is equal to the weights. * */ vnl_vector ExpMu(const vnl_matrix &x); /** * \brief Returns the b-Vector for the estimation */ vnl_vector B(); private: // Estimates the rank of the matrix and creates a permutation vector so // that the most important columns are first. Depends on a QR-algorithm. void EstimatePermutation(const vnl_matrix &xData); -#pragma warning(disable: 4251) +#ifdef _MSC_VER +# pragma warning(disable: 4251) +#endif + vnl_vector m_Permutation; // Holds a permutation matrix which is used during calculation of B vnl_vector m_B; // B-Values. Linear componentn of the model. bool m_AddConstantColumn; // If true, a constant value is added to each row // int m_Rank; // The estimated input rank of the matrix. }; } #endif //mitkGeneralizedLInearModel_h diff --git a/Modules/Classification/CLMiniApps/CLSimpleVoxelClassification.cpp b/Modules/Classification/CLMiniApps/CLSimpleVoxelClassification.cpp index 9befddf770..5754df9dd6 100644 --- a/Modules/Classification/CLMiniApps/CLSimpleVoxelClassification.cpp +++ b/Modules/Classification/CLMiniApps/CLSimpleVoxelClassification.cpp @@ -1,225 +1,223 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include // CTK #include "mitkCommandLineParser.h" int main(int argc, char* argv[]) { // Setup CLI Module parsable interface mitkCommandLineParser parser; parser.setTitle("Simple Random Forest Classifier"); parser.setCategory("Classification"); parser.setDescription("Learns and predicts classes"); parser.setContributor("MBI"); parser.setArgumentPrefix("--", "-"); // Add command line argument names parser.addArgument("help", "h", mitkCommandLineParser::Bool, "Show options"); parser.addArgument("loadFile", "l", mitkCommandLineParser::InputFile, "DataCollection File"); parser.addArgument( "colIds", "c", mitkCommandLineParser::String, "Patient Identifiers from DataCollection used for training"); parser.addArgument("testId", "t", mitkCommandLineParser::String, "Patient Identifier from DataCollection used for testing"); parser.addArgument("features", "b", mitkCommandLineParser::String, "Features"); parser.addArgument("stats", "s", mitkCommandLineParser::String, "Output file for stats"); parser.addArgument("treeDepth", "d", mitkCommandLineParser::Int, "limits tree depth"); parser.addArgument("forestSize", "f", mitkCommandLineParser::Int, "number of trees"); parser.addArgument("configName", "n", mitkCommandLineParser::String, "human readable name for configuration"); parser.addArgument("output", "o", mitkCommandLineParser::OutputDirectory, "output folder for results"); parser.addArgument("classmap", "m", mitkCommandLineParser::String, "name of class that is to be learnt"); std::map parsedArgs = parser.parseArguments(argc, argv); // Show a help message if (parsedArgs.size()==0 || parsedArgs.count("help") || parsedArgs.count("h")) { std::cout << parser.helpText(); return EXIT_SUCCESS; } // Default values - bool useStatsFile = false; unsigned int forestSize = 8; unsigned int treeDepth = 10; std::string configName = ""; std::string outputFolder = ""; std::vector features; std::vector trainingIds; std::vector testingIds; std::vector loadIds; // features + masks needed for training and evaluation std::string outputFile; std::string classMap; std::string xmlFile; std::ofstream experimentFS; // Parse input parameters { if (parsedArgs.count("colIds") || parsedArgs.count("c")) { std::istringstream ss(us::any_cast(parsedArgs["colIds"])); std::string token; while (std::getline(ss, token, ',')) trainingIds.push_back(token); } if (parsedArgs.count("output") || parsedArgs.count("o")) { outputFolder = us::any_cast(parsedArgs["output"]); } if (parsedArgs.count("classmap") || parsedArgs.count("m")) { classMap = us::any_cast(parsedArgs["classmap"]); } if (parsedArgs.count("configName") || parsedArgs.count("n")) { configName = us::any_cast(parsedArgs["configName"]); } if (parsedArgs.count("features") || parsedArgs.count("b")) { std::istringstream ss(us::any_cast(parsedArgs["features"])); std::string token; while (std::getline(ss, token, ',')) features.push_back(token); } if (parsedArgs.count("treeDepth") || parsedArgs.count("d")) { treeDepth = us::any_cast(parsedArgs["treeDepth"]); } if (parsedArgs.count("forestSize") || parsedArgs.count("f")) { forestSize = us::any_cast(parsedArgs["forestSize"]); } if (parsedArgs.count("stats") || parsedArgs.count("s")) { - useStatsFile = true; experimentFS.open(us::any_cast(parsedArgs["stats"]).c_str(), std::ios_base::app); } if (parsedArgs.count("testId") || parsedArgs.count("t")) { std::istringstream ss(us::any_cast(parsedArgs["testId"])); std::string token; while (std::getline(ss, token, ',')) testingIds.push_back(token); } for (unsigned int i = 0; i < features.size(); i++) { loadIds.push_back(features.at(i)); } loadIds.push_back(classMap); if (parsedArgs.count("stats") || parsedArgs.count("s")) { outputFile = us::any_cast(parsedArgs["stats"]); } if (parsedArgs.count("loadFile") || parsedArgs.count("l")) { xmlFile = us::any_cast(parsedArgs["loadFile"]); } else { MITK_ERROR << parser.helpText(); return EXIT_FAILURE; } } mitk::DataCollection::Pointer trainCollection; mitk::DataCollection::Pointer testCollection; { mitk::CollectionReader colReader; // Load only relevant images colReader.SetDataItemNames(loadIds); colReader.AddSubColIds(testingIds); testCollection = colReader.LoadCollection(xmlFile); colReader.ClearDataElementIds(); colReader.ClearSubColIds(); colReader.SetDataItemNames(loadIds); colReader.AddSubColIds(trainingIds); trainCollection = colReader.LoadCollection(xmlFile); } ////////////////////////////////////////////////////////////////////////////// // If required do Training.... ////////////////////////////////////////////////////////////////////////////// //mitk::DecisionForest forest; mitk::VigraRandomForestClassifier::Pointer forest = mitk::VigraRandomForestClassifier::New(); forest->SetTreeCount(forestSize); forest->SetMaximumTreeDepth(treeDepth); // create feature matrix auto trainDataX = mitk::DCUtilities::DC3dDToMatrixXd(trainCollection, features, classMap); // create label matrix auto trainDataY = mitk::DCUtilities::DC3dDToMatrixXi(trainCollection, classMap, classMap); forest->Train(trainDataX, trainDataY); // prepare feature matrix for test case auto testDataX = mitk::DCUtilities::DC3dDToMatrixXd(testCollection,features, classMap); auto testDataNewY = forest->Predict(testDataX); mitk::DCUtilities::MatrixToDC3d(testDataNewY, testCollection, "RESULT", classMap); Eigen::MatrixXd Probs = forest->GetPointWiseProbabilities(); Eigen::MatrixXd prob0 = Probs.col(0); Eigen::MatrixXd prob1 = Probs.col(1); mitk::DCUtilities::MatrixToDC3d(prob0, testCollection,"prob0", classMap); mitk::DCUtilities::MatrixToDC3d(prob1, testCollection,"prob1", classMap); std::vector outputFilter; mitk::CollectionWriter::ExportCollectionToFolder(testCollection, outputFolder + "/result_collection.xml", outputFilter); return EXIT_SUCCESS; } diff --git a/Modules/Classification/CLMiniApps/CLSurWeighting.cpp b/Modules/Classification/CLMiniApps/CLSurWeighting.cpp index 4b1e6b872f..881a35707f 100644 --- a/Modules/Classification/CLMiniApps/CLSurWeighting.cpp +++ b/Modules/Classification/CLMiniApps/CLSurWeighting.cpp @@ -1,73 +1,73 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkForest_cpp #define mitkForest_cpp #include "time.h" #include #include #include #include #include #include #include #include #include int main(int argc, char* argv[]) { MITK_INFO << "Argc " << argc; ////////////////////////////////////////////////////////////////////////////// // Read Images ////////////////////////////////////////////////////////////////////////////// mitk::DataCollection::Pointer col = mitk::DataCollection::New(); MITK_INFO << "Arg 2 " << argv[2]; mitk::Image::Pointer sur=mitk::IOUtil::LoadImage(argv[2]); col->AddData(sur.GetPointer(),"sur"); MITK_INFO << "Arg 3 " << argv[3]; mitk::Image::Pointer mask=mitk::IOUtil::LoadImage(argv[3]); col->AddData(mask.GetPointer(),"mask"); std::vector modalities; for (int i = 4; i < argc; ++i) { MITK_INFO << "Img " << argv[i]; std::stringstream ss; ss << i; modalities.push_back(ss.str()); mitk::Image::Pointer img = mitk::IOUtil::LoadImage(argv[i]); col->AddData(img.GetPointer(),ss.str()); } mitk::LRDensityEstimation est; est.SetCollection(col); est.SetTrainMask("sur"); est.SetTestMask("mask"); est.SetModalities(modalities); est.SetWeightName("weight"); est.Update(); mitk::Image::Pointer w= col->GetMitkImage("weight"); - mitk::IOUtil::SaveImage(w,argv[1]); + mitk::IOUtil::Save(w,argv[1]); return 0; } -#endif \ No newline at end of file +#endif diff --git a/Modules/Classification/CLMiniApps/CLVoxelClassification.cpp b/Modules/Classification/CLMiniApps/CLVoxelClassification.cpp index 708c7556f5..949387a7cb 100644 --- a/Modules/Classification/CLMiniApps/CLVoxelClassification.cpp +++ b/Modules/Classification/CLMiniApps/CLVoxelClassification.cpp @@ -1,438 +1,437 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkForest_cpp #define mitkForest_cpp #include "time.h" #include #include #include #include #include #include #include #include #include #include #include // ----------------------- Forest Handling ---------------------- //#include #include //#include //#include //#include //#include // ----------------------- Point weighting ---------------------- //#include //#include //#include #include //#include //#include //#include //#include int main(int argc, char* argv[]) { MITK_INFO << "Starting MITK_Forest Mini-App"; - double startTime = time(0); ////////////////////////////////////////////////////////////////////////////// // Read Console Input Parameter ////////////////////////////////////////////////////////////////////////////// ConfigFileReader allConfig(argv[2]); bool readFile = true; std::stringstream ss; for (int i = 0; i < argc; ++i ) { MITK_INFO << "-----"<< argv[i]<<"------"; if (readFile) { if (argv[i][0] == '+') { readFile = false; continue; } else { try { allConfig.ReadFile(argv[i]); } catch (std::exception &e) { MITK_INFO << e.what(); } } } else { std::string input = argv[i]; std::replace(input.begin(), input.end(),'_',' '); ss << input << std::endl; } } allConfig.ReadStream(ss); try { ////////////////////////////////////////////////////////////////////////////// // General ////////////////////////////////////////////////////////////////////////////// int currentRun = allConfig.IntValue("General","Run",0); int doTraining = allConfig.IntValue("General","Do Training",1); std::string forestPath = allConfig.Value("General","Forest Path"); std::string trainingCollectionPath = allConfig.Value("General","Patient Collection"); std::string testCollectionPath = trainingCollectionPath; MITK_INFO << "Training collection: " << trainingCollectionPath; ////////////////////////////////////////////////////////////////////////////// // Read Default Classification ////////////////////////////////////////////////////////////////////////////// std::vector trainPatients = allConfig.Vector("Training Group",currentRun); std::vector testPatients = allConfig.Vector("Test Group",currentRun); std::vector modalities = allConfig.Vector("Modalities",0); std::string trainMask = allConfig.Value("Data","Training Mask"); std::string completeTrainMask = allConfig.Value("Data","Complete Training Mask"); std::string testMask = allConfig.Value("Data","Test Mask"); std::string resultMask = allConfig.Value("Data", "Result Mask"); std::string resultProb = allConfig.Value("Data", "Result Propability"); std::string outputFolder = allConfig.Value("General","Output Folder"); std::string writeDataFilePath = allConfig.Value("Forest","File to write data to"); ////////////////////////////////////////////////////////////////////////////// // Read Forest Parameter ////////////////////////////////////////////////////////////////////////////// int minimumSplitNodeSize = allConfig.IntValue("Forest", "Minimum split node size",1); int numberOfTrees = allConfig.IntValue("Forest", "Number of Trees",255); double samplesPerTree = atof(allConfig.Value("Forest", "Samples per Tree").c_str()); if (samplesPerTree <= 0.0000001) { samplesPerTree = 1.0; } MITK_INFO << "Samples per Tree: " << samplesPerTree; int sampleWithReplacement = allConfig.IntValue("Forest", "Sample with replacement",1); double trainPrecision = atof(allConfig.Value("Forest", "Precision").c_str()); if (trainPrecision <= 0.0000000001) { trainPrecision = 0.0; } double weightLambda = atof(allConfig.Value("Forest", "Weight Lambda").c_str()); if (weightLambda <= 0.0000000001) { weightLambda = 0.0; } int maximumTreeDepth = allConfig.IntValue("Forest", "Maximum Tree Depth",10000); - int randomSplit = allConfig.IntValue("Forest","Use RandomSplit",0); + // TODO int randomSplit = allConfig.IntValue("Forest","Use RandomSplit",0); ////////////////////////////////////////////////////////////////////////////// // Read Statistic Parameter ////////////////////////////////////////////////////////////////////////////// std::string statisticFilePath = allConfig.Value("Evaluation", "Statistic output file"); std::string statisticShortFilePath = allConfig.Value("Evaluation", "Statistic short output file"); std::string statisticShortFileLabel = allConfig.Value("Evaluation", "Index for short file"); std::string statisticGoldStandard = allConfig.Value("Evaluation", "Gold Standard Name","GTV"); - bool statisticWithHeader = allConfig.IntValue("Evaluation", "Write header in short file",0); + // TODO bool statisticWithHeader = allConfig.IntValue("Evaluation", "Write header in short file",0); std::vector labelGroupA = allConfig.Vector("LabelsA",0); std::vector labelGroupB = allConfig.Vector("LabelsB",0); ////////////////////////////////////////////////////////////////////////////// // Read Special Parameter ////////////////////////////////////////////////////////////////////////////// - bool useWeightedPoints = allConfig.IntValue("Forest", "Use point-based weighting",0); - bool writePointsToFile = allConfig.IntValue("Forest", "Write points to file",0); - int importanceWeightAlgorithm = allConfig.IntValue("Forest","Importance weight Algorithm",0); + // TODO bool useWeightedPoints = allConfig.IntValue("Forest", "Use point-based weighting",0); + // TODO bool writePointsToFile = allConfig.IntValue("Forest", "Write points to file",0); + // TODO int importanceWeightAlgorithm = allConfig.IntValue("Forest","Importance weight Algorithm",0); std::string importanceWeightName = allConfig.Value("Forest","Importance weight name",""); std::ofstream timingFile; timingFile.open((statisticFilePath + ".timing").c_str(), std::ios::app); timingFile << statisticShortFileLabel << ";"; std::time_t lastTimePoint; time(&lastTimePoint); ////////////////////////////////////////////////////////////////////////////// // Read Images ////////////////////////////////////////////////////////////////////////////// std::vector usedModalities; - for (int i = 0; i < modalities.size(); ++i) + for (std::size_t i = 0; i < modalities.size(); ++i) { usedModalities.push_back(modalities[i]); } usedModalities.push_back(trainMask); usedModalities.push_back(completeTrainMask); usedModalities.push_back(testMask); usedModalities.push_back(statisticGoldStandard); usedModalities.push_back(importanceWeightName); // vtkSmartPointer colReader = vtkSmartPointer::New(); mitk::CollectionReader* colReader = new mitk::CollectionReader(); colReader->AddDataElementIds(trainPatients); colReader->SetDataItemNames(usedModalities); //colReader->SetNames(usedModalities); mitk::DataCollection::Pointer trainCollection; if (doTraining) { trainCollection = colReader->LoadCollection(trainingCollectionPath); } colReader->ClearDataElementIds(); colReader->AddDataElementIds(testPatients); mitk::DataCollection::Pointer testCollection = colReader->LoadCollection(testCollectionPath); std::time_t now; time(&now); double seconds = std::difftime(now, lastTimePoint); timingFile << seconds << ";"; time(&lastTimePoint); /* if (writePointsToFile) { MITK_INFO << "Use external weights..."; mitk::ExternalWeighting weightReader; weightReader.SetModalities(modalities); weightReader.SetTestCollection(testCollection); weightReader.SetTrainCollection(trainCollection); weightReader.SetTestMask(testMask); weightReader.SetTrainMask(trainMask); weightReader.SetWeightsName("weights"); weightReader.SetCorrectionFactor(1.0); weightReader.SetWeightFileName(writeDataFilePath); weightReader.WriteData(); return 0; }*/ ////////////////////////////////////////////////////////////////////////////// // If required do Training.... ////////////////////////////////////////////////////////////////////////////// //mitk::DecisionForest forest; mitk::VigraRandomForestClassifier::Pointer forest = mitk::VigraRandomForestClassifier::New(); forest->SetSamplesPerTree(samplesPerTree); forest->SetMinimumSplitNodeSize(minimumSplitNodeSize); forest->SetTreeCount(numberOfTrees); forest->UseSampleWithReplacement(sampleWithReplacement); forest->SetPrecision(trainPrecision); forest->SetMaximumTreeDepth(maximumTreeDepth); forest->SetWeightLambda(weightLambda); - // TOOD forest.UseRandomSplit(randomSplit); + // TODO forest.UseRandomSplit(randomSplit); if (doTraining) { // 0 = LR-Estimation // 1 = KNN-Estimation // 2 = Kliep // 3 = Extern Image // 4 = Zadrozny // 5 = Spectral // 6 = uLSIF auto trainDataX = mitk::DCUtilities::DC3dDToMatrixXd(trainCollection, modalities, trainMask); auto trainDataY = mitk::DCUtilities::DC3dDToMatrixXi(trainCollection, trainMask, trainMask); //if (useWeightedPoints) if (false) { MITK_INFO << "Activated Point-based weighting..."; //forest.UseWeightedPoints(true); forest->UsePointWiseWeight(true); //forest.SetWeightName("calculated_weight"); /*if (importanceWeightAlgorithm == 1) { mitk::KNNDensityEstimation est; est.SetCollection(trainCollection); est.SetTrainMask(trainMask); est.SetTestMask(testMask); est.SetModalities(modalities); est.SetWeightName("calculated_weight"); est.Update(); } else if (importanceWeightAlgorithm == 2) { mitk::KliepDensityEstimation est; est.SetCollection(trainCollection); est.SetTrainMask(trainMask); est.SetTestMask(testMask); est.SetModalities(modalities); est.SetWeightName("calculated_weight"); est.Update(); } else if (importanceWeightAlgorithm == 3) { forest.SetWeightName(importanceWeightName); } else if (importanceWeightAlgorithm == 4) { mitk::ZadroznyWeighting est; est.SetCollection(trainCollection); est.SetTrainMask(trainMask); est.SetTestMask(testMask); est.SetModalities(modalities); est.SetWeightName("calculated_weight"); est.Update(); } else if (importanceWeightAlgorithm == 5) { mitk::SpectralDensityEstimation est; est.SetCollection(trainCollection); est.SetTrainMask(trainMask); est.SetTestMask(testMask); est.SetModalities(modalities); est.SetWeightName("calculated_weight"); est.Update(); } else if (importanceWeightAlgorithm == 6) { mitk::ULSIFDensityEstimation est; est.SetCollection(trainCollection); est.SetTrainMask(trainMask); est.SetTestMask(testMask); est.SetModalities(modalities); est.SetWeightName("calculated_weight"); est.Update(); } else*/ { mitk::LRDensityEstimation est; est.SetCollection(trainCollection); est.SetTrainMask(trainMask); est.SetTestMask(testMask); est.SetModalities(modalities); est.SetWeightName("calculated_weight"); est.Update(); } auto trainDataW = mitk::DCUtilities::DC3dDToMatrixXd(trainCollection, "calculated_weight", trainMask); forest->SetPointWiseWeight(trainDataW); forest->UsePointWiseWeight(true); } forest->Train(trainDataX, trainDataY); // TODO forest.Save(forestPath); } else { // TODO forest.Load(forestPath); } time(&now); seconds = std::difftime(now, lastTimePoint); timingFile << seconds << ";"; time(&lastTimePoint); ////////////////////////////////////////////////////////////////////////////// // If required do Save Forest.... ////////////////////////////////////////////////////////////////////////////// //writer.// (forest); /* auto w = forest->GetTreeWeights(); w(0,0) = 10; forest->SetTreeWeights(w);*/ mitk::IOUtil::Save(forest,"d:/tmp/forest.forest"); ////////////////////////////////////////////////////////////////////////////// // If required do test ////////////////////////////////////////////////////////////////////////////// auto testDataX = mitk::DCUtilities::DC3dDToMatrixXd(testCollection,modalities, testMask); auto testDataNewY = forest->Predict(testDataX); //MITK_INFO << testDataNewY; mitk::DCUtilities::MatrixToDC3d(testDataNewY, testCollection, resultMask, testMask); //forest.SetMaskName(testMask); //forest.SetCollection(testCollection); //forest.Test(); //forest.PrintTree(0); time(&now); seconds = std::difftime(now, lastTimePoint); timingFile << seconds << ";"; time(&lastTimePoint); ////////////////////////////////////////////////////////////////////////////// // Cost-based analysis ////////////////////////////////////////////////////////////////////////////// // TODO Reactivate //MITK_INFO << "Calculate Cost-based Statistic "; //mitk::CostingStatistic costStat; //costStat.SetCollection(testCollection); //costStat.SetCombinedA("combinedHealty"); //costStat.SetCombinedB("combinedTumor"); //costStat.SetCombinedLabel("combinedLabel"); //costStat.SetMaskName(testMask); ////std::vector labelHealthy; ////labelHealthy.push_back("result_prop_Class-0"); ////labelHealthy.push_back("result_prop_Class-4"); ////std::vector labelTumor; ////labelTumor.push_back("result_prop_Class-1"); ////labelTumor.push_back("result_prop_Class-2"); ////labelTumor.push_back("result_prop_Class-3"); //costStat.SetProbabilitiesA(labelGroupA); //costStat.SetProbabilitiesB(labelGroupB); //std::ofstream costStatisticFile; //costStatisticFile.open((statisticFilePath + ".cost").c_str(), std::ios::app); //std::ofstream lcostStatisticFile; //lcostStatisticFile.open((statisticFilePath + ".longcost").c_str(), std::ios::app); //costStat.WriteStatistic(lcostStatisticFile,costStatisticFile,2.5,statisticShortFileLabel); //costStatisticFile.close(); //costStat.CalculateClass(50); ////////////////////////////////////////////////////////////////////////////// // Save results to folder ////////////////////////////////////////////////////////////////////////////// std::vector outputFilter; //outputFilter.push_back(resultMask); //std::vector propNames = forest.GetListOfProbabilityNames(); //outputFilter.insert(outputFilter.begin(), propNames.begin(), propNames.end()); mitk::CollectionWriter::ExportCollectionToFolder(testCollection, outputFolder + "/result_collection.xml", outputFilter); MITK_INFO << "Calculate Statistic...." ; ////////////////////////////////////////////////////////////////////////////// // Calculate and Print Statistic ////////////////////////////////////////////////////////////////////////////// std::ofstream statisticFile; statisticFile.open(statisticFilePath.c_str(), std::ios::app); std::ofstream sstatisticFile; sstatisticFile.open(statisticShortFilePath.c_str(), std::ios::app); mitk::CollectionStatistic stat; stat.SetCollection(testCollection); stat.SetClassCount(2); stat.SetGoldName(statisticGoldStandard); stat.SetTestName(resultMask); stat.SetMaskName(testMask); stat.Update(); //stat.Print(statisticFile,sstatisticFile,statisticWithHeader, statisticShortFileLabel); stat.Print(statisticFile,sstatisticFile,true, statisticShortFileLabel); statisticFile.close(); time(&now); seconds = std::difftime(now, lastTimePoint); timingFile << seconds << std::endl; time(&lastTimePoint); timingFile.close(); } catch (std::string s) { MITK_INFO << s; return 0; } catch (char* s) { MITK_INFO << s; } return 0; } -#endif \ No newline at end of file +#endif