-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoopFlexFingerNeuralPredictor.m
More file actions
103 lines (82 loc) · 6.17 KB
/
LoopFlexFingerNeuralPredictor.m
File metadata and controls
103 lines (82 loc) · 6.17 KB
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] = LoopFlexFingerNeuralPredictor(X,~,~)
%LOOPFLEXFINGERNEURALPREDICTOR neural network simulation function.
%
% Auto-generated by MATLAB, 25-Mar-2022 15:15:43.
%
% [Y] = LoopFlexFingerNeuralPredictor(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.891601639905516663;4.0479216095831391797;4.633088065659513255;-3.5986818915679923414;3.5888409880328535628;-11.486345359597480709;0.97404787780805135444;4.2129585627563876926;-3.697819195678922366;1.1573430237185238223;4.0171636216259054564;-0.66641672959363118522;-2.8017367582182570729;-0.66980184068549331045;0.33213086052324131137;1.3096762914347161999;0.31232414405873731855;-0.1412697410869555581;-3.705186838666767013;3.2697718572610172671;2.7540365139328124577;6.0880065330979995508;5.6663500480193045306;6.6036428373890938559;-3.7157077343987126028];
IW1_1 = [1.6830569989487149662 0.77267109165838554485 1.2252236928141904126;-0.15698552467012585887 -0.2693870364947825724 -1.7102977068639217961;-1.3579216549944963521 -1.5674614461424503098 -3.2864923574927109584;1.0461676647380859784 4.1342831834843156713 0.79358986403156184242;-1.0506395134999657603 -4.1283777050225856087 -0.7750122753049712987;1.9874916536632072361 2.1365734286518196505 -6.8250603974176433653;5.2995388024227043644 -2.4723443171062142731 -1.8915852354536992763;-0.42951812005484357737 -1.0460777792493693994 3.1961540362219640343;0.094768584859157858902 -6.1027029468216271724 -1.6329447788556270549;-0.39771943220113453732 0.87892313145098821536 4.2775163912910745267;-0.55971665252131708179 -0.9427557293040655928 3.4335189872964693159;-4.5500051008791757567 2.8050525900066340945 1.398014771490002417;0.47667563799784373746 3.1934103783781564445 0.11407817185807510307;-4.555440747996464701 2.7988939462625221921 1.4038245686477055507;0.45743248989482970801 -1.9188042301245833432 -2.2460681514195153241;-0.32144222232529778838 -2.5518836934142825612 3.4805949442602144295;0.05001962335972642143 1.6356623448264833165 -1.9773357174818428916;4.4776142748808061 0.62199738237680990416 3.2154027155988180731;-0.48091962266621263167 1.1613553390184971903 -0.77198914759366132898;1.1130839682277462455 -2.825322416405180892 -2.9752657834186746477;-0.15155853441310307428 -4.0947142560514224741 2.1607296204359514036;0.19006637476703092116 -1.7385962222410276112 4.6666282722735488164;-0.36721237222123936927 -1.4001109811544705241 4.2668015526910689772;1.0714366531349683864 -0.53929809550937046758 2.1023382753202333184;0.05910568564049702156 -2.54781993402892315 4.0691084016644634147];
% Layer 2
b2 = [1.8652373115516500679;-0.32104329380939383709;1.4197640467753445126];
LW2_1 = [-1.3984321780804980229 -1.1335434976493525827 0.018763837771108470703 -1.3885255810122449915 -1.3564993409039451944 2.5924008535047136093 -0.01030900005469164056 -3.1415155161518630855 -0.01653182744404698909 0.0035573794922884116945 0.58099535012376923859 0.99479468611983457027 0.057350770444890446231 -1.0047501420333273536 -0.0010808093041212360735 -0.031189147505496558205 0.037133289916191268565 0.00037878350342759414902 0.43334611180327309299 -0.0038750518203607671811 0.033244790754389554055 -0.15136675000927468648 2.3317227026490203734 0.33412963774114445847 -0.008665328216916269588;0.6797724627118131302 -0.57860987858332579847 -0.0064597847181858281812 0.52183087444078668504 0.5199338217166140641 -2.9084454502077954352 0.0091266796992194292731 1.7475717830640151718 0.00016507056641335595944 0.001996120681025912412 -0.35078415450592564939 -0.78261223503021215553 -0.0096574656734234824024 0.791244163066942785 -0.0022598816116610027059 0.011108279393217842385 -0.0091101659652197842371 -1.5546857614211939447e-05 -0.37325827926975890803 -0.00139564260773197878 -0.0080244083895127729655 0.027245671511762648703 -1.0897005059504258906 -1.0645548904669532853 0.0019291173399567085583;-1.7642201739286373918 -0.84268943823422015615 0.012580995866196246005 -1.0322097923549065079 -1.0096577332209744071 2.7801161176389381779 -0.0081572056478546439012 -2.4765370933313275437 -0.011867527002344831905 0.0023696443196882365639 0.46416263312114974804 0.78037184836694695189 0.040639144036934284065 -0.78822582367232674194 -0.00063814144255494923124 -0.022957222015760000294 0.026624713876920468036 0.00026282378175349979882 0.34418809488389157103 -0.0026765593144619250453 0.02395482273992071906 -0.10190233793989654509 1.7732303997225717929 0.16710343932495300145 -0.0060556421616297017793];
% Output 1
y1_step1.ymin = -1;
y1_step1.gain = [0.021704937921319;0.0214050249475353;0.0154778227261563];
y1_step1.xoffset = [5.201559128;-92.69357154;5.201746502];
% ===== 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