-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ckreutz
committed
Dec 12, 2023
1 parent
65434b3
commit 0ec58a9
Showing
3 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...mework3/Examples/ToyModels/TransientFunction/TransientFunction_library/WriteTextSummary.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
% WriteTextSummary(fit, folder) | ||
% | ||
% fit a fit or cell array of fits as generated by | ||
% arConditon2NewDataStruct*.m | ||
% | ||
% folder [WriteTextSummary] | ||
% | ||
% This function write matlab code for simulating the dynamics based on | ||
% fitted transient functions in the specified folder. | ||
% | ||
% Example: | ||
% arLoad | ||
% fits = arApproximateTimeCoursesByTransientFunction2; | ||
% WriteTextSummary(fits) | ||
% t = linspace(0,100,101); | ||
% plot(t,feval(fits{1}.label,t)); | ||
|
||
function WriteTextSummary(fit,folder) | ||
if ~exist('folder','var') || isempty(folder) | ||
folder = 'WriteTextSummary'; | ||
end | ||
if ~isdir(folder) | ||
mkdir(folder); | ||
end | ||
|
||
if iscell(fit) | ||
for i=1:length(fit) | ||
if isfield(fit{i},'pLabel') % otherwise fitting failed | ||
WriteTextSummary(fit{i}); | ||
else | ||
fprintf('WriteTextSummary.m: It seems that fit{%i} fitting was failed.\n',i) | ||
end | ||
end | ||
|
||
else | ||
if isfield(fit,'label') | ||
name = sprintf('%s',fit.label); | ||
else | ||
name = sprintf('Model%i_%s_condition%i',fit.m, fit.x, fit.c); | ||
end | ||
name = strrep(name,' ','_'); | ||
filename = [folder,filesep,name,'.m']; | ||
fid = fopen(filename,'w'); | ||
|
||
fprintf(fid,'%s This function can be used to approximate model%i, condition%i, dynamic variable %s\n\n','%',fit.m, fit.c, fit.x); | ||
fprintf(fid,'function [out, outSD] = %s(t)\n',name); | ||
for i=1:length(fit.data.p) | ||
if strcmp('init____dummy___',fit.data.p{i})~=1 % omit this D2D dummy parameter | ||
if strcmp(fit.data.p{i},fit.data.fp{i})~=1 | ||
fprintf(fid,'%s = %s;\n',fit.data.p{i},fit.data.fp{i}); | ||
else | ||
ind = strmatch(fit.data.p{i},fit.pLabel,'exact'); | ||
fprintf(fid,'%s = %f;\n',fit.data.p{i},fit.p(ind)); | ||
end | ||
end | ||
end | ||
fprintf(fid,'\n'); | ||
for i=1:length(fit.data.fu) | ||
fprintf(fid,'%s = %s;\n',fit.u{i},Replacements(fit.data.fu{i})); | ||
end | ||
fprintf(fid,'\n'); | ||
for i=1:length(fit.data.fy) | ||
fprintf(fid,'out = %s;\n',Replacements(fit.data.fy{i})); | ||
end | ||
fprintf(fid,'\n'); | ||
fprintf(fid,'outSD = NaN(size(out));\n'); | ||
fprintf(fid,'outSD(:) = %f;\n',fit.approxErr); | ||
fprintf(fid,'\n'); | ||
|
||
|
||
|
||
|
||
|
||
fclose(fid); | ||
end | ||
|
||
|
||
function out = Replacements(in) | ||
out = strrep(in,'*','.*'); | ||
out = strrep(out,'/','./'); | ||
out = strrep(out,'^','.^'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...work3/Examples/ToyModels/TransientFunction/TransientFunction_library/arSetParsTransient.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
% This function calls arSetPars but also translates info (e.g. bounds) into | ||
% ar.fit_transient | ||
function arSetParsTransient(pLabel, varargin) | ||
global ar | ||
if length(varargin)>0 | ||
p = varargin{1}; | ||
else | ||
p = []; | ||
end | ||
if length(varargin)>1 | ||
qFit = varargin{2}; | ||
else | ||
qFit = []; | ||
end | ||
if length(varargin)>2 | ||
qLog10 = varargin{3}; | ||
else | ||
qLog10 = []; | ||
end | ||
if length(varargin)>3 | ||
lb = varargin{4}; | ||
else | ||
lb = []; | ||
end | ||
if length(varargin)>4 | ||
ub = varargin{5}; | ||
else | ||
ub = []; | ||
end | ||
|
||
% translate bounds to fit_transient.bounds | ||
if(isfield(ar,'fit_transient')) | ||
ind = strmatch(pLabel,ar.fit_transient.bounds.pLabel,'exact'); | ||
if ~isemtpy(lb) | ||
ar.fit_transient.bounds.lb(ind) = lb; | ||
end | ||
if ~isemtpy(ub) | ||
ar.fit_transient.bounds.ub(ind) = ub; | ||
end | ||
end | ||
% arSetPars(pLabel, [p], [qFit], [qLog10], [lb], [ub], [type], [meanp], [stdp]) | ||
arSetPars(pLabel_or_ar, varargin{:}) |