Newer
Older
#include "entrypoint.h"
#include "parameter.h"
#include "print.h"
#include "operation.h"
#include "dtw.h"
#include "lcss.h"
#include "pdtw.h"
#include "help.h"
#include "calcul.h"
#include "draw.h"
#include "preprocess.h"
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
void mains::master(vtr<string> const &args)
{
/*TContent<int, int, int, int> stru(0, 0, 1, 2);
stru.*/
auto params = parseParameters(args);
master_run(params);
}
vtr<result_operation> mains::master_run(vtr<parameter> const ¶ms)
{
vtr<result_operation> results;
for (auto p : params)
results.push_back(master_run(p));
for (size_t i = 0; i < results.size(); i++)
{
printResult(results[i], params[i]);
}
return results;
}
result_operation mains::master_run(parameter const ¶m)
{
result_time times;
auto begin = chrono::steady_clock::now();
auto data = parseData(param);
times.parsing = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - begin).count();
begin = chrono::steady_clock::now();
preprocess(data, param);
times.preprocesing = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - begin).count();
if (param.isDebugInfo()) {
cout << print::input(data.input, 30) << endl; // print for debug comment or delete if not needed
cout << print::input(data.query, 30) << endl; // print for debug comment or delete if not needed
}
begin = chrono::steady_clock::now();
auto result = run(data, param);
times.opeartion = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - begin).count();
result.time = times;
writeResult(data, result, times, param);
return result;
}
vtr<parameter> mains::parseParameters(vtr<string> const &args)
vector<string> scripts;
for (size_t i = 0; i < args.size() - 1; i++)
{
if (args[i] == "-script")
{
scripts = parser::readFileByLine(args[i + 1]);
auto param = parameter::setParameters(args);
vtr<parameter> params(scripts.size());
for (size_t i = 0; i < scripts.size(); i++) //secondary switches applyed to all script lines ...for more robust behaviour
auto lineArgs = help::split(scripts[i], " \t");
parameter::applyParameter(lineArgs, args);
params[i] = parameter::setParameters(lineArgs);
params.push_back(param);
return params;
input_data mains::parseData(parameter const ¶ms)
{
data.files.input = parser::getAllFileNames(params.inPath); //file path of all input files
data.files.query = parser::getAllFileNames(params.inQuery); //file path of all input files
data.files.keyInput = parser::getAllFileNames(params.inKeyInput); //file path of all input files
data.files.keyQuery = parser::getAllFileNames(params.inKeyQuery); //file path of all input files
data.input = parser::readData<double>(data.files.input); //parsing
if (data.input.size() < 1)
throw runtime_error("problem occured when loading input data");
if (params.distance == 4)
data.keyInput = parser::readData<int>(data.files.keyInput);
data.query = parser::readData<double>(data.files.query); //parsing
if (data.query.size() < 1)
throw runtime_error("problem occured when loading query data");
if (params.distance == 4)
data.keyInput = parser::readData<int>(data.files.keyQuery);
if (params.isClusters()) //parsing clusters file
{
auto clusterTmp = parser::parseClusters(data.files.query, params.inClusterPath);
data.clusters = parser::parseClusters(data.files.input, params.inClusterPath);
int clusterSize = (int)data.clusters.ids.size();
for (size_t i = 0; i < clusterTmp.ids.size(); i++)
data.clusters.ids[(int)i + clusterSize + 1] = clusterTmp.ids.at((int)i + 1);
}
}
catch (const std::exception &e)
{
cout << e.what() << endl;
exit(0);
}
if (params.isDebugInfo())
{
cout << print::vector(data.files.query);
cout << print::vector(data.files.input);
cout << print::input(data.query, 30) << endl; // print for debug comment or delete if not needed
cout << print::input(data.input, 30) << endl; // print for debug comment or delete if not needed
cout << print::inputStats(data.input, 30);
cout << print::inputStats(data.query, 30);
return data;
}
result_operation mains::run(input_data const &data, parameter const ¶ms)
{
result_operation result;
if (params.operation < 2 || params.operation == 3 || params.operation == 5)
{
auto single = data.convert_inputDataSingle();
result = operation::main(single, params);
}
else
result = operation::main(data, params);
result_operation mains::extern_logic(vtr3<double> const &input, vtr<string> const &args)
{
//cout << print::printVector(args);
auto params = parameter::setParameters(args);
//INPUT DATA PARSING
input_data data;
result_time times;
auto begin = chrono::steady_clock::now();
data.input = input;
vtr<string> inputFiles(input.size());
for (size_t i = 0; i < input.size(); i++)
{
inputFiles[i] = "ext" + to_string((int)i + 1);
}
data.files.input = inputFiles;
begin = chrono::steady_clock::now();
preprocess(data, params);
times.preprocesing = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - begin).count();
if (params.isDebugInfo())
cout << print::input(data.input, 30) << endl; // print for debug comment or delete if not needed
//RUN METHOD
//begin = chrono::steady_clock::now();
result_operation result;
if (params.operation < 2 || params.operation == 3 || params.operation == 5)
{
auto dataSingle = data.convert_inputDataSingle();
result = operation::main(dataSingle, params);
}
else
result = operation::main(data, params);
//times.opeartion = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - begin).count();
//PRINT REUSULT
//mains::printResultLogic(data, result, times, params);
return result;
}
void mains::preprocess(input_data &data, parameter const& params)
{
//DATA PREPROCESSING
if (params.isReduce()) {
preprocess::reduce<double>(data.input, params.reduce);
preprocess::reduce<double>(data.query, params.reduce);
preprocess::reduce<int>(data.keyInput, params.reduce);
preprocess::reduce<int>(data.keyQuery, params.reduce);
preprocess::paa<double>(data.input, params.paa);
preprocess::paa<double>(data.query, params.paa);
preprocess::paa<int>(data.keyInput, params.paa);
preprocess::paa<int>(data.keyQuery, params.paa);
if (params.isSax()) {
preprocess::sax(data.input, params.sax);
preprocess::sax(data.query, params.sax);
preprocess::prolong<double>(data.input, params.prolong);
preprocess::prolong<double>(data.query, params.prolong);
preprocess::prolong<int>(data.keyInput, params.prolong);
preprocess::prolong<int>(data.keyQuery, params.prolong);
}
//if (params.isZNormalization())
// help::normalizeMany(input);
if (params.isInterpolate()) {
preprocess::interpolate(data.input);
preprocess::interpolate(data.query);
preprocess::normalizeZeroOne(data.input, params.normalize);
preprocess::normalizeZeroOne(data.query, params.normalize);
preprocess::smooth(data.input, params.smooth);
preprocess::smooth(data.query, params.smooth);
void mains::printResult(result_operation &result, parameter const ¶ms)
if (!result.dtw.score.empty())
cout << print::vector(result.dtw.score);
if (params.isPrintOutput()) {
if (params.isOmp())
cout << print::matrix(result.matrixSimilarity[params.scoreType], params);
cout << print::matrix(result.matrixCluster[params.scoreType], params);
cout << print::scores_clustering(result, params.precision);
if (params.isTime())
cout << print::timeMeasures(result.time, params);
}
void mains::writeResult(input_data const &data, result_operation &result, result_time ×, parameter const ¶ms)
{
/*if (!result.matrixSimilarity.empty())
result.matrixSimilarity = help::alterStructure(result.matrixSimilarity);*/
//WRITE LOG FILES
if (params.isWriteOutput()) {
print::write(print::matrix(result.matrixSimilarity[params.scoreType], params), params.outputPath + ".matrix", false);
print::write(print::scores_clustering(result, params.precision), params.outputPath + ".score", false);
}
if (params.isHtml())
{
print::write(
/*print::printParameterString(args) + "</br>" +*/
print::scores_clustering(result, params.precision) +
print::htmlClusters(data.input, result.matrixCluster[0], data.clusters), params.outputPath + ".html", true);
print::write(print::gdf(data.files.input, data.input, result.matrixSimilarity[params.scoreType], data.clusters), params.outputPath + ".gdf", false);
print::write(print::timeMeasures(times, params), params.outputPath + ".time", false);