-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasisfunctionactivations.m
92 lines (78 loc) · 2.51 KB
/
basisfunctionactivations.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
81
82
83
84
85
86
87
88
89
90
91
92
function activations = basisfunctionactivations(centers,widths,xs)
% Compute basis activations for 1 or more time steps
%
% Input:
% centers - centers of the basis functions
% widths - widths of the basis functions
% xs - if scalar: current phase (or time)
% if vector: sequence of phases (or time)
% Output:
% activations - activations of the basis functions at each time step
if (nargin==0)
% If no arguments are passed, test the function
activations = testbasisfunctionactivations;
return;
end
n_basis_functions = length(centers);
activations = zeros(length(xs),n_basis_functions);
for bb=1:n_basis_functions
activations(:,bb) = exp((-0.5/(widths(bb).^2)) * (xs - centers(bb)).^2);
end
%-------------------------------------------------------------------------------
function activations = testbasisfunctionactivations
clf
time = 2;
time_exec = 2.5;
dt = 1/50;
% Get time and phase vector
order = 1;
[ts xs xds vs vds alpha] = canonicalintegrate(time,dt,time_exec,order); %#ok<NASGU>
N = ceil(1+time_exec/dt); % Number of time steps
ts = dt*(0:N-1)';
n_basis_functions = 10;
for time_instead_of_phase=0:1
if (time_instead_of_phase)
ps = ts;
[centers widths] = basisfunctioncenters(n_basis_functions,time);
else
ps = xs;
[centers widths] = basisfunctioncenters(n_basis_functions,time,alpha);
end
% Get activations
activations = basisfunctionactivations(centers,widths,ps);
subplot(2,5,1+time_instead_of_phase*5)
plot(ts,activations')
xlabel('t (s)')
ylabel('activations')
axis tight
if (time_instead_of_phase)
title('In time space')
else
title('In phase space')
end
ylim([0 1.1])
for order = 0:3
if (order==0)
% 'Fake' the canonical system (not used for order 0)
vs = ones(size(ts));
else
[ts xs xds vs vds] = canonicalintegrate(time,dt,time_exec,order); %#ok<NASGU>
end
% Plot basis functions, multiplied with canonical system
subplot(2,5,2+order+time_instead_of_phase*5)
plot(ts,repmat(vs,1,n_basis_functions).*activations)
hold on
plot(ts,vs,'-k','LineWidth',2)
hold off
xlabel('t (s)')
ylabel('activation * v')
axis tight
labels = {'No canonical','1st order','2nd order','sigmoid'};
title(labels{order+1})
if (order~=2)
ylim([0 1.1])
end
end
end
end
end