-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoryModule.m
80 lines (64 loc) · 2.24 KB
/
MemoryModule.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
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
classdef (Abstract) MemoryModule < handle
% Abstract memory module class
%
% patterns are stored as nU x nP
% weight matrix is nU x nU
properties
FLAG_keepTrackOfPatterns = true;
P % stored patterns [nU x nP]
M % weight matrix [nU x nU]
tau=0; % baseweight when adding patterns
end
methods
function z = myName(~), z = 'MemoryModuleAbstract'; end
% constructor
function self = MemoryModule(nU)
self.M = zeros(nU, nU);
self.P = [];
end
% get parms
function z = nU(self), z = size(self.M,1); end
function z = nP(self), z = size(self.P,2); end
% functions we can define here
function AddPatterns(self, P0, alpha)
if nargin == 2, alpha = 1; end
for iP = 1:size(P0,2)
self.AddOnePattern(P0(:,iP), alpha);
end
end
% baseline matrices
function InitializeMatrix(self, z)
if nargin==2 && ischar(z) || isstring(z)
Z = load(z);
assert(Z.nU == self.nU, 'stored nUnits [%d] is not the same as current nUnits [%d]', Z.nU, self.nU);
self.M = Z.M0(randi(length(Z.M0), self.nU, self.nU));
else
self.myInitializeMatrix(z);
end
end
function myInitializeMatrix(self, ~)
self.M = zeros(nU, nU);
end
end
methods (Abstract)
AddOnePattern(self, P0, alpha)
X = Recall(self, X)
end
methods (Static, Abstract)
P = MakePatterns(nP, nU)
P = AddNoise(nP, nU, eta)
S = PatternSimilarity(P0,P1);
end
methods (Static)
function SaveBaselineMatrix(constructor, nP, nU)
% call with @constructor, nP, nU
H = constructor(nU);
fn = sprintf('%s-BaselineStore.mat', H.myName);
P = H.MakePatterns(nP, nU);
H.AddPatterns(P);
M0 = H.M(:);
save(fn, 'M0', 'nU', 'nP');
fprintf('Wrote M0 with %d patterns and %d units to %s.\n', nP, nU, fn);
end
end
end