-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMMSet.cpp
138 lines (110 loc) · 3.23 KB
/
SMMSet.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
/*
www.mhc-pathway.net/smm
Original file by Bjoern Peters.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "stdafx.h"
#include "SMMSet.h"
CSMMSet::CSMMSet(void)
{
}
CSMMSet::~CSMMSet(void)
{
}
void CSMMSet::CreateMaskedSet(const CSMMSet &source, const UIntVec &mask)
{
CDataset::operator=(source);
const unsigned M=source.ElementNumber();
const unsigned N=mask.size();
m_A.resize(M,N);
for(unsigned m=0; m<M; m++)
for(unsigned n=0; n<N; n++)
m_A(m,n)=source.m_A(m,mask[n]);
}
void CSMMSet::CreateSubset(const CSMMSet &source, const UIntVec &members)
{
CDataset::CreateSubset(source,members);
const unsigned M=members.size();
const unsigned N=source.MatrixCols();
m_A.resize(M,N);
for(unsigned m=0; m<M; m++)
for(unsigned n=0; n<N; n++)
m_A(m,n)=source.m_A(members[m],n);
}
void CSMMSet::AddSet(const CSMMSet &source)
{
assert(m_A.NumCols()==source.m_A.NumCols());
CDataset::AddSet(source);
const unsigned N=m_A.NumCols();
const unsigned M1=m_A.NumRows();
const unsigned M2=source.m_A.NumRows();
const CNumMat A=m_A;
m_A.resize(M1+M2,source.m_A.NumCols());
for(unsigned m=0; m<M1; m++)
for(unsigned n=0; n<N; n++)
m_A(m,n)=A(m,n);
for(unsigned m=0; m<M2; m++)
for(unsigned n=0; n<N; n++)
m_A(m+M1,n)=source.m_A(m,n);
}
void CSMMSet::Predict(const CNumVec &x)
{
m_predictions.SetToProduct(m_A,x);
}
double CSMMSet::XDistance(const CNumVec &x)
{
assert(x.size()==MatrixCols());
m_predictions.SetToProduct(m_A,x);
m_difference=GetPredictions();
m_difference-=GetMeasurements();
if(InequalitiesPresent())
{
for(unsigned m=0; m<m_difference.size(); m++)
{
if(m_inequalities[m]!=EQUAL)
{
if(m_inequalities[m]==GREATER)
{
if(m_difference[m]>0)
m_difference[m]=0;
}
else if(m_difference[m]<0)
m_difference[m]=0;
}
}
}
return(m_difference.ScalarProduct(m_difference));
}
double CSMMSet::XGradient(const CNumVec &x,CNumVec &ddistdx)
{
double dist=XDistance(x);
ddistdx.SetToProduct(m_A,m_difference,true);
return(dist);
}
/*
// Only member of CV SMMSet:
void CVSMMSet::CreateMaskedCopy(const CVSMMSet &source, const UIntVec &mask)
{
unsigned subnum=source.SubsetNum();
m_train.resize(subnum);
m_blind.resize(subnum);
for(unsigned s=0; s<subnum; s++)
{
m_train[s].CreateMaskedSet(source.m_train[s],mask);
m_blind[s].CreateMaskedSet(source.m_blind[s],mask);
}
}
*/