-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradient_fit_normalized.m
62 lines (54 loc) · 3.02 KB
/
gradient_fit_normalized.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
function [fitresult, gof] = gradient_fit_normalized(F_DBS_, I_inf,x0,T_syn ,ub, lb,MaxIter,mode,normalize)
%CREATEFIT(F_DBS_,I_INF)
% Create a fit.
%
% Data for 'close_form_sol' fit:
% X Input : F_DBS_
% Y Output: I_inf
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 15-Feb-2021 18:25:09
f0=x0(1);
U0=x0(2);
D0=x0(3);
F0=x0(4);
%% Fit: 'close_form_sol'.
[xData, yData] = prepareCurveData( F_DBS_, I_inf );
if strcmp(mode,'Normal') %% normal -> (U*(1-f)+f)/
if normalize
Formula=['((f+U*(1-f)*(1-exp(-1./(x*F))))/(1-(1-f)*exp(-1./(x*F))))*((1-exp(-1./(x*D)))/(1-(1-(f+U*(1-f)*(1-exp(-1./(x*F))))/(1-(1-f)*exp(-1./(x*F))))*exp(-1./(x*D))))/(1-exp(-1./(x*',num2str(T_syn),')))/(U*(1-f)+f)'];%*
else
Formula=['((f+U*(1-f)*(1-exp(-1./(x*F))))/(1-(1-f)*exp(-1./(x*F))))*((1-exp(-1./(x*D)))/(1-(1-(f+U*(1-f)*(1-exp(-1./(x*F))))/(1-(1-f)*exp(-1./(x*F))))*exp(-1./(x*D))))/(1-exp(-1./(x*',num2str(T_syn),')))'];%*
end
elseif strcmp(mode,'AllLog')%% all log -> (exp(U)*(1-exp(f))+exp(f))/
if normalize
Formula=['((exp(f)+exp(U)*(1-exp(f))*(1-exp(-1./(x*exp(F)))))/(1-(1-exp(f))*exp(-1./(x*exp(F)))))*((1-exp(-1./(x*exp(D))))/(1-(1-(exp(f)+exp(U)*(1-exp(f))*(1-exp(-1./(x*exp(F)))))/(1-(1-exp(f))*exp(-1./(x*exp(F)))))*exp(-1./(x*exp(D)))))/(1-exp(-1./(x*',num2str(T_syn),')))/(exp(U)*(1-exp(f))+exp(f))'];%*
else
Formula=['((exp(f)+exp(U)*(1-exp(f))*(1-exp(-1./(x*exp(F)))))/(1-(1-exp(f))*exp(-1./(x*exp(F)))))*((1-exp(-1./(x*exp(D))))/(1-(1-(exp(f)+exp(U)*(1-exp(f))*(1-exp(-1./(x*exp(F)))))/(1-(1-exp(f))*exp(-1./(x*exp(F)))))*exp(-1./(x*exp(D)))))/(1-exp(-1./(x*',num2str(T_syn),')))'];%*
end
elseif strcmp(mode,'HalfLog')%% only f and U are log
Formula=['((exp(f)+exp(U)*(1-exp(f))*(1-exp(-1./(x*F))))/(1-(1-exp(f))*exp(-1./(x*F))))*((1-exp(-1./(x*D)))/(1-(1-(exp(f)+exp(U)*(1-exp(f))*(1-exp(-1./(x*F))))/(1-(1-exp(f))*exp(-1./(x*F))))*exp(-1./(x*D))))/(exp(U)*(1-exp(f))+exp(f))/(1-exp(-1./(x*',num2str(T_syn),')))'];%(exp(U)*(1-exp(f))+exp(f))*
end
% Set up fittype and options.
ft = fittype( Formula, 'independent', 'x', 'dependent', 'y' );
if MaxIter<400
opts = fitoptions( 'Method', 'NonlinearLeastSquares','MaxIter',MaxIter,'DiffMaxChange',.05);
else
opts = fitoptions( 'Method', 'NonlinearLeastSquares');
end
opts.Display = 'Off';
opts.Lower = [lb(3:4),lb(2),lb(1)];%[0 0 0 0];
opts.StartPoint = [F0, D0,U0,f0]; %[0.855027860168076 0.806963747508719 0.156395362862094 0.133170887149803];
opts.Upper = [ub(3:4),ub(2),ub(1)];%[2 2 1 1];
[fitresult, gof] = fit( xData, yData, ft, opts );
% % Plot fit with data.
% figure( 'Name', 'close_form_sol' );
% h = plot( fitresult, xData, yData );
% legend( h, 'I_inf vs. F_DBS_', 'close_form_sol', 'Location', 'NorthEast', 'Interpreter', 'none' );
% % Label axes
% xlabel( 'F_DBS_', 'Interpreter', 'none' );
% ylabel( 'I_inf', 'Interpreter', 'none' );
% grid on