12 #ifndef mitkForest_cpp 13 #define mitkForest_cpp 28 vnl_matrix<double> feature;
29 vnl_vector<double> label;
37 std::fstream file(path);
38 std::vector<std::vector<double> > listOfRows;
41 while (std::getline(file, line))
44 if (listOfRows.size() < 1)
46 listOfRows.push_back(current_row);
48 else if (current_row.size() == listOfRows[0].size())
50 listOfRows.push_back(current_row);
55 vnl_matrix<double> result(listOfRows.size(), listOfRows[0].size());
56 for (std::size_t i = 0; i < listOfRows.size(); ++i)
58 for (std::size_t j = 0; j < listOfRows[0].size(); ++j)
60 result(i, j) = listOfRows[i][j];
69 std::fstream file(train);
70 std::vector<std::vector<double> > listOfRows;
71 std::vector<double> label;
77 while (std::getline(file, line))
80 if (listOfRows.size() < 1)
82 listOfRows.push_back(current_row);
86 else if (current_row.size() == listOfRows[0].size())
88 listOfRows.push_back(current_row);
95 std::fstream file2(test);
96 while (std::getline(file2, line))
99 if (listOfRows.size() < 1)
101 listOfRows.push_back(current_row);
105 else if (current_row.size() == listOfRows[0].size())
107 listOfRows.push_back(current_row);
114 vnl_matrix<double> resultMatrix(listOfRows.size(), listOfRows[0].size());
115 vnl_vector<double> resultLabel(listOfRows.size());
116 for (std::size_t i = 0; i < listOfRows.size(); ++i)
118 for (std::size_t j = 0; j < listOfRows[0].size(); ++j)
120 resultMatrix(i, j) = listOfRows[i][j];
122 resultLabel(i) = label[i];
125 set.feature = resultMatrix;
126 set.label = resultLabel;
127 set.ratio = trSamples / teSamples;
132 int main(
int argc,
char* argv[])
144 parser.
setTitle(
"Importance weighting algorithm");
145 parser.
setDescription(
"Calculates the importance weighting of two input matrixes. ");
148 MITK_INFO <<
"Extracting Parameters....";
149 std::map<std::string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
151 std::string trainingPath =
us::any_cast<std::string>(parsedArgs[
"training"]);
152 std::string predictionPath =
us::any_cast<std::string>(parsedArgs[
"prediction"]);
153 std::string outputPath =
us::any_cast<std::string>(parsedArgs[
"output"]);
159 MITK_INFO <<
"Calculating Weights...";
161 auto weights = glm.
ExpMu(input.feature);
163 MITK_INFO <<
"Writing Weights ...";
164 MITK_INFO << outputPath;
165 std::ofstream file(outputPath);
166 for (
unsigned int i = 0; i < input.label.size(); ++i)
168 if (input.label(i) < 0.5)
170 file << (input.ratio * weights(i)) << std::endl;
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false, mitkCommandLineParser::Channel channel=mitkCommandLineParser::Channel::None)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
Generalized Linear Model that allows linear models for non-gaussian data.
void setCategory(std::string category)
const vnl_matrix< double > ReadMatrix(std::string path)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
std::vector< double > MITKCLUTILITIES_EXPORT splitDouble(std::string str, char delimiter)
vnl_vector< double > ExpMu(const vnl_matrix< double > &x)
Estimation of the exponential factor for a given function.
void setTitle(std::string title)
void setDescription(std::string description)
const TrainingSet ReadBothMatrix(std::string train, std::string test)
int main(int argc, char *argv[])