-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFestoFingerNeuralPredictor.m
103 lines (82 loc) · 6.17 KB
/
FestoFingerNeuralPredictor.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
93
94
95
96
97
98
99
100
101
102
103
function [Y,Xf,Af] = FestoFingerNeuralPredictor(X,~,~)
%FESTOFINGERNEURALPREDICTOR neural network simulation function.
%
% Auto-generated by MATLAB, 25-Mar-2022 15:15:42.
%
% [Y] = FestoFingerNeuralPredictor(X,~,~) takes these arguments:
%
% X = 1xTS cell, 1 inputs over TS timesteps
% Each X{1,ts} = 3xQ matrix, input #1 at timestep ts.
%
% and returns:
% Y = 1xTS cell of 1 outputs over TS timesteps.
% Each Y{1,ts} = 3xQ matrix, output #1 at timestep ts.
%
% where Q is number of samples (or series) and TS is the number of timesteps.
%#ok<*RPMT0>
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1.xoffset = [0.0127;0.008;0.047];
x1_step1.gain = [78.7401574803149;200;50];
x1_step1.ymin = -1;
% Layer 1
b1 = [6.9146063926383609655;-4.9794805886495874248;-3.9905239824277511929;-2.4686014237164322083;8.8840080144993880396;-3.1736007368442598064;2.2847209750521382254;3.1803160304087496613;-3.3797240180646612728;2.6861962167859352313;1.5395016002574737346;-2.3686127441459370324;-0.57248585067335688858;0.98895111559563331216;-1.864156555434622442;-1.8910686352693486523;0.48253942967473234527;0.013816053603352237977;-4.9514864329462939807;1.9801787977447136146;-4.3687383482767634391;-5.2702631187947392988;5.5571130601825320383;-3.7097079553110683392;5.6496639002674893248];
IW1_1 = [-0.47243375059924030968 -2.1239836399324629745 3.534123481002097833;3.1256193547630868323 2.4138971693542461416 -1.86845844791103044;0.76665451058646105764 -3.9187437425428486293 1.2095130887774478978;1.3997610839529674998 -3.051135915042593183 4.5341130407682097569;-1.9493254423359682725 -1.9612330122426120393 4.3290802361253168939;1.3346997227787400497 -3.1214225606631331722 -0.70418810163440326289;-0.021465881240261761032 -0.96044633006203450343 3.2597359520653417242;-1.8993813501411935807 -1.7769319505961187478 -2.8288969224834530358;0.07754460525966830331 -2.0497037703974654299 -0.36452170124158728148;-0.48880328503152042918 2.5452147493646375409 -1.7923579151684643218;-1.1222633044973666649 1.7414521688948136902 -2.4250040813870072931;3.4855698112687232282 2.6192264098994577637 0.18325510901705846512;1.390801074706887519 4.9238891675619882449 -1.4572501718959232075;2.7281530704760150741 2.3970336936615255219 1.5463879673275990889;1.8212612614035195158 -4.6040182025417690781 -0.85578752374891864374;0.14614526928926252491 -0.51502646951979469403 -3.9266696650372545641;-1.1991611518495581823 2.4186573811597447126 -6.0719504279860192497;0.63151303473514353026 1.2834012754164976222 -4.7832495476550160873;0.61695823218997070114 1.8033075992839404655 -3.9597083476144114833;-0.033546278087281770908 -1.1804804483762698641 -4.4173639220577083364;-0.80935537804092660963 -0.23127892025061594361 3.3861172744960930103;0.45946237984095944507 1.0451274764149447449 -3.4825389975835854273;2.5113804407893263182 0.12359095852018404937 -2.5177795215686598063;-0.64931945735394780428 -0.60493262367483413566 3.4287302304202658121;0.020753453878590608084 1.9577744397062739612 0.58886654273916827496];
% Layer 2
b2 = [0.76853880232745830359;-0.9792656928545034889;0.64150397889845267585];
LW2_1 = [0.97065624708216402539 0.046424839959773728237 0.16467055708921865542 0.08735985547614315283 -2.2972966185049088494 0.012617889029453807637 -0.35796704031752307751 0.019114961147475927061 -0.15279892536546471615 0.27448839650985268346 0.10137938581602047583 0.020515046394223704351 0.02236110900616410796 -0.0014647777941162885753 0.025191478752528268653 -0.28396190590934555775 0.0047506248407885509275 0.073589755462244194062 0.16567939901128947433 -0.29617208838408898286 0.75100181236251928318 0.5384894818329777344 -0.50820089432570725307 -0.81587936354459200672 1.1369664134125778698;-2.2458245007805666127 -0.0037056791873140387632 -0.054063972735398875546 -0.02200641041410791518 2.5315559287251088172 -0.0093951818836732516049 0.027763043620612288392 0.018992966153367700499 0.29685997930394630862 -0.044752666422856357542 -0.025427538261427511113 0.00044952472573676785592 -0.015673937922055312943 0.0051552399629869365486 -0.0065229972826720949292 -0.033704210029940534499 -0.017907176553066464497 0.0030290782110443934851 0.013106738662652420505 -0.12730994816021914962 -0.10878507147581908954 -1.9034488591306237826 -0.49573050335190727012 -0.24099644246022511318 0.094376598499674807519;1.1813211370477176843 0.036952694070258529369 0.12919176557799588734 0.071454615234487373066 -2.5296278054203904517 0.010232444319505071967 -0.28474039176402166085 0.015485650869775244992 -0.13300602961682755909 0.21535032637306375514 0.082840969864134417211 0.015999154250652975612 0.018645213811035662999 -0.0014853577301211339911 0.020132888494408970187 -0.22170869059840669912 0.0033813267058358923746 0.057921050651713691659 0.12190550504837560641 -0.23906230418998938858 0.61892701692204654673 0.78507412531036224745 -0.43234207335704899489 -0.67657148596259719664 1.328242391536433642];
% Output 1
y1_step1.ymin = -1;
y1_step1.gain = [0.036795121498829;0.041427132803829;0.0292035589710718];
y1_step1.xoffset = [8.561669037;-44.48184834;8.568077529];
% ===== SIMULATION ========
% Format Input Arguments
isCellX = iscell(X);
if ~isCellX
X = {X};
end
% Dimensions
TS = size(X,2); % timesteps
if ~isempty(X)
Q = size(X{1},2); % samples/series
else
Q = 0;
end
% Allocate Outputs
Y = cell(1,TS);
% Time loop
for ts=1:TS
% Input 1
Xp1 = mapminmax_apply(X{1,ts},x1_step1);
% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*Xp1);
% Layer 2
a2 = repmat(b2,1,Q) + LW2_1*a1;
% Output 1
Y{1,ts} = mapminmax_reverse(a2,y1_step1);
end
% Final Delay States
Xf = cell(1,0);
Af = cell(2,0);
% Format Output Arguments
if ~isCellX
Y = cell2mat(Y);
end
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end
% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end
% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end