-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmaPersonality.cpp
More file actions
61 lines (53 loc) · 1.79 KB
/
smaPersonality.cpp
File metadata and controls
61 lines (53 loc) · 1.79 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
#include"smaPersonality.h"
void SMA::setFrameSize(int SIZE_OF_FRAME){
frame_size=SIZE_OF_FRAME;
}
int SMA::getFrameSize(){
return frame_size;
}
void SMA::rescale( float& posSMA, float& negSMA, float& neuSMA){
if(posSMA>0.333333)posSMA=1;
else posSMA=0;
if(negSMA>0.333333)negSMA=1;
else negSMA=0;
if(neuSMA>0.333333)neuSMA=1;
else neuSMA=0;
}
void SMA::calculateSMA(Vector<Mood>& moodLogs, float& posSMA, float& negSMA, float& neuSMA){
int posCount = 0, negCount = 0, neuCount = 0;
int count = min(frame_size, (int)moodLogs.size());
for (int i = moodLogs.size() - count; i < moodLogs.size(); ++i) {
if (moodLogs[i] == _positive_) {
posCount++;
} else if (moodLogs[i] == _negative_) {
negCount++;
} else if (moodLogs[i]== _neutral_) {
neuCount++;
}
}
posSMA = (float)posCount / count;
negSMA = (float)negCount / count;
neuSMA = (float)neuCount / count;
}
Personality SMA::predictPersonality(Vector<Mood> moodLogs){
float posSMA, negSMA, neuSMA;
calculateSMA(moodLogs, posSMA, negSMA, neuSMA);
if(debug)
Serial.printf("Before scaling posSMA:%f neuSMA:%f negSMA:%f \n",posSMA,neuSMA,negSMA);
rescale(posSMA, negSMA, neuSMA);
if(debug)
Serial.printf("After sacling posSMA:%f neuSMA:%f negSMA:%f \n",posSMA,neuSMA,negSMA);
bool p=(bool)posSMA;
bool n=(bool)negSMA;
bool m=(bool)neuSMA;
if(debug){
Serial.println(p);
Serial.println(m);
Serial.println(n);
}
if((!p&!m&!n)||(p&m&n)||(p&!m&n)||(!p&m&!n))return _balanced_;// [111][000][101][010]
else if(p&m&!n)return _creative_;//[110]
else if(p&!m&!n)return _achiever_;//[100]
else if((!p&!m&n)||(!p&m&n)) return _distressed_; //[001][011]
else return _balanced_;
}