-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gnuplot.cpp
51 lines (37 loc) · 1.56 KB
/
Gnuplot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
#include "Gnuplot.h"
#include <fstream>
#include <iostream>
#include <filesystem>
namespace Utils
{
void Gnuplot::Execute()
{
std::string cmdPath = getRelativePath();
{
std::filesystem::path p = std::filesystem::current_path();
if (cmdPath[0] != '/' && cmdPath[0] != '\\')
p += '/';
p += cmdPath;
p += getDataFileName();
if (cmdPath[cmdPath.length() - 1] != '/' && cmdPath[cmdPath.length() - 1] != '\\')
cmdPath += "/";
cmdPath += cmdFileName;
std::ofstream cmdf(cmdPath, std::ios::out | std::ios::trunc);
if (!cmdf.is_open()) return;
if (ctype == ChartType::logisticRegression)
{
cmdf << "plot " << p << " index 0 u 1:2 w l lt 1 lw 2 lc rgb \"blue\" title \"Generating Boundary\", " << p << " index 1 u 1:2 w p pt 7 ps 1 lc rgb \"green\" title \"Data Points First Class\", " << p << " index 2 u 1:2 w p pt 7 ps 1 lc rgb \"red\" title \"Data Points Second Class\"" << std::endl;
}
else if (ctype == ChartType::linearRegression)
{
cmdf << "plot " << p << " index 0 u 1:2 w l lt 1 lw 2 lc rgb \"blue\" title \"Generating Function\", " << p << " index 1 u 1:2 w p pt 7 ps 1 lc rgb \"green\" title \"Data Points\", " << p << " index 2 u 1:2 w l lt 1 lw 2 lc rgb \"red\" title \"Regression\"" << std::endl;
}
else
{
cmdf << "plot " << p << " index 0 u 1:2 w l lt 1 lw 2 lc rgb \"blue\" title \"Training Loss\", " << p << " index 1 u 1:2 w l lt 1 lw 2 lc rgb \"red\" title \"Validation Loss\"" << std::endl;
}
}
std::string cmd = std::string("start /b gnuplot --persist ") + cmdPath;
system(cmd.c_str());
}
}