-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.h
214 lines (185 loc) · 8.06 KB
/
mainwindow.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#include <QMainWindow>
#include <QDoubleValidator>
#include <QStringList>
#include <vector>
#include <unordered_map>
#include <chrono>
#include <deque> // Different kind of vector -- no need for copy constructors.
#include "UI/plotLabel.h"
#include "QCustomPlot/qcustomplot.h"
#include <qwt_plot_curve.h>
#include "Reservoir_sampling/reservoirSamplingAlgorithm.h"
#include "Reservoir_sampling/sample.h"
#include "Functions/Kernels/kernels.h"
#include "KDE/kerneldensityestimator.h"
#include "KDE/smoothingParameterCounter.h"
#include "Functions/function.h"
#include "groupingThread/kMedoidsAlgorithm/attributeData.h"
#include "ClusterKernelWrappers/enhancedClusterKernelAlgorithm.h"
#include "Benchmarking/errorsCalculator.h"
#include "DESDA.h"
#include "kerDepCcWde.h"
#include "SOMKEAlgorithm.h"
#include "UI/plot.h"
enum class KernelSettingsColumns : int {
kKernelColumnIndex = 0,
kSmoothingParameterColumnIndex = 1,
kCarrierRestrictionColumnIndex = 2
};
enum class TargetFunctionSettingsColumns : int {
kMeanColumnIndex = 0,
kStandardDeviationColumnIndex = 1,
kContributionColumnIndex = 2
};
enum class ReservoirSamplingAlgorithms : int {
kBasicReservoirSamplingAlgorithm = 0,
kBiasedReservoirSamplingAlgorithm = 1
};
namespace Ui {
class MainWindow;
}
typedef std::shared_ptr<double> double_ptr;
typedef std::shared_ptr<int> int_ptr;
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
protected:
int step_number_ = 0;
QVector<std::shared_ptr<point>> domain_;
QVector<double> drawable_domain_;
QVector<std::shared_ptr<plotLabel>> plot_labels_;
double label_vertical_offset_ = 0;
double label_horizontal_offset_ = 0;
const double label_vertical_offset_step_ = 0.03;
void AddErrorLabelsToPlot(const QVector<QString> &labels, const QVector<double_ptr> &values);
void AddErrorLabelToPlot(const QString &label, double *value);
void AddDoubleLabelToPlot(const QString &label, double *value);
void AddIntLabelToPlot(const QString &label, int *value);
void AddConstantLabelToPlot(const QString &label);
void AddL1ErrorsToSum(QVector<ErrorsCalculator*> &errors_calculators, QVector<double> &errors_sums);
void AddL2ErrorsToSum(QVector<ErrorsCalculator*> &errors_calculators, QVector<double> &errors_sums);
void AddSupErrorsToSum(QVector<ErrorsCalculator*> &errors_calculators, QVector<double> &errors_sums);
void AddModErrorsToSum(QVector<ErrorsCalculator*> &errors_calculators, QVector<double> &errors_sums);
void AddColorsLegendToPlot();
private:
// Pens for 1d plot
const QPen model_plot_pen_ = QPen(Qt::red);
//const QPen windowed_plot_pen_ = QPen(QColor(255, 220, 0));
const QPen windowed_plot_pen_ = QPen(QColor(255, 195, 0));
const QPen kde_plot_pen_ = QPen(QColor(0, 255, 0));
const QPen weighted_plot_pen_ = QPen(QColor(0, 255, 255));
const QPen desda_kde_plot_pen_ = QPen(QColor(0, 0, 255));
const QPen desda_rare_elements_kde_plot_pen_ = QPen(Qt::black, 2);
const QPen derivative_plot_pen_ = QPen(QColor(185, 160, 130)); // Orange
const QPen standardized_derivative_plot_pen_ = QPen(QColor(110, 40, 0)); // Yellow
void FillErrorIndicesColors();
QVector<QColor> error_indices_colors = {};
// Contour plots
Plot *contour_plot_ = nullptr;
std::vector<QCPAbstractItem *> lines_on_plot_;
long long start = 0;
int screen_generation_frequency_ = 1;
// Default settings
const qreal kMaxX = 999.0;
const qreal kMinX = -999.0;
const qreal kMaxY = 99.0;
const qreal kMinY = -99.0;
const qreal kMinSmoothingParameter = 0.0;
const qreal kMaxSmoothingParameter = 2.0;
const int kDecimalNumbers = 3;
const qreal kDefaultMinX = -5;
const qreal kDefaultMaxX = 15;
const qreal kDefaultMinY = -0.3;
const qreal kDefaultMaxY = 0.5;
std::vector<std::shared_ptr<cluster>> stored_medoids_;
Ui::MainWindow *ui;
vector<std::shared_ptr<vector<double>>> samples_;
std::vector<std::shared_ptr<sample>> objects_;
std::vector<std::shared_ptr<cluster>> *clusters_ = nullptr;
std::unordered_map<std::string, attributeData *> attributes_data_;
// Tests
/*static*/ void testNewFunctionalities();
void SetupValidators();
void SetupPlot();
void SetupKernelsTable();
// Prediction
QVector<double> kernel_prognosis_derivative_values_;
// Errors
double l1_w_ = 0, l1_n_ = 0,
l2_w_ = 0, l2_n_ = 0,
sup_w_ = 0, sup_n_ = 0,
mod_w_ = 0, mod_n_ = 0;
QVector<std::pair<std::vector<double>, double>>
atypical_elements_points_and_derivatives_ = {};
double quantile_estimator_value_ = 0;
std::shared_ptr<dataParser> parser_;
std::shared_ptr<dataReader> reader_;
std::shared_ptr<kernelDensityEstimator> derivative_estimator_;
std::shared_ptr<kernelDensityEstimator> enhanced_kde_;
vector<std::shared_ptr<vector<double>>> means_, standard_deviations_;
QStringList kernel_types_;
std::shared_ptr<function> target_function_;
void DrawPlots(DESDA *DESDAAlgorithm);
void DrawPlots(EnhancedClusterKernelAlgorithm *CKAlgorithm);
void DrawPlots(KerDEP_CC_WDE *WDEAlgorithm);
void DrawPlots(SOMKEAlgorithm *somke_algorithm);
void ClearPlot();
void AddPlot(const QVector<qreal> *Y, const QPen &pen);
void ResizePlot();
unsigned long long MarkUncommonClusters(DESDA *DESDAAlgorithm);
void MarkUncommonClusters2D(DESDA *DESDAAlgorithm, std::deque<QwtPlotCurve> *uncommon_clusters_markers);
void FillStandardDeviations(
vector<std::shared_ptr<vector<double>>> *stDevs);
void FillMeans(vector<std::shared_ptr<vector<double>>> *means);
private slots:
void RefreshKernelsTable();
void AddKernelToTable(int rowNumber,
QDoubleValidator *smoothingParameterValidator);
void RefreshTargetFunctionTable();
void UniformContributions();
qreal CountLastContribution();
void UpdateLastContribution();
void FillDomain(QVector<std::shared_ptr<point> > *domain,
std::shared_ptr<point> *prototypePoint);
distribution *GenerateTargetDistribution(
vector<std::shared_ptr<vector<double>>> *means,
vector<std::shared_ptr<vector<double>>> *stDevs,
double additionalMultiplier=1);
reservoirSamplingAlgorithm *GenerateReservoirSamplingAlgorithm(
dataReader *reader,
dataParser *parser);
kernelDensityEstimator *GenerateKernelDensityEstimator(
int dimensionsNumber, const bool &radial=false);
function *GenerateTargetFunction(
vector<std::shared_ptr<vector<double>>> *means,
vector<std::shared_ptr<vector<double>>> *stDevs,
double additionalMultiplier=1);
static int CanAnimationBePerformed(int dimensionsNumber);
static QString FormatNumberForDisplay(double number);
void on_pushButton_start_clicked();
void Run1DExperimentWithDESDA();
void Run1DExperimentWithClusterKernels();
void Run1DExperimentWithWDE();
void Run1DExperimentWithSOMKE();
void RunAccuracyExperiment();
void on_spinBox_dimensionsNumber_editingFinished();
void on_pushButton_addTargetFunction_clicked();
void on_pushButton_removeTargetFunction_clicked();
void on_pushButton_clicked();
void resizeEvent(QResizeEvent *event) override;
// 2D Plot
static std::vector<std::vector<double>> Generate2DPlotErrorDomain(const QVector<double> &xErrorDomain,
const QVector<double> &yErrorDomain);
static std::vector<std::vector<double>> Generate1DPlotErrorDomain(DESDA *DESDAAlgorithm);
static std::vector<std::vector<double>> Generate1DWindowedPlotErrorDomain(DESDA *DESDAAlgorithm);
static double Calculate2DDomainArea(const std::vector<std::vector<double>> &domain);
static std::vector<double> GetFunctionsValueOnDomain(function *func, const std::vector<std::vector<double>> &domain);
// 3D exp
void run_3d_experiment();
void on_toolButton_findDataStream_clicked();
};
#endif // MAIN_WINDOW_H