-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLearner.cpp
48 lines (34 loc) · 1.2 KB
/
Learner.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
#include "Learner.h"
#define STOCHASTIC_TOLERANCE 0.00001
#pragma mark - Constructor and Destructor
Learner::Learner(int numParams, vector<SupervisedData*> data, float learningRate) {
/* You can initialize a Learner with no data, but you should pass an empty vector rather than NULL. The training examples should be stored OUTSIDE of the class. */
_learningRate = learningRate;
_data = data;
// Initialize x_{i} values to the zero vector
_M = numParams;
_parameterValues = (double*)malloc(sizeof(double) * _M);
for (int i = 0; i < _M; i++)
_parameterValues[i] = 0;
_hypothesis = NULL;
}
Learner::Learner(int numParams, vector<SupervisedData*> data, float learningRate, float (*hypothesis)(float y)) {
_learningRate = learningRate;
_data = data;
// Initialize x_{i} values to the zero vector
_M = numParams;
_parameterValues = (double*)malloc(sizeof(double) * _M);
for (int i = 0; i < _M; i++)
_parameterValues[i] = 0;
_hypothesis = hypothesis;
}
Learner::~Learner() {
delete _parameterValues;
}
#pragma mark - Public Functions
int Learner::numParams() {
return _M;
}
double* Learner::params() {
return _parameterValues;
}