-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisual.cpp
249 lines (230 loc) · 6.8 KB
/
visual.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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#pragma once
#include "MyForm.h"
using namespace DoseEffectsWithGui;
/*chart functions */
void MyForm::addToGraph(coreType ct, System::Windows::Forms::DataVisualization::Charting::Chart^ chart) {
if (u == NULL) return;
System::Windows::Forms::DataVisualization::Charting::Series^ col;
switch (ct)
{
case DoseEffectsWithGui::epiph:
col = chart->Series["Func"];
break;
case DoseEffectsWithGui::cos:
col = chart->Series["Func1"];
break;
case DoseEffectsWithGui::lap:
col = chart->Series["Func2"];
break;
case DoseEffectsWithGui::gaus:
col = chart->Series["Func3"];
break;
case DoseEffectsWithGui::quart:
col = chart->Series["Func4"];
break;
case DoseEffectsWithGui::ravn:
col = chart->Series["Func5"];
break;
case DoseEffectsWithGui::triangl:
col = chart->Series["Func6"];
break;
//this is normal distribution
case DoseEffectsWithGui::notCore:
col = chart->Series["Func7"];
default:
break;
}
col->Points->Clear();
for (int i = 0; i < numberOfPoints; i++) {
col->Points->AddXY(f[i].x, f[i].y);
}
}
void MyForm::clearAllGraphs(System::Windows::Forms::DataVisualization::Charting::Chart^ chart) {
chart->Series["Func"]->Points->Clear();
chart->Series["Func1"]->Points->Clear();
chart->Series["Func2"]->Points->Clear();
chart->Series["Func3"]->Points->Clear();
chart->Series["Func4"]->Points->Clear();
chart->Series["Func5"]->Points->Clear();
chart->Series["Func6"]->Points->Clear();
chart->Series["Func7"]->Points->Clear();
}
void MyForm::drawGraph(coreType ct, System::Windows::Forms::DataVisualization::Charting::Chart^ chart) {
clearAllGraphs(chart);
addToGraph(ct, chart);
}
/*Other*/
coreType MyForm::getCoreType() {
String^ coreValue = Convert::ToString(comboBox1->SelectedItem);
if (coreValue == "Åïàíå÷íèêîâà ÿäðî") {
return epiph;
}
else if (Convert::ToString(comboBox1->SelectedItem) == "Êîñèíóñ-ÿäðî") {
return cos;
}
else if (coreValue == "Ëàïëàñà ÿäðî") {
return lap;
}
else if (coreValue == "Ãàóññîâî ÿäðî ") {
return gaus;
}
else if (coreValue == "Êâàäðàòè÷åñêîå ÿäðî") {
return quart;
}
else if (coreValue == "Ðàâíîìåðíîå ÿäðî") {
return ravn;
}
else if (coreValue == "Òðåóãîëüíîå ÿäðî") {
return triangl;
}
else {
return epiph;
}
}
/*read/parse/update parameters*/
void MyForm::refreshGrid() {
while (dataGridViewU->Rows->Count > 1)
for (int i = 0; i < dataGridViewU->Rows->Count - 1; i++) {
dataGridViewU->Rows->Remove(dataGridViewU->Rows[i]);
}
if (u != NULL) {
for (int i = 0; i < volume; i++) {
dataGridViewU->Rows->Add();
dataGridViewU->Rows[i]->Cells[0]->Value = Convert::ToString(u[i]);
dataGridViewU->Rows[i]->Cells[1]->Value = Convert::ToString(w[i]);
}
}
}
void MyForm::parseInterval() {
try {
x_low = Convert::ToDouble(textBox1->Text);
x_high = Convert::ToDouble(textBox2->Text);
}
catch (...) {
try {
String^ s = textBox1->Text->Replace('.', ',');
x_low = Convert::ToDouble(s);
s = textBox2->Text->Replace('.', ',');
x_high = Convert::ToDouble(s);
}
catch (...) {
MessageBox::Show("Èíòåðâàë óêàçàí íåâåðíî");
return;
}
}
}
void MyForm::countInterval(double &low, double &high) {
//ñòðîèì ôóíêöèþ ïî âñåì âñòðå÷àþùèìñÿ çíà÷åíèÿì
low = *(std::min_element(u, u + volume));
high = *(std::max_element(u, u + volume));
}
void MyForm::updateRange() {
double low, high;
if (u != NULL) {
countInterval(low, high);
}
else {
double range = sqrt(Convert::ToDouble(numericUpDown7->Value)) * 3;
low = Convert::ToDouble(numericUpDown6->Value) - range;
high = Convert::ToDouble(numericUpDown6->Value) + range;
}
textBox1->Text = Convert::ToString(low);
textBox2->Text = Convert::ToString(high);
x_low = low;
x_high = high;
}
/*button clicks*/
void MyForm::generate() {
if (u != NULL) {
delete[] u;
delete[] w;
delete[] f;
}
volume = Convert::ToInt32(numericUpDown4->Value);
if (Convert::ToString(comboBox2->SelectedItem) != "From file") {
u = new double[volume];
w = new double[volume];
double M = Convert::ToDouble(numericUpDown6->Value); //mean
double D = Convert::ToDouble(numericUpDown7->Value); //dispersion
createUArray(u, volume, M, sqrt(D));
createWArray(u, w, volume, M, sqrt(D));
updateRange();
}
else {
//donow
}
refreshGrid();
}
point* getNormalDistribution(double x_low, double x_high, double step, double M, double stddev) {
// create normal distribution of double with set mean and stddev
normal_distribution <double> distribution(M, stddev);
int number_of_calc = (int)((x_high - x_low) / step);
point* result = new point[number_of_calc];
double x = x_low, y = 0.0;
for (int i = 0; i < number_of_calc; i++, x+=step) {
result[i].x = x;
// Returns the probability of [-inf,x] of a gaussian distribution
result[i].y = 0.5 * (1 + erf((x - M) / (stddev * sqrt(2.))));
}
return result;
}
//åñëè ó íàñ âûáîðêà ïîëó÷åíà ñëó÷àéíûì îáðàçîì, òî ìû çíàåì çàðàíåå, êàê ðàñïðåäåë¸í Õ è ìîæåì
// äîáàâèòü íà ÷àðòû ãðàôèêè CDF (cumulative distribution function), ò.å. ôóíêöèþ ðàñïðåäåëåíèÿ äëÿ íîðìàëüíîãî
// ðàñïðåäåëåíèÿ ñ çàäàííûìè ìàò. îæèäàíèåì è ñòàíäàðòíûì îòêëîíåíèåì
void MyForm::addCDFtoChart(System::Windows::Forms::DataVisualization::Charting::Chart^ chart) {
if (Convert::ToString(comboBox2->SelectedItem) == "From file") return;
double M = Convert::ToDouble(numericUpDown6->Value); //mean
double D = Convert::ToDouble(numericUpDown7->Value); //dispersion
f = getNormalDistribution(x_low, x_high, step, M, sqrt(D));
addToGraph(notCore, chart);
}
Core* MyForm::createCore() {
cT = getCoreType();
Core *core;
switch (cT)
{
case DoseEffectsWithGui::epiph:
core = new EpanchCore;
break;
case DoseEffectsWithGui::cos:
core = new CosCore;
break;
case DoseEffectsWithGui::lap:
core = new LaplCore;
break;
case DoseEffectsWithGui::ravn:
core = new RavnCore;
break;
case DoseEffectsWithGui::gaus:
core = new GausCore;
break;
case DoseEffectsWithGui::triangl:
core = new TreangCore;
break;
case DoseEffectsWithGui::quart:
core = new SquareCore;
break;
default:
core = new EpanchCore;
break;
}
return core;
}
void MyForm::doNWestimate(){
step = Convert::ToDouble(numericUpDown3->Value);
c = Convert::ToDouble(numericUpDown5->Value);
h = c * pow(volume, -0.2);
Core* core = createCore();
numberOfPoints = (int)((x_high - x_low) / step);
f = getFbiased(x_low, x_high, step, core, h, u, w, volume);
delete core;
}
void MyForm::doKnnEstimate() {
step = Convert::ToDouble(numericUpDown3->Value);
numberOfPoints = (int)((x_high - x_low) / step);
cT = getCoreType();
Core *core = createCore();
int k = Convert::ToInt32(numericUpDown1->Value);
f = getKNN(x_low, x_high, step, core, k, u, w, volume);
delete core;
}