- Integrated the file import into the main interface (not as a plugin anymore)
[mldemos:mldemos.git] / MLDemos / mlsaving.cpp
1 /*********************************************************************
2 MLDemos: A User-Friendly visualization toolkit for machine learning
3 Copyright (C) 2010  Basilio Noris
4 Contact: mldemos@b4silio.com
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free
18 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *********************************************************************/
20 #include "mldemos.h"
21 #include <QDebug>
22 #include <fstream>
23 #include <QPixmap>
24 #include <QBitmap>
25 #include <QSettings>
26 #include <QFileDialog>
27 #include <QTextStream>
28 #include "classifier.h"
29 #include "regressor.h"
30 #include <fstream>
31
32 using namespace std;
33
34 void MLDemos::SaveLayoutOptions()
35 {
36         QCoreApplication::setOrganizationDomain("b4silio");
37         QCoreApplication::setOrganizationName("b4silio");
38         QCoreApplication::setApplicationName("MLDemos");
39
40         QSettings settings;
41         settings.beginGroup("Gui");
42         settings.setValue("geometry", saveGeometry());
43         settings.setValue("windowState", saveState());
44         settings.setValue("algoGeometry", algorithmWidget->saveGeometry());
45         settings.setValue("drawGeometry", drawToolbarWidget->saveGeometry());
46         settings.setValue("displayGeometry", displayDialog->saveGeometry());
47         settings.setValue("statsGeometry", statsDialog->saveGeometry());
48         settings.setValue("compareGeometry", compareWidget->saveGeometry());
49
50         settings.setValue("algoTab", algorithmOptions->tabWidget->currentIndex());
51         settings.setValue("ShowAlgoOptions", algorithmWidget->isVisible());
52         settings.setValue("ShowCompare", compareWidget->isVisible());
53         settings.setValue("ShowDrawOptions", drawToolbarWidget->isVisible());
54         settings.setValue("ShowDisplayOptions", displayDialog->isVisible());
55         settings.setValue("ShowStatsOptions", statsDialog->isVisible());
56         settings.setValue("ShowToolbar", ui.actionShow_Toolbar->isChecked());
57         settings.setValue("SmallIcons", ui.actionSmall_Icons->isChecked());
58 //    settings.setValue("canvasType", ui.canvasTypeCombo->currentIndex());
59     settings.endGroup();
60
61         settings.beginGroup("displayOptions");
62     settings.setValue("infoCheck", displayOptions->infoCheck->isChecked());
63         settings.setValue("mapCheck", displayOptions->mapCheck->isChecked());
64         settings.setValue("modelCheck", displayOptions->modelCheck->isChecked());
65         settings.setValue("samplesCheck", displayOptions->samplesCheck->isChecked());
66         settings.setValue("gridCheck", displayOptions->gridCheck->isChecked());
67         settings.setValue("spinZoom", displayOptions->spinZoom->value());
68         settings.endGroup();
69
70         settings.beginGroup("drawingOptions");
71         settings.setValue("infoCheck", drawToolbarContext1->randCombo->currentIndex());
72         settings.setValue("spinCount", drawToolbarContext1->spinCount->value());
73         settings.setValue("spinSize", drawToolbarContext1->spinSize->value());
74         settings.setValue("spinAngle", drawToolbarContext2->spinAngle->value());
75         settings.setValue("spinSigmaX", drawToolbarContext2->spinSigmaX->value());
76         settings.setValue("spinSigmaY", drawToolbarContext2->spinSigmaY->value());
77         settings.setValue("spinObsAngle", drawToolbarContext3->spinAngle->value());
78         settings.setValue("spinObsSigmaX", drawToolbarContext3->spinSigmaX->value());
79         settings.setValue("spinObsSigmaY", drawToolbarContext3->spinSigmaY->value());
80         settings.setValue("spinObsPowerX", drawToolbarContext3->spinPowerX->value());
81         settings.setValue("spinObsPowerY", drawToolbarContext3->spinPowerY->value());
82         settings.setValue("spinObsRepulsionX", drawToolbarContext3->spinRepulsionX->value());
83         settings.setValue("spinObsRepulsionY", drawToolbarContext3->spinRepulsionY->value());
84         settings.setValue("spinRadius", drawToolbarContext4->spinRadius->value());
85         settings.setValue("spinAlpha", drawToolbarContext4->spinAlpha->value());
86         settings.setValue("eraseCheck", drawToolbar->eraseButton->isChecked());
87         settings.setValue("sprayCheck", drawToolbar->sprayButton->isChecked());
88         settings.setValue("singleCheck", drawToolbar->singleButton->isChecked());
89         settings.setValue("ellipseCheck", drawToolbar->ellipseButton->isChecked());
90         settings.setValue("lineCheck", drawToolbar->lineButton->isChecked());
91         settings.setValue("trajectoryCheck", drawToolbar->trajectoryButton->isChecked());
92         settings.setValue("obstacleCheck", drawToolbar->obstacleButton->isChecked());
93         settings.setValue("paintCheck", drawToolbar->paintButton->isChecked());
94         settings.setValue("infoCheck", drawToolbarContext1->randCombo->currentIndex());
95         settings.endGroup();
96
97         settings.beginGroup("classificationOptions");
98         settings.setValue("positiveClass", optionsClassify->positiveSpin->value());
99         settings.setValue("foldCount", optionsClassify->foldCountSpin->value());
100         settings.setValue("trainRatio", optionsClassify->traintestRatioCombo->currentIndex());
101         settings.setValue("tab", optionsClassify->tabWidget->currentIndex());
102         settings.endGroup();
103
104         settings.beginGroup("regressionOptions");
105         settings.setValue("foldCount", optionsRegress->foldCountSpin->value());
106         settings.setValue("trainRatio", optionsRegress->traintestRatioCombo->currentIndex());
107         settings.setValue("tab", optionsRegress->tabWidget->currentIndex());
108         settings.endGroup();
109
110         settings.beginGroup("dynamicalOptions");
111         settings.setValue("centerType", optionsDynamic->centerCombo->currentIndex());
112         settings.setValue("zeroCheck", optionsDynamic->zeroCheck->isChecked());
113         settings.setValue("resampleType", optionsDynamic->resampleCombo->currentIndex());
114         settings.setValue("resampleCount", optionsDynamic->resampleSpin->value());
115         settings.setValue("obstacleType", optionsDynamic->obstacleCombo->currentIndex());
116         settings.setValue("dT", optionsDynamic->dtSpin->value());
117         settings.setValue("tab", optionsDynamic->tabWidget->currentIndex());
118         settings.setValue("colorCheck", optionsDynamic->colorCheck->isChecked());
119         settings.endGroup();
120
121         settings.beginGroup("compareOptions");
122         settings.setValue("foldCount", optionsCompare->foldCountSpin->value());
123         settings.setValue("trainRatio", optionsCompare->traintestRatioCombo->currentIndex());
124         settings.endGroup();
125
126         settings.beginGroup("clusterOptions");
127     settings.setValue("tab", optionsCluster->tabWidget->currentIndex());
128     settings.setValue("trainRatio", optionsCluster->trainRatioCombo->currentIndex());
129     settings.setValue("optimizeCombo", optionsCluster->optimizeCombo->currentIndex());
130     settings.endGroup();
131
132     settings.beginGroup("maximizeOptions");
133     settings.setValue("tab", optionsMaximize->tabWidget->currentIndex());
134     settings.setValue("varianceSpin", optionsMaximize->varianceSpin->value());
135     settings.setValue("iterationsSpin", optionsMaximize->iterationsSpin->value());
136     settings.setValue("stoppingSpin", optionsMaximize->stoppingSpin->value());
137     settings.setValue("benchmarkCombo", optionsMaximize->benchmarkCombo->currentIndex());
138     settings.endGroup();
139
140     settings.beginGroup("projectOptions");
141     settings.setValue("tab", optionsProject->tabWidget->currentIndex());
142     settings.endGroup();
143
144         settings.beginGroup("statsOptions");
145         settings.setValue("tab", showStats->tabWidget->currentIndex());
146         settings.endGroup();
147
148         FOR(i,classifiers.size())
149         {
150                 if(!classifiers[i]) continue;
151                 settings.beginGroup(QString("plugins::classifiers::") + classifiers[i]->GetName());
152                 classifiers[i]->SaveOptions(settings);
153                 settings.endGroup();
154         }
155         FOR(i,clusterers.size())
156         {
157                 if(!clusterers[i]) continue;
158                 settings.beginGroup(QString("plugins::clusterers::") + clusterers[i]->GetName());
159                 clusterers[i]->SaveOptions(settings);
160                 settings.endGroup();
161         }
162         FOR(i,regressors.size())
163         {
164                 if(!regressors[i]) continue;
165                 settings.beginGroup(QString("plugins::regressors::") + regressors[i]->GetName());
166                 regressors[i]->SaveOptions(settings);
167                 settings.endGroup();
168         }
169         FOR(i,dynamicals.size())
170         {
171                 if(!dynamicals[i]) continue;
172                 settings.beginGroup(QString("plugins::dynamicals::") + dynamicals[i]->GetName());
173                 dynamicals[i]->SaveOptions(settings);
174                 settings.endGroup();
175         }
176     FOR(i,maximizers.size())
177     {
178         if(!maximizers[i]) continue;
179         settings.beginGroup(QString("plugins::maximizers::") + maximizers[i]->GetName());
180         maximizers[i]->SaveOptions(settings);
181         settings.endGroup();
182     }
183     FOR(i,projectors.size())
184     {
185         if(!projectors[i]) continue;
186         settings.beginGroup(QString("plugins::projectors::") + projectors[i]->GetName());
187         projectors[i]->SaveOptions(settings);
188         settings.endGroup();
189     }
190 }
191
192 void MLDemos::LoadLayoutOptions()
193 {
194         QCoreApplication::setOrganizationDomain("b4silio");
195         QCoreApplication::setOrganizationName("b4silio");
196         QCoreApplication::setApplicationName("MLDemos");
197
198         QSettings settings;
199         settings.beginGroup("Gui");
200         if(settings.contains("geometry")) restoreGeometry(settings.value("geometry").toByteArray());
201         if(settings.contains("windowState")) restoreState(settings.value("windowState").toByteArray());
202         if(settings.contains("algoGeometry")) algorithmWidget->restoreGeometry(settings.value("algoGeometry").toByteArray());
203         if(settings.contains("drawGeometry")) drawToolbarWidget->restoreGeometry(settings.value("drawGeometry").toByteArray());
204         if(settings.contains("displayGeometry")) displayDialog->restoreGeometry(settings.value("displayGeometry").toByteArray());
205         if(settings.contains("statsGeometry")) statsDialog->restoreGeometry(settings.value("statsGeometry").toByteArray());
206         if(settings.contains("compareGeometry")) compareWidget->restoreGeometry(settings.value("compareGeometry").toByteArray());
207 #ifdef MACX // ugly hack to avoid resizing problems on the mac
208         if(height() < 400) resize(width(),400);
209         if(algorithmWidget->height() < 220) algorithmWidget->resize(636,220);
210 #endif // MACX
211
212         if(settings.contains("algoTab")) algorithmOptions->tabWidget->setCurrentIndex(settings.value("algoTab").toInt());
213         if(settings.contains("ShowAlgoOptions")) algorithmWidget->setVisible(settings.value("ShowAlgoOptions").toBool());
214         if(settings.contains("ShowCompare")) compareWidget->setVisible(settings.value("ShowCompare").toBool());
215         if(settings.contains("ShowDrawOptions")) drawToolbarWidget->setVisible(settings.value("ShowDrawOptions").toBool());
216         if(settings.contains("ShowDisplayOptions")) displayDialog->setVisible(settings.value("ShowDisplayOptions").toBool());
217         if(settings.contains("ShowStatsOptions")) statsDialog->setVisible(settings.value("ShowStatsOptions").toBool());
218         if(settings.contains("ShowToolbar")) ui.actionShow_Toolbar->setChecked(settings.value("ShowToolbar").toBool());
219         if(settings.contains("SmallIcons")) ui.actionSmall_Icons->setChecked(settings.value("SmallIcons").toBool());
220 //    if(settings.contains("canvasType")) ui.canvasTypeCombo->setCurrentIndex(settings.value("canvasType").toInt());
221     settings.endGroup();
222
223     actionAlgorithms->setChecked(algorithmWidget->isVisible());
224         actionCompare->setChecked(compareWidget->isVisible());
225         actionDrawSamples->setChecked(drawToolbarWidget->isVisible());
226         actionDisplayOptions->setChecked(displayDialog->isVisible());
227         actionShowStats->setChecked(statsDialog->isVisible());
228
229         settings.beginGroup("displayOptions");
230         if(settings.contains("infoCheck")) displayOptions->infoCheck->setChecked(settings.value("infoCheck").toBool());
231         if(settings.contains("mapCheck")) displayOptions->mapCheck->setChecked(settings.value("mapCheck").toBool());
232         if(settings.contains("modelCheck")) displayOptions->modelCheck->setChecked(settings.value("modelCheck").toBool());
233         if(settings.contains("samplesCheck")) displayOptions->samplesCheck->setChecked(settings.value("samplesCheck").toBool());
234         if(settings.contains("gridCheck")) displayOptions->gridCheck->setChecked(settings.value("gridCheck").toBool());
235         if(settings.contains("spinZoom")) displayOptions->spinZoom->setValue(settings.value("spinZoom").toFloat());
236         //if(settings.contains("xDimIndex")) displayOptions->xDimIndex->setValue(settings.value("xDimIndex").toInt());
237         //if(settings.contains("yDimIndex")) displayOptions->yDimIndex->setValue(settings.value("yDimIndex").toInt());
238         settings.endGroup();
239
240         settings.beginGroup("drawingOptions");
241         if(settings.contains("infoCheck")) drawToolbarContext1->randCombo->setCurrentIndex(settings.value("infoCheck").toInt());
242         if(settings.contains("spinAngle")) drawToolbarContext2->spinAngle->setValue(settings.value("spinAngle").toFloat());
243         if(settings.contains("spinSize")) drawToolbarContext1->spinSize->setValue(settings.value("spinSize").toFloat());
244         if(settings.contains("spinCount")) drawToolbarContext1->spinCount->setValue(settings.value("spinCount").toFloat());
245         if(settings.contains("spinSigmaX")) drawToolbarContext2->spinSigmaX->setValue(settings.value("spinSigmaX").toFloat());
246         if(settings.contains("spinSigmaY")) drawToolbarContext2->spinSigmaY->setValue(settings.value("spinSigmaY").toFloat());
247         if(settings.contains("spinObsAngle")) drawToolbarContext3->spinAngle->setValue(settings.value("spinObsAngle").toFloat());
248         if(settings.contains("spinObsSigmaX")) drawToolbarContext3->spinSigmaX->setValue(settings.value("spinObsSigmaX").toFloat());
249         if(settings.contains("spinObsSigmaY")) drawToolbarContext3->spinSigmaY->setValue(settings.value("spinObsSigmaY").toFloat());
250         if(settings.contains("spinObsPowerX")) drawToolbarContext3->spinPowerX->setValue(settings.value("spinObsPowerX").toInt());
251         if(settings.contains("spinObsPowerY")) drawToolbarContext3->spinPowerY->setValue(settings.value("spinObsPowerY").toInt());
252         if(settings.contains("spinObsRepulsionX")) drawToolbarContext3->spinRepulsionX->setValue(settings.value("spinObsRepulsionX").toFloat());
253         if(settings.contains("spinObsRepulsionY")) drawToolbarContext3->spinRepulsionY->setValue(settings.value("spinObsRepulsionY").toFloat());
254         if(settings.contains("spinRadius")) drawToolbarContext4->spinRadius->setValue(settings.value("spinRadius").toFloat());
255         if(settings.contains("spinAlpha")) drawToolbarContext4->spinAlpha->setValue(settings.value("spinAlpha").toFloat());
256         if(settings.contains("eraseCheck")) drawToolbar->eraseButton->setChecked(settings.value("eraseCheck").toBool());
257         if(settings.contains("sprayCheck")) drawToolbar->sprayButton->setChecked(settings.value("sprayCheck").toBool());
258         if(settings.contains("singleCheck")) drawToolbar->singleButton->setChecked(settings.value("singleCheck").toBool());
259         if(settings.contains("ellipseCheck")) drawToolbar->ellipseButton->setChecked(settings.value("ellipseCheck").toBool());
260         if(settings.contains("lineCheck")) drawToolbar->lineButton->setChecked(settings.value("lineCheck").toBool());
261         if(settings.contains("trajectoryCheck")) drawToolbar->trajectoryButton->setChecked(settings.value("trajectoryCheck").toBool());
262         if(settings.contains("obstacleCheck")) drawToolbar->obstacleButton->setChecked(settings.value("obstacleCheck").toBool());
263         if(settings.contains("paintCheck")) drawToolbar->paintButton->setChecked(settings.value("paintCheck").toBool());
264         settings.endGroup();
265
266         settings.beginGroup("classificationOptions");
267         if(settings.contains("positiveClass")) optionsClassify->positiveSpin->setValue(settings.value("positiveClass").toFloat());
268         if(settings.contains("foldCount")) optionsClassify->foldCountSpin->setValue(settings.value("foldCount").toFloat());
269         if(settings.contains("trainRatio")) optionsClassify->traintestRatioCombo->setCurrentIndex(settings.value("trainRatio").toInt());
270         if(settings.contains("tab")) optionsClassify->tabWidget->setCurrentIndex(settings.value("tab").toInt());
271         settings.endGroup();
272
273         settings.beginGroup("regressionOptions");
274         if(settings.contains("foldCount")) optionsRegress->foldCountSpin->setValue(settings.value("foldCount").toFloat());
275     if(settings.contains("trainRatio")) optionsRegress->traintestRatioCombo->setCurrentIndex(settings.value("trainRatio").toInt());
276     if(settings.contains("tab")) optionsRegress->tabWidget->setCurrentIndex(settings.value("tab").toInt());
277         settings.endGroup();
278
279         settings.beginGroup("dynamicalOptions");
280         if(settings.contains("centerType")) optionsDynamic->centerCombo->setCurrentIndex(settings.value("centerType").toInt());
281         if(settings.contains("zeroCheck")) optionsDynamic->zeroCheck->setChecked(settings.value("zeroCheck").toBool());
282         if(settings.contains("resampleType")) optionsDynamic->resampleCombo->setCurrentIndex(settings.value("resampleType").toInt());
283         if(settings.contains("resampleCount")) optionsDynamic->resampleSpin->setValue(settings.value("resampleCount").toFloat());
284         if(settings.contains("obstacleType")) optionsDynamic->obstacleCombo->setCurrentIndex(settings.value("obstacleType").toInt());
285         if(settings.contains("dT")) optionsDynamic->dtSpin->setValue(settings.value("dT").toFloat());
286         if(settings.contains("tab")) optionsDynamic->tabWidget->setCurrentIndex(settings.value("tab").toInt());
287         if(settings.contains("colorCheck")) optionsDynamic->colorCheck->setChecked(settings.value("colorCheck").toBool());
288         settings.endGroup();
289
290         settings.beginGroup("compareOptions");
291         if(settings.contains("foldCount")) optionsCompare->foldCountSpin->setValue(settings.value("foldCount").toFloat());
292         if(settings.contains("trainRatio")) optionsCompare->traintestRatioCombo->setCurrentIndex(settings.value("trainRatio").toInt());
293         settings.endGroup();
294
295         settings.beginGroup("clusterOptions");
296         if(settings.contains("tab")) optionsCluster->tabWidget->setCurrentIndex(settings.value("tab").toInt());
297     if(settings.contains("trainRatio")) optionsCluster->trainRatioCombo->setCurrentIndex(settings.value("trainRatio").toInt());
298     if(settings.contains("optimizeCombo")) optionsCluster->optimizeCombo->setCurrentIndex(settings.value("optimizeCombo").toInt());
299     settings.endGroup();
300
301     settings.beginGroup("maximizeOptions");
302     if(settings.contains("tab")) optionsMaximize->tabWidget->setCurrentIndex(settings.value("tab").toInt());
303     if(settings.contains("varianceSpin")) optionsMaximize->varianceSpin->setValue(settings.value("varianceSpin").toDouble());
304     if(settings.contains("iterationsSpin")) optionsMaximize->iterationsSpin->setValue(settings.value("iterationsSpin").toInt());
305     if(settings.contains("stoppingSpin")) optionsMaximize->stoppingSpin->setValue(settings.value("stoppingSpin").toDouble());
306     if(settings.contains("benchmarkCombo")) optionsMaximize->benchmarkCombo->setCurrentIndex(settings.value("benchmarkCombo").toInt());
307     settings.endGroup();
308
309     settings.beginGroup("projectOptions");
310     if(settings.contains("tab")) optionsProject->tabWidget->setCurrentIndex(settings.value("tab").toInt());
311     settings.endGroup();
312
313         settings.beginGroup("statsOptions");
314         if(settings.contains("tab")) showStats->tabWidget->setCurrentIndex(settings.value("tab").toInt());
315         settings.endGroup();
316
317         FOR(i,classifiers.size())
318         {
319                 if(!classifiers[i]) continue;
320                 settings.beginGroup(QString("plugins::classifiers::") + classifiers[i]->GetName());
321                 classifiers[i]->LoadOptions(settings);
322                 settings.endGroup();
323         }
324         FOR(i,clusterers.size())
325         {
326                 if(!clusterers[i]) continue;
327                 settings.beginGroup(QString("plugins::clusterers::") + clusterers[i]->GetName());
328                 clusterers[i]->LoadOptions(settings);
329                 settings.endGroup();
330         }
331         FOR(i,regressors.size())
332         {
333                 if(!regressors[i]) continue;
334                 settings.beginGroup(QString("plugins::regressors::") + regressors[i]->GetName());
335                 regressors[i]->LoadOptions(settings);
336                 settings.endGroup();
337         }
338         FOR(i,dynamicals.size())
339         {
340                 if(!dynamicals[i]) continue;
341                 settings.beginGroup(QString("plugins::dynamicals::") + dynamicals[i]->GetName());
342                 dynamicals[i]->LoadOptions(settings);
343                 settings.endGroup();
344         }
345     FOR(i,maximizers.size())
346     {
347         if(!maximizers[i]) continue;
348         settings.beginGroup(QString("plugins::maximizers::") + maximizers[i]->GetName());
349         maximizers[i]->LoadOptions(settings);
350         settings.endGroup();
351     }
352     FOR(i,projectors.size())
353     {
354         if(!projectors[i]) continue;
355         settings.beginGroup(QString("plugins::projectors::") + projectors[i]->GetName());
356         projectors[i]->LoadOptions(settings);
357         settings.endGroup();
358     }
359     canvas->repaint();
360 }
361
362
363 void MLDemos::SaveParams( QString filename )
364 {
365         if(!classifier && !regressor && !clusterer && !dynamical && !maximizer) return;
366         QFile file(filename);
367         file.open(QFile::WriteOnly | QFile::Append);
368         QTextStream out(&file);
369         if(!file.isOpen()) return;
370
371         if(!canvas->data->GetCount()) out << "0 2\n";
372         char groupName[255];
373
374     if(canvas->dimNames.size())
375     {
376         out << "headers" << " " << canvas->dimNames.size();
377         FOR(i, canvas->dimNames.size())
378         {
379             QString header = canvas->dimNames.at(i);
380             // we take out all spaces as they're really not nice for parsing the headers afterwards
381             header.replace("\n", "_");
382             header.replace(" ", "_");
383             header.replace("\t", "_");
384             out << " " << header;
385         }
386         out << "\n";
387     }
388         if(classifier)
389         {
390                 int tab = optionsClassify->tabWidget->currentIndex();
391                 sprintf(groupName,"classificationOptions");
392                 out << groupName << ":" << "tab" << " " << optionsClassify->tabWidget->currentIndex() << "\n";
393                 out << groupName << ":" << "positiveClass" << " " << optionsClassify->positiveSpin->value() << "\n";
394                 if(tab < classifiers.size() && classifiers[tab])
395                 {
396                         classifiers[tab]->SaveParams(out);
397                 }
398         }
399         if(regressor)
400         {
401                 int tab = optionsRegress->tabWidget->currentIndex();
402                 sprintf(groupName,"regressionOptions");
403         out << groupName << ":" << "tab" << " " << optionsRegress->tabWidget->currentIndex() << "\n";
404         out << groupName << ":" << "outputDimCombo" << " " << optionsRegress->outputDimCombo->currentIndex() << "\n";
405         if(tab < regressors.size() && regressors[tab])
406                 {
407                         regressors[tab]->SaveParams(out);
408                 }
409         }
410         if(dynamical)
411         {
412                 int tab = optionsDynamic->tabWidget->currentIndex();
413                 sprintf(groupName,"dynamicalOptions");
414                 out << groupName << ":" << "centerType" << " " << optionsDynamic->centerCombo->currentIndex() << "\n";
415                 out << groupName << ":" << "zeroCheck" << " " << optionsDynamic->zeroCheck->isChecked() << "\n";
416                 out << groupName << ":" << "resampleType" << " " << optionsDynamic->resampleCombo->currentIndex() << "\n";
417                 out << groupName << ":" << "resampleCount" << " " << optionsDynamic->resampleSpin->value() << "\n";
418                 out << groupName << ":" << "obstacleType" << " " << optionsDynamic->obstacleCombo->currentIndex() << "\n";
419                 out << groupName << ":" << "dT" << " " << optionsDynamic->dtSpin->value() << "\n";
420                 out << groupName << ":" << "colorCheck" << " " << optionsDynamic->colorCheck->isChecked() << "\n";
421                 out << groupName << ":" << "tab" << " " << optionsDynamic->tabWidget->currentIndex() << "\n";
422                 if(tab < dynamicals.size() && dynamicals[tab])
423                 {
424                         dynamicals[tab]->SaveParams(out);
425                 }
426         }
427         if(clusterer)
428         {
429                 int tab = optionsCluster->tabWidget->currentIndex();
430                 sprintf(groupName,"clusterOptions");
431         out << groupName << ":" << "tab" << " " << optionsCluster->tabWidget->currentIndex() << "\n";
432         out << groupName << ":" << "trainRatio" << " " << optionsCluster->trainRatioCombo->currentIndex() << "\n";
433         out << groupName << ":" << "optimizeCombo" << " " << optionsCluster->optimizeCombo->currentIndex() << "\n";
434         if(tab < clusterers.size() && clusterers[tab])
435                 {
436                         clusterers[tab]->SaveParams(out);
437                 }
438         }
439         if(maximizer)
440         {
441                 int tab = optionsMaximize->tabWidget->currentIndex();
442                 double variance = optionsMaximize->varianceSpin->value();
443                 sprintf(groupName,"maximizationOptions");
444                 out << groupName << ":" << "tab" << " " << optionsMaximize->tabWidget->currentIndex() << "\n";
445                 out << groupName << ":" << "gaussVarianceSpin" << " " << optionsMaximize->varianceSpin->value() << "\n";
446                 out << groupName << ":" << "iterationsSpin" << " " << optionsMaximize->iterationsSpin->value() << "\n";
447                 out << groupName << ":" << "stoppingSpin" << " " << optionsMaximize->stoppingSpin->value() << "\n";
448                 out << groupName << ":" << "benchmarkCombo" << " " << optionsMaximize->benchmarkCombo->currentIndex() << "\n";
449                 if(tab < maximizers.size() && maximizers[tab])
450                 {
451                         maximizers[tab]->SaveParams(out);
452                 }
453         }
454     if(projector)
455     {
456         int tab = optionsProject->tabWidget->currentIndex();
457         sprintf(groupName,"projectOptions");
458         out << groupName << ":" << "tab" << " " << optionsProject->tabWidget->currentIndex() << "\n";
459         if(tab < projectors.size() && projectors[tab])
460         {
461             projectors[tab]->SaveParams(out);
462         }
463     }
464 }
465
466 bool startsWith(char *a, char *b)
467 {
468         bool yeah = true;
469         for (int i=0; i<strlen(b); i++)
470         {
471                 yeah &= a[i] == b[i];
472         }
473         return yeah;
474 }
475
476 void MLDemos::LoadParams( QString filename )
477 {
478         QFile file(filename);
479         file.open(QFile::ReadOnly);
480         QTextStream in(&file);
481         if(!file.isOpen()) return;
482
483         int sampleCnt, size;
484         in >> sampleCnt;
485         in >> size;
486         QString line;
487         //char line[255];
488         float value;
489
490         char classGroup[255];
491         char regrGroup[255];
492         char dynGroup[255];
493         char clustGroup[255];
494     char maximGroup[255];
495     char projGroup[255];
496     sprintf(classGroup,"classificationOptions");
497         sprintf(regrGroup,"regressionOptions");
498         sprintf(dynGroup,"dynamicalOptions");
499         sprintf(clustGroup,"clusteringOptions");
500     sprintf(maximGroup,"maximizationOptions");
501     sprintf(projGroup,"projectOptions");
502
503         // we skip the samples themselves
504         qDebug() << "Skipping "<< sampleCnt <<" samples" << endl;
505         FOR(i, sampleCnt) line = in.readLine();
506     bool bClass = false, bRegr = false, bDyn = false, bClust = false, bMaxim = false, bProj = false;
507         qDebug() << "Loading parameter list" << endl;
508         int tab = 0;
509         while(!in.atEnd())
510         {
511                 in >> line;
512         in >> value;
513         //              qDebug() << line << " " << value << endl;
514         if(line.startsWith("headers"))
515         {
516             int headerCount = value;
517             canvas->dimNames.clear();
518             FOR(i, headerCount)
519             {
520                 QString header;
521                 in >> header;
522                 canvas->dimNames << header;
523             }
524             //qDebug() << "dimensions: " << dimensionNames;
525             canvas->dimNames;
526         }
527         if(line.startsWith(classGroup))
528                 {
529                         bClass = true;
530                         algorithmOptions->tabWidget->setCurrentWidget(algorithmOptions->tabClass);
531                         if(line.endsWith("tab")) optionsClassify->tabWidget->setCurrentIndex(tab = (int)value);
532                         if(line.endsWith("positiveClass")) optionsClassify->positiveSpin->setValue((int)value);
533                         if(tab < classifiers.size() && classifiers[tab]) classifiers[tab]->LoadParams(line,value);
534                 }
535                 if(line.startsWith(regrGroup))
536                 {
537                         bRegr = true;
538                         algorithmOptions->tabWidget->setCurrentWidget(algorithmOptions->tabRegr);
539             if(line.endsWith("tab")) optionsRegress->tabWidget->setCurrentIndex(tab = (int)value);
540             if(line.endsWith("outputDimCombo")) optionsRegress->outputDimCombo->setCurrentIndex((int)value);
541             if(tab < regressors.size() && regressors[tab]) regressors[tab]->LoadParams(line,value);
542                 }
543                 if(line.startsWith(dynGroup))
544                 {
545                         bDyn = true;
546                         algorithmOptions->tabWidget->setCurrentWidget(algorithmOptions->tabDyn);
547                         if(line.endsWith("centerType")) optionsDynamic->centerCombo->setCurrentIndex((int)value);
548                         if(line.endsWith("zeroCheck")) optionsDynamic->zeroCheck->setChecked((int)value);
549                         if(line.endsWith("resampleType")) optionsDynamic->resampleCombo->setCurrentIndex((int)value);
550                         if(line.endsWith("resampleCount")) optionsDynamic->resampleSpin->setValue((int)value);
551                         if(line.endsWith("obstacleType")) optionsDynamic->obstacleCombo->setCurrentIndex((int)value);
552                         if(line.endsWith("dT")) optionsDynamic->dtSpin->setValue((float)value);
553                         if(line.endsWith("colorCheck")) optionsDynamic->colorCheck->setChecked((int)value);
554                         if(line.endsWith("tab")) optionsDynamic->tabWidget->setCurrentIndex(tab = (int)value);
555                         if(tab < dynamicals.size() && dynamicals[tab]) dynamicals[tab]->LoadParams(line,value);
556                 }
557                 if(line.startsWith(clustGroup))
558                 {
559                         bClust = true;
560                         algorithmOptions->tabWidget->setCurrentWidget(algorithmOptions->tabClust);
561             if(line.endsWith("tab")) optionsCluster->tabWidget->setCurrentIndex(tab = (int)value);
562             if(line.endsWith("trainRatio")) optionsCluster->trainRatioCombo->setCurrentIndex(tab = (int)value);
563             if(line.endsWith("optimizeCombo")) optionsCluster->optimizeCombo->setCurrentIndex(tab = (int)value);
564             if(tab < clusterers.size() && clusterers[tab]) clusterers[tab]->LoadParams(line,value);
565                 }
566                 if(line.startsWith(maximGroup))
567                 {
568                         bMaxim = true;
569                         algorithmOptions->tabWidget->setCurrentWidget(algorithmOptions->tabMax);
570                         if(line.endsWith("tab")) optionsMaximize->tabWidget->setCurrentIndex(tab = (int)value);
571                         if(line.endsWith("gaussVarianceSpin")) optionsMaximize->varianceSpin->setValue((double)value);
572                         if(line.endsWith("iterationsSpin")) optionsMaximize->iterationsSpin->setValue((int)value);
573                         if(line.endsWith("stoppingSpin")) optionsMaximize->stoppingSpin->setValue((double)value);
574                         if(line.endsWith("benchmarkCombo")) optionsMaximize->benchmarkCombo->setCurrentIndex(tab = (int)value);
575                         if(tab < maximizers.size() && maximizers[tab]) maximizers[tab]->LoadParams(line,value);
576                 }
577         if(line.startsWith(projGroup))
578         {
579             bProj = true;
580             algorithmOptions->tabWidget->setCurrentWidget(algorithmOptions->tabProj);
581             if(line.endsWith("tab")) optionsProject->tabWidget->setCurrentIndex(tab = (int)value);
582             if(tab < projectors.size() && projectors[tab]) projectors[tab]->LoadParams(line,value);
583         }
584         }
585     ResetPositiveClass();
586     ManualSelectionUpdated();
587     InputDimensionsUpdated();
588     if(bClass) Classify();
589         if(bRegr) Regression();
590         if(bDyn) Dynamize();
591         if(bClust) Cluster();
592         if(bMaxim) Maximize();
593     if(bProj) Project();
594     actionAlgorithms->setChecked(algorithmWidget->isVisible());
595 }