- added multiple format support for input data (now supports csv, tabs, ; and spaces)
[mldemos:baraks-mldemos.git] / _AlgorithmsPlugins / Projections / interfacePCAProjection.cpp
1 #include "interfacePCAProjection.h"
2 #include "projectorPCA.h"
3
4 PCAProjection::PCAProjection()
5     : widget(new QWidget())
6 {
7     params = new Ui::paramsPCA();
8     params->setupUi(widget);
9 }
10
11
12 // virtual functions to manage the algorithm creation
13 Projector *PCAProjection::GetProjector()
14 {
15     return new ProjectorPCA();
16 }
17
18 void PCAProjection::DrawInfo(Canvas *canvas, QPainter &painter, Projector *projector)
19 {
20     if(!canvas || !projector) return;
21     ProjectorPCA *pca = (ProjectorPCA*)projector;
22     QPixmap pixmap(params->eigenGraph->width(), params->eigenGraph->height());
23     QBitmap bitmap(pixmap.width(), pixmap.height());
24     bitmap.clear();
25     pixmap.setMask(bitmap);
26     pixmap.fill(Qt::transparent);
27     QPainter eigenPainter(&pixmap);
28     pca->DrawEigenvals(eigenPainter);
29     params->eigenGraph->setPixmap(pixmap);
30
31     params->eigenList->clear();
32     fvec values = pca->GetEigenValues();
33     float accumulator = 0;
34     float maxEigVal = 0;
35     FOR(i, values.size()) if(values[i] == values[i] && values[i] >= 0) maxEigVal += values[i];
36
37     FOR(i, values.size())
38     {
39         float eigval = values[i];
40         if(eigval == eigval && eigval >= 0)
41         {
42             accumulator += eigval / maxEigVal;
43         }
44         else eigval = 0;
45         params->eigenList->addItem(QString("e%1 %2 %3%%").arg(i).arg(eigval, 0, 'f', 2).arg(accumulator*100, 0, 'f', 1));
46     }
47 }
48
49 void PCAProjection::DrawModel(Canvas *canvas, QPainter &painter, Projector *projector)
50 {
51     if(!canvas || !projector) return;
52 }
53
54 // virtual functions to manage the GUI and I/O
55 QString PCAProjection::GetAlgoString()
56 {
57     return QString("PCA");
58 }
59
60 void PCAProjection::SetParams(Projector *projector)
61 {
62     if(!projector) return;
63     if(params->useRangeCheck->isChecked())
64     {
65         int startIndex = params->startRangeSpin->value()-1;
66         int stopIndex = params->stopRangeSpin->value()-1;
67         projector->startIndex = min(startIndex, stopIndex);
68         projector->stopIndex = max(startIndex, stopIndex);
69     }
70     else
71     {
72         projector->startIndex = 0;
73         projector->stopIndex = -1;
74     }
75 }
76
77 void PCAProjection::SaveOptions(QSettings &settings)
78 {
79     //settings.setValue("kernelCluster", params->kernelClusterSpin->value());
80 }
81
82 bool PCAProjection::LoadOptions(QSettings &settings)
83 {
84     //if(settings.contains("kernelCluster")) params->kernelClusterSpin->setValue(settings.value("kernelCluster").toFloat());
85     return true;
86 }
87
88 void PCAProjection::SaveParams(QTextStream &file)
89 {
90     //file << "clusterOptions" << ":" << "kernelCluster" << " " << params->kernelClusterSpin->value() << "\n";
91 }
92
93 bool PCAProjection::LoadParams(QString name, float value)
94 {
95     //if(name.endsWith("kernelCluster")) params->kernelClusterSpin->setValue((int)value);
96     return true;
97 }