-
Notifications
You must be signed in to change notification settings - Fork 28
/
CDataModel.h
129 lines (122 loc) · 2.96 KB
/
CDataModel.h
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
/* Interfaces classes for data sets and mapping models. Long term these classes are expected to be extended. An early set of extensions was rolled back to incorporate William V. Baxter's port to MSVC.*/
#ifndef CDATAMODEL_H
#define CDATAMODEL_H
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>
#include "ndlexceptions.h"
#include "ndlstrutil.h"
#include "CNdlInterfaces.h"
#include "CMatrix.h"
// a model of a data set.
class CDataModel
{
public:
// Initialise the model.
CDataModel() {
_init();
}
virtual ~CDataModel() {}
CDataModel(unsigned int nData) : numData(nData) {}
inline string getType() const
{
return type;
}
// Set a string representing the model type.
inline void setType(const string name)
{
type = name;
}
inline string getBaseType() const
{
return baseType;
}
// Set a string representing the model type.
inline void setBaseType(const string name)
{
baseType = name;
}
// Get the long name of the model.
inline string getName() const
{
return modelName;
}
// Set the long name of the model.
inline void setName(const string name)
{
modelName = name;
}
virtual unsigned int getOptNumParams() const=0;
virtual void display(ostream& os) const=0;
virtual inline unsigned int getNumData() const
{
return numData;
}
virtual inline void setNumData(unsigned int val)
{
numData = val;
}
private:
void _init()
{
setBaseType("dataModel");
}
string baseType;
string type;
string modelName;
unsigned int numData;
};
// a model which maps from one data space to another.
class CMapModel : public CDataModel
{
public:
CMapModel() : CDataModel()
{
_init();
}
CMapModel(unsigned int inDim, unsigned int outDim, unsigned int nData) : inputDim(inDim), outputDim(outDim), CDataModel(nData)
{
_init();
}
// map from an input to an output.
virtual void out(CMatrix& yPred, const CMatrix& inData) const=0;
// compute gradient with respect to parameters of an output.
virtual double outGradParams(CMatrix& g, const CMatrix& Xin, unsigned int pointNo, unsigned int outputNo) const=0;
virtual double outGradX(CMatrix& g, const CMatrix& Xin, unsigned int pointNo, unsigned int outputNo) const=0;
// Set the input dimension.
inline void setInputDim(unsigned int dim)
{
inputDim = dim;
}
// Get the input dimension.
inline unsigned int getInputDim() const
{
return inputDim;
}
// Set the output dimension.
inline void setOutputDim(unsigned int dim)
{
outputDim = dim;
}
// Get the output dimension.
inline unsigned int getOutputDim() const
{
return outputDim;
}
private:
void _init()
{
setBaseType("mapModel");
}
unsigned int outputDim;
unsigned int inputDim;
string modelName;
string type;
};
void writeMapModelToStream(const CMapModel& model, ostream& out);
CMapModel* readMapModelFromStream(istream& in);
#endif