-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSMACOFZEIDEL.cpp
More file actions
96 lines (81 loc) · 2.62 KB
/
SMACOFZEIDEL.cpp
File metadata and controls
96 lines (81 loc) · 2.62 KB
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
///////////////////////////////////////////////////////////
// SMACOFZEIDEL.cpp
// Implementation of the Class SMACOFZEIDEL
// Created on: 07-Lie-2013 20:07:32
// Original author: Povilas
///////////////////////////////////////////////////////////
/*! \class SMACOFZEIDEL
\brief A class of methods and attributes for SMACOFZEIDEL algorithm.
*/
#include "SMACOFZEIDEL.h"
#include "ShufleObjects.h"
#include <float.h>
#include <iostream>
#include <cmath>
SMACOFZEIDEL::SMACOFZEIDEL()
{
}
SMACOFZEIDEL::~SMACOFZEIDEL()
{
}
SMACOFZEIDEL::SMACOFZEIDEL(double eps, int maxIter, int d, ShufleEnum shEnum):SMACOF(eps, maxIter, d)
{
shufleEnum = shEnum;
initializeProjectionMatrix();
}
/*SMACOFZEIDEL::SMACOFZEIDEL(ObjectMatrix initProjection, double eps, int maxIter, int d, ShufleEnum shEnum):SMACOF(eps, maxIter, d)
{
shufleEnum = shEnum;
Y = initProjection;
}
SMACOFZEIDEL::SMACOFZEIDEL(double eps, int maxIter, int d, ShufleEnum shEnum, ObjectMatrix initialX):SMACOF(eps, maxIter, d, initialX)
{
shufleEnum = shEnum;
}*/
ObjectMatrix SMACOFZEIDEL::getProjection()
{
stressErrors.reserve(maxIteration);
int i;
int m = X.getObjectCount();
double sum = 0.0;
// str = getStress();
stressErrors.push_back(getStress());
double Epsilon = DBL_MAX;
ObjectMatrix Gutman, Y_new(m);
std::vector<unsigned int> shufledIndexes;
shufledIndexes.reserve(m);
Y_new = Y;
Gutman = getGutman();
int iteration = 0;
DataObject objGutmani;
while (iteration < maxIteration && Epsilon > epsilon)
{
shufledIndexes = ShufleObjects::shufleObjectMatrix(shufleEnum, Y);
for (int row = 0; row < m; row++)
{
i = shufledIndexes.at(row);
objGutmani = Gutman.getObjectAt(i);
for (int j = 0; j < d; j++)
{
sum = 0.0;
for (int k = 0; k < m; k++)
sum += objGutmani.getFeatureAt(k) * Y.getObjectAt(k).getFeatureAt(j);
Y_new.updateDataObject(i, j, (sum / (float) m));
}
Gutman = getGutman(Y_new, i); //change ith row
Y_new.updateDataObjectClass(i, X.getObjectAt(i).getClassLabel());
}
Y = Y_new;
iteration++;
// str = getStress();
stressErrors.push_back(getStress());
Epsilon = std::fabs((stressErrors.at(iteration - 1) - stressErrors.at(iteration)));
// std::cout <<iteration << " " << Epsilon << " " << str << std::endl;
}
Y.setPrintClass(X.getStringClassAttributes());
return Y;
}
/*double SMACOFZEIDEL::getStress()
{
return DimReductionMethod::getStress();
}*/