Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running SecondOrder example during setup #27

Merged
merged 6 commits into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Examples/SecondOrder/container.mat
Binary file not shown.
85 changes: 85 additions & 0 deletions Examples/SecondOrder/run_example.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
%% ==========Moving to the example folder==========


[str,~,~] = fileparts(mfilename('fullpath'));
oldFolder=cd(str);

%% ==========Reference data settings==========

% Create a RaPIdObject (optional but recommended - will work with just a structure)
RaPIdObject=RaPIdClass();

%Output data
RaPIdObject.experimentData.pathToReferenceData = 'measuredDataO.mat'; %Data file name
RaPIdObject.experimentData.expressionReferenceTime = 'time'; %Time variable name
RaPIdObject.experimentData.expressionReferenceData = 'signal'; %Data variable name

%Input data
RaPIdObject.experimentData.pathToInData = '';

%% ==========Experiment settings==========

%General settings
RaPIdObject.experimentSettings.tf = 50; %Simulation length
RaPIdObject.experimentSettings.ts = 0.01; %Sampling time
RaPIdObject.experimentSettings.t_fitness_start = 4; %Start calculating fintess function after t_fintess_start
RaPIdObject.experimentSettings.timeOut = 2; %Seconds before simulation timeout
RaPIdObject.experimentSettings.integrationMethod = 'ode45'; %Solver selection
RaPIdObject.experimentSettings.solverMode = 'Simulink';
RaPIdObject.experimentSettings.optimizationAlgorithm = 'pso'; %Selection of optimization algorithm
RaPIdObject.experimentSettings.maxIterations = 100; %Maximum number of estimation iterations
RaPIdObject.experimentSettings.verbose = 1; %Can trigger more data for debugging
RaPIdObject.experimentSettings.saveHist = 0; %Don't save history

%Model related settings
RaPIdObject.experimentSettings.pathToSimulinkModel = 'variable_rafael.mdl'; %Simulink model file name
RaPIdObject.experimentSettings.pathToFMUModel = 'Rafael_0original_0estimated.fmu'; %FMU file name
RaPIdObject.experimentSettings.modelName = 'variable_rafael'; %Simulink model name
RaPIdObject.experimentSettings.blockName = 'variable_rafael/Rafael_original_estimated'; %FMU name
RaPIdObject.experimentSettings.scopeName = 'simout'; %Result sink name
RaPIdObject.experimentSettings.displayMode = 'Show';

%Estimation parameter settings
RaPIdObject.experimentSettings.p_0 = [0.3, 4.1, 1.7, 1.1]; %Initial parameter guess
RaPIdObject.experimentSettings.p_min = [0.1, 3.9, 1.5, 1.1]; %Minimum values of parameters
RaPIdObject.experimentSettings.p_max = [1, 4.2, 1.7, 1.5]; %Maximum values of parameters

%Fitness function settings
RaPIdObject.experimentSettings.cost_type = 1; %Fitness function selection
RaPIdObject.experimentSettings.objective_weights = 1; %Weights of the output signals for fitness function

%% ==========Optimization Algorithm settings==========

switch RaPIdObject.experimentSettings.optimizationAlgorithm
case 'pso'
RaPIdObject.psoSettings.w = 0.25; %Particle inertia weight
RaPIdObject.psoSettings.self_coeff = 0.25; %Self recognition coefficient
RaPIdObject.psoSettings.social_coeff = 0.25; %Social coefficient
RaPIdObject.psoSettings.limit = 0.25; %Iteration limit
RaPIdObject.psoSettings.nRandMin = 8; %Minimum number of random particles
RaPIdObject.psoSettings.nb_particles = 8; %Number of particles
RaPIdObject.psoSettings.fitnessStopRatio = 1e-5; %Fitness stop ratio
RaPIdObject.psoSettings.kick_multiplier = 0.002; %Kick multiplier
RaPIdObject.psoSettings.method = 'PSO';
end

%% ==========FMU parameters, inputs and outputs==========

RaPIdObject.parameterNames = {'transferFunction.b[1]','transferFunction.a[1]','transferFunction.a[2]','transferFunction.a[3]'};
RaPIdObject.fmuInputNames = {};
RaPIdObject.fmuOutputNames = {'y1'}; %Output variable names

%% ==========Running the computation==========

%Opening simulink model
open_system(RaPIdObject.experimentSettings.pathToSimulinkModel); %Opening the simulink model
open_system(strcat(RaPIdObject.experimentSettings.modelName,'/Scope')); %Opening the scope in the model to observe estimation process
pause(1); %Waiting one second for scope to initialize
%%

%Starting the estimation process
[sol, hist] = rapid(RaPIdObject);
sprintf('Vector of estimated parameters is: %s',mat2str(sol,3))
%Restoring workspace
cd(oldFolder);

40 changes: 20 additions & 20 deletions Examples/SecondOrder/variable_rafael.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Model {
NumRootInports 0
NumRootOutports 0
ParameterArgumentNames ""
ComputedModelVersion "1.22"
ComputedModelVersion "1.24"
NumModelReferences 0
NumTestPointedSignals 0
}
Expand Down Expand Up @@ -39,7 +39,7 @@ Model {
DockPosition "Left"
Width [50]
Height [50]
Filter [8]
Filter [9]
}
Object {
$PropName "ExplorerBarInfo"
Expand All @@ -56,7 +56,7 @@ Model {
LoadSaveID "0"
Extents [1512.0, 869.0]
ZoomFactor [3.5635593220338988]
Offset [-2.1474435196194435, 50.071343638525562]
Offset [-2.1474435196194577, 50.071343638525548]
}
}
}
Expand All @@ -66,9 +66,9 @@ Model {
ModifiedByFormat "%<Auto>"
LastModifiedBy "Tin Rabuzin"
ModifiedDateFormat "%<Auto>"
LastModifiedDate "Fri Feb 19 15:13:42 2016"
RTWModifiedTimeStamp 377795587
ModelVersionFormat "1.%<AutoIncrement:22>"
LastModifiedDate "Tue Feb 23 09:54:14 2016"
RTWModifiedTimeStamp 378122050
ModelVersionFormat "1.%<AutoIncrement:24>"
ConfigurationManager "None"
SampleTimeColors off
SampleTimeAnnotations off
Expand Down Expand Up @@ -850,21 +850,21 @@ Model {
Position [310, 207, 350, 263]
ZOrder -3
Floating off
Location [207, 743, 907, 1016]
Open on
Location [389, 469, 1296, 987]
Open off
NumInputPorts "1"
List {
ListType AxesTitles
axes1 "%<SignalLabel>"
}
List {
ListType ScopeGraphics
FigureColor "[0.501960784313725 0.501960784313725 0.501960784313725]"
AxesColor "[0 0 0]"
AxesTickColor "[1 1 1]"
LineColors "[1 1 0;1 0 1;0 1 1;1 0 0;0 1 0;0 0 1]"
FigureColor "[1 1 1]"
AxesColor "[1 1 1]"
AxesTickColor "[0 0 0]"
LineColors "[0 0 1;1 0 0;0 1 1;1 0 0;0 1 0;0 0 1]"
LineStyles "-|-|-|-|-|-"
LineWidths "[0.5 0.5 0.5 0.5 0.5 0.5]"
LineWidths "[2 2 0.5 0.5 0.5 0.5]"
MarkerStyles "none|none|none|none|none|none"
}
ShowLegends off
Expand Down Expand Up @@ -942,7 +942,7 @@ MatData {
"6UE '-T;W!4:6UE !T;VQE<F%N8V4 . . 8 ( !@ % \" $ ! 0 ) \" "
" #@ #@ & \" 8 !0 @ ! 0 $ \"0 @ !)0 X X !@ @ "
" & 4 ( 0 $ ! D ( +4,<Z^(V&C\\. . 8 ( !@ % \" $ "
" ! 0 ) \" #\"4A35OP+L6#@ $ & & \" ( !0 @ ! 0 $ !0 $ \\"
" ! 0 ) \" )\"/UP0RVE8]#@ $ & & \" ( !0 @ ! 0 $ !0 $ \\"
" ! \\ &YR &YI &YB &YS &YE "
" &YT &YP87)A;65T97)S &YC;VYS=&%N=', &YD:7-C<F5T90 &YC;VYT:6YU;W5S &YI;G!U= "
" &YO=71P=70 &YI;G1E<FYA; &YN;VYE &EN<'5T<&]R=&1A=&$ &]U='!U='!O<G1D871A X X"
Expand Down Expand Up @@ -1065,7 +1065,7 @@ MatData {
" @ ! . R 8 ( @ % \" $ ! 0 % 0 $ $ @ 8FQO8VMI8V]N "
" '5S969M=6EC;VYI9F%N>0 . , 8 ( !@ % \" 0 ) X P !"
"@ @ ) @ 4 ( 0 $ ! ( 0 ! #@ #@ & \" 8 !0 @ ! 0"
" $ \"0 @ 400 X P !@ @ ) @ 4 ( 0 $ ! ( 0 ! #@ "
" $ \"0 @ @ D(0 X P !@ @ ) @ 4 ( 0 $ ! ( 0 ! #@ "
" % & \" 0 !0 @ ! &0 $ $ !D !2869A96Q?;W)I9VEN86Q?97-T:6UA=&5D "
" X P !@ @ ) @ 4 ( 0 $ ! ( 0 ! #@ (@ & \" ( !0 "
" @ ! 0 $ !0 $ T ! #0 &9M:6QL;V=L979E; . . 8 ( ! % \" "
Expand Down Expand Up @@ -1122,17 +1122,17 @@ MatData {
"871H &9O;&1E<G!A=&@ &9I;&5N86UE '5N>FEP961P871H ')E;&%T:7"
"9E9FUU9F]L9&5R &1L;'!A=&@ 'AM;'!A=&@ %)E;&]A9 %)E;&]A9$-P"
"='( $YE=F5R3&]A9&5D $YO1&QL4&QA=&9O<FU3=7!P;W)T . 2 8 ( ! % "
" \" $ 4 0 0 % #(X+49E8BTR,#$T(#$W.C$V.C(T X \"( !@ @ $ 4 ( "
" \" $ 4 0 0 % #(S+49E8BTR,#$V(# X.C(T.C$U X \"( !@ @ $ 4 ( "
" 0 %4 ! ! !5 6#I<9&5V7&E497-L85]285!)9%QI5&5S;&%?4F%0261<17AA;7!L97-<4V5C;VYD3W)D97)<4F%F865L"
"7S!O<FEG:6YA;%\\P97-T:6UA=&5D+F9M=0 X !H !@ @ $ 4 ( 0 #4 ! ! U 6"
"#I<9&5V7&E497-L85]285!)9%QI5&5S;&%?4F%0261<17AA;7!L97-<4V5C;VYD3W)D97( . 4 8 ( ! % \" "
" $ ? 0 0 'P %)A9F%E;%\\P;W)I9VEN86Q?,&5S=&EM871E9\"YF;74 #@ ( & \" 0 !"
"0 @ ! 3P $ $ $\\ !#.EQ5<V5R<UQ424Y204)^,5Q!<'!$871A7$QO8V%L7%1E;7!<9FUU7'1P,C W8C4R83)?93"
"!B-U\\T-3AC7SDT,S5?9C(Q961E8C=A-C4S X P !@ @ $ 4 ( ! ! #@ "
"0 @ ! 3P $ $ $\\ !#.EQ5<V5R<UQ424Y204)^,5Q!<'!$871A7$QO8V%L7%1E;7!<9FUU7'1P-3$Q,C-F-#-?86"
"4U85\\T-3!F7S@V.&-?,#DR,C,U,S<R,&1C X P !@ @ $ 4 ( ! ! #@ "
" + & \" 0 !0 @ ! ?@ $ $ 'X !#.EQ5<V5R<UQ424Y204)^,5Q!<'!$871A7$QO8V%L"
"7%1E;7!<9FUU7'1P,C W8C4R83)?93!B-U\\T-3AC7SDT,S5?9C(Q961E8C=A-C4S7&)I;F%R:65S7'=I;C,R7%)A9F%E;%\\P;W)I9VEN86Q?,&5S"
"7%1E;7!<9FUU7'1P-3$Q,C-F-#-?864U85\\T-3!F7S@V.&-?,#DR,C,U,S<R,&1C7&)I;F%R:65S7'=I;C,R7%)A9F%E;%\\P;W)I9VEN86Q?,&5S"
"=&EM871E9\"YD;&P X \"8 !@ @ $ 4 ( 0 &0 ! ! !D 0SI<57-E<G-<5$E.4D%\""
"?C%<07!P1&%T85Q,;V-A;%Q496UP7&9M=5QT<#(P-V(U,F$R7V4P8C=?-#4X8U\\Y-#,U7V8R,65D96(W838U,UQM;V1E;$1E<V-R:7!T:6]N+GAM;"
"?C%<07!P1&%T85Q,;V-A;%Q496UP7&9M=5QT<#4Q,3(S9C0S7V%E-6%?-#4P9E\\X-CAC7S Y,C(S-3,W,C!D8UQM;V1E;$1E<V-R:7!T:6]N+GAM;"
" . , 8 ( \"0( % \" $ ! 0 \" $ X X !@ @ & "
" 4 ( 0 $ ! D ( . , 8 ( \"0( % \" $ ! 0 "
" \" $ X P !@ @ ) @ 4 ( 0 $ ! ( 0 ! #@ % & \" "
Expand Down
88 changes: 88 additions & 0 deletions Sources/core/@RaPIdClass/RaPIdClass.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
%% <Rapid Parameter Identification is a toolbox for automated parameter identification>
%
% Copyright 2015 Luigi Vanfretti, Achour Amazouz, Maxime Baudette,
% Tetiana Bogodorova, Jan Lavenius, Tin Rabuzin, Giuseppe Laera,
% Francisco Gomez-Lopez
%
% The authors can be contacted by email: luigiv at kth dot se
%
% This file is part of Rapid Parameter Identification ("RaPId") .
%
% RaPId is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% RaPId is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public License
% along with RaPId. If not, see <http://www.gnu.org/licenses/>.

classdef RaPIdClass <handle
%RAPIDCLASS defines a handle object to store and send settings and data in RaPId
% without too much overhead

properties
psoSettings
gaSettings
combiSettings
naiveSettings
knitroSettings
nmSettings
cgSettings
psoExtSettings
gaExtSettings
fminconSettings
pfSettings
experimentSettings
experimentData
resultData
fmuOutputNames
parameterNames
fmuInputNames
version; %decimals of sqrt(2)
end

methods (Static)
function obj = loadobj(s)% Implements self-updating loading features to ensure backwards
% compatibility with old objects
try
if ~isprop(s, 'version') || isempty(s.version) % if no version -> assign version=1
s.version=double(~isempty(isprop(s, 'version'))); % 0 if really old, else 1 - old
obj = RaPIdClass(s); % update object
elseif s.version <1.41 % check if latest ver
obj = RaPIdClass(s); % update object
else
obj=s; % everything is up to date
end
catch err
disp(err)
disp(struct2table(err.stack))
end
end

end

methods
function obj = RaPIdClass(varargin) %Constructor
if nargin == 0 %Create a new object of the latest version
try
obj=initRapidObj(obj);
catch
%NOP, will still give a an object
end
elseif isa(varargin{1},'RaPIdClass') && varargin{1}.version==1.41
%NOP, up to date
else % Old version, try to update
obj=RaPIdClass(); % New object
obj=obj.updateRapidObj(varargin{1}); % update old object
end
end
function obj = saveobj(obj)

end
end
end
37 changes: 37 additions & 0 deletions Sources/core/@RaPIdClass/initRapidObj.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function obj = initRapidObj(obj)
% INITRAPIDOBJ this function is meant to create a default rapidobject
% Detailed explanation goes here
obj.experimentSettings=struct('tf',1,'ts',0.1,'p_min',[],'p_max',[],'p_0',[],...
'cost_type',1,'objective_weights',1,'t_fitness_start',0,...
'integrationMethod','ode45','maxIterations',100,'solverMode','Simulink',...
'pathToSimulinkModel','','modelName','','blockName','','scopeName','simout',...
'verbose',1,'displayMode','hide','saveHist',0,'timeOut',2,...
'pathToFmuModel','','outputPostProcessing','','optimizationAlgorithm','pso',...
'pathToFMUModel','');
obj.experimentData = struct('pathToInData','','expressionInData','',...
'expressionInDataTime','','referenceOutdata',[],'referenceTime',[],...
'pathToReferenceData','','expressionReferenceTime','','expressionReferenceData','');
obj.psoSettings=struct('w',0.25,'self_coeff',0.25,'social_coeff',0.25,...
'limit',0.2500,'nRandMin',8,'nb_particles',8,'fitnessStopRatio',1e-5,...
'kick_multiplier',0.002,'w_min', 0.01, 'w_max',1,'method','PSO');
obj.gaSettings=struct('nbCromosomes',40,'nbCroossOver1',10,'nbCroossOver2',10,...
'nbMutations',10,'nbReproduction',10,'limit',10,'fitnessStopRatio',1e-5,...
'headSize1',5,'headSize2',5,'headSize3',3,'nbReinjection',5,'nRandMin',10, ...
'p0s', [],'storeData',0);
obj.combiSettings=struct('firstMethod','pso','psoExtOptions','nm','secondMetod','nm');
obj.naiveSettings=struct('tolerance1',1e-4,'tolerance2',1e-7,'iterations',1,'iterations2',1,'iterations3',1);
obj.knitroSettings=struct('path2Knitro','','knOptionsFile','', ...
'knOptions','optimset(''Algorithm'',''active-set'',''TolFun'',1e-6,''TolX'',1e-6);');
obj.nmSettings='optimset(''fminsearch'')';
obj.cgSettings='optimset(optimset(''fminunc''),''FinDiffType'',''central'',''TolX'',1e-6,''LargeScale'',''off'')';
obj.psoExtSettings='psoptimset';
obj.gaExtSettings='gaoptimset';
obj.fminconSettings='optimset(''FinDiffRelStep'',0.1)';
obj.pfSettings=struct('nb_particles', 100,'prune_threshold', 0.1,'kernel_sigma',1);
obj.resultData=[];
obj.fmuOutputNames={''};
obj.parameterNames={''};
obj.fmuInputNames={''};
obj.version=1.41;
end

Loading