- Author:
- Shelley Fong <sfon036@UoA.auckland.ac.nz>
- Date:
- 2024-11-08 10:24:21+13:00
- Desc:
- fix error
- Permanent Source URI:
- https://models.physiomeproject.org/workspace/826/rawfile/70e675b7b8af2e14572beca493704b180f864c41/matlab_parameter_fitting/f_gate_fitting.m
% based on Na_h gate by Pan.
clear;
% clc;
% close all;
%% Options
run_optimisation = false;
%% Set directories
current_dir = pwd;
main_dir = current_dir; %
data_dir = [main_dir '\data' filesep];
output_dir = [main_dir '\output' filesep];
storage_dir = [main_dir '\storage' filesep];
%% Steady-state gating parameters and time constants
V = transpose(-120:1:50);
alpha_f = 5.7897e-07*exp(V/-14.5897);
beta_f = 0.01163*exp(V/33.92694);
tau_f = 1./(alpha_f + beta_f);
g_ss_f = alpha_f./(alpha_f + beta_f);
%% Fit bond graph parameters to model
% params: [kf, zf, kr, zr];
error_func_alpha = @(params) square_error(alpha_f - calc_alpha(params,V/1000));
error_func_beta = @(params) square_error(beta_f - calc_beta(params,V/1000));
error_func_gss = @(params) square_error(g_ss_f - p2gss(params,V));
error_func_tau = @(params) square_error(tau_f- p2tau(params,V));
error_func = @(params) error_func_alpha(params) + error_func_beta(params) + error_func_gss(params) + error_func_tau(params);
% error_func = @(params) error_func_gss(params) + error_func_tau(params);
A = [];
b = [];
Aeq = [];
beq = [];
lb = [0; -10; 0; -10];
ub = [Inf; 10; Inf; 10];
options_unc = optimoptions('fminunc','MaxFunEvals',10000);
options_ps = optimoptions('particleswarm','UseParallel',false,'HybridFcn',@fmincon,...
'SwarmSize',1500,'FunctionTolerance',1e-13);
if run_optimisation
[params_vec,fval,exitflag,output] = particleswarm(error_func,4,lb,ub,options_ps);
save([storage_dir 'to_f_parameters.mat'],'params_vec');
else
load([storage_dir 'to_f_parameters.mat']);
end
% [params_vec,fval,exitflag,output,grad,hessian] = fminunc(error_func,params_vec,options_unc);
%% Plot
% find things again over a wider V range
if false
V2 = transpose(-120:1:50);
else
V2 = V;
end
g_ss_fit = p2gss(params_vec,V2);
h1 = figure;
plot(V2,g_ss_f,'kx');
hold on;
plot(V2,g_ss_fit,'k');
legend('kinetic','Fitted');
xlabel('Voltage (mV)');
ylabel('h_{ss}');
set(gca,'FontSize',28);
xlim([-120 60]);
set(gca,'XTick',-120:30:60);
set(gca,'YTick',0:0.2:1);
xticklabels({-120,'',-60,'',0,'',60});
yticklabels({0,'','','','',1});
set(gca,'LineWidth',3);
grid on;
tau_fit = p2tau(params_vec,V2);
h2 = figure;
plot(V2,tau_f,'kx');
hold on;
plot(V2,tau_fit,'k');
legend('kinetic','Fitted');
xlabel('Voltage (mV)');
ylabel('\tau_f (ms)');
set(gca,'FontSize',28);
xlim([-120 60]);
set(gca,'XTick',-120:30:60);
% set(gca,'YTick',0:0.2:1);
xticklabels({-120,'',-60,'',0,'',60});
% yticklabels({0,'','','','',1});
set(gca,'LineWidth',3);
set(gca,'xgrid','on');
% print_figure(h1,output_dir,'g_ss_f');
% print_figure(h2,output_dir,'tau_f');
alpha_fit = calc_alpha(params_vec,V2/1000);
beta_fit = calc_beta(params_vec,V2/1000);
figure,
subplot(1,2,1)
plot(V2,alpha_f,'x',V2,alpha_fit);
legend('original','fit');
subplot(1,2,2)
plot(V2,beta_f,'x',V2,beta_fit);
legend('original','fit');