-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCG_Learning.m
77 lines (30 loc) · 1.61 KB
/
CG_Learning.m
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
classdef CG_Learning < handle
% Purpose: do CG learning
% Input: gainParameter, previous estimates of params,
% moments matrix, new data point
% Output: parameter estimates, new value of variable
properties
% things we need to instatiate the class
gainParameter; % constant gain parameter
previousParameters; % estimate of previous parameters
D_Matrix; % moments matrix for estimation
zMat; % variables that are used for estimation
variable; % that is the previous value of variable we are estimating
end
methods
function obj = CG_Learning(gainParam,previousParameters,D_Matrix,zMat,variable)
% class constructor
obj.gainParameter = gainParam;
obj.previousParameters = previousParameters;
obj.D_Matrix = D_Matrix;
obj.zMat = zMat;
obj.variable = variable;
end
function [ paramsOut, D_Out] = do_CG_Learning(obj)
% estimate parameters using CG
paramsOut = obj.previousParameters + obj.gainParameter * inv(obj.D_Matrix)*obj.zMat *( obj.variable - obj.previousParameters' * obj.zMat );
% update moments matrix
D_Out = obj.D_Matrix + obj.gainParameter * (obj.zMat * obj.zMat' - obj.D_Matrix);
end
end
end