Skip to content
Snippets Groups Projects
Commit 6fcf549f authored by Laurie Boffelli's avatar Laurie Boffelli
Browse files

Correction Dynamics_Model (modification: fmincon)

parent 87cb224e
No related branches found
No related tags found
No related merge requests found
...@@ -161,7 +161,13 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle ...@@ -161,7 +161,13 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle
X_ini = [X_ini; new_X_ini]; X_ini = [X_ini; new_X_ini];
X_ini=obj.normalise_X(X_ini) X_ini=obj.normalise_X(X_ini)
[new_X_variable,loglikelihood] = fminunc(f,X_ini); lb = repmat(0,1,length(X_ini));
ub = repmat(1,1,length(X_ini));
A = [];
b = [];
Aeq = [];
beq = [];
[new_X_variable,loglikelihood] = fmincon(f,X_ini,A,b,Aeq,beq,lb,ub);
obj.confidence = [obj.confidence, -loglikelihood / size(new_X_variable,1)]; obj.confidence = [obj.confidence, -loglikelihood / size(new_X_variable,1)];
new_X_variable = obj.normalise_X(new_X_variable); new_X_variable = obj.normalise_X(new_X_variable);
...@@ -178,7 +184,7 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle ...@@ -178,7 +184,7 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle
obj.nb_times_fixed = [obj.nb_times_fixed; 0]; obj.nb_times_fixed = [obj.nb_times_fixed; 0];
end end
if abs(obj.X(i) - new_X(i)) < 1e-3 if abs(obj.X(i) - new_X(i)) < 1e-3%1e-2
obj.nb_times_fixed(i) = obj.nb_times_fixed(i)+1; obj.nb_times_fixed(i) = obj.nb_times_fixed(i)+1;
else else
obj.nb_times_fixed(i) = 0; obj.nb_times_fixed(i) = 0;
...@@ -202,21 +208,21 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle ...@@ -202,21 +208,21 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle
if new_N_fixed > N-3 if new_N_fixed > N-3
new_N_fixed = N-3; new_N_fixed = N-3;
end end
%
if new_N_fixed < 0 if new_N_fixed < 0
new_N_fixed = 0; new_N_fixed = 0;
end end
%
if new_N_fixed < N-13 if new_N_fixed < N-13 %N-8
new_N_fixed = N-13; new_N_fixed = N-13; %N-8;
end end
if size(new_X, 1) < 12 if size(new_X, 1) < 4 %12
new_N_fixed = size(new_X, 1) - 2; new_N_fixed = size(new_X, 1) - 2;
if new_N_fixed < 0 if new_N_fixed < 0
new_N_fixed = 0; new_N_fixed = 0;
end end
elseif size(new_X, 1) == 12 elseif size(new_X, 1) == 4 %12
new_N_fixed = 0; new_N_fixed = 0;
end end
...@@ -262,8 +268,13 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle ...@@ -262,8 +268,13 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle
X_ini = X_tmp(2:end-1)'; X_ini = X_tmp(2:end-1)';
lb = repmat(0,1,length(X_ini));
[new_X,loglikelihood] = fminunc(f,X_ini); ub = repmat(1,1,length(X_ini));
A = [];
b = [];
Aeq = [];
beq = [];
[new_X,loglikelihood] = fmincon(f,X_ini,A,b,Aeq,beq,lb,ub);
new_X = [0; obj.normalise_X(new_X); 1]; new_X = [0; obj.normalise_X(new_X); 1];
obj.X = new_X; obj.X = new_X;
...@@ -288,6 +299,8 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle ...@@ -288,6 +299,8 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle
function loglikelihood = logP_x_knowing_y_partialUpdate(obj, last_fixed_X, variable_X, alpha, sigma) function loglikelihood = logP_x_knowing_y_partialUpdate(obj, last_fixed_X, variable_X, alpha, sigma)
N_variable = size(variable_X,1); N_variable = size(variable_X,1);
% variable_X = obj.normalise_X(variable_X);
% if N == 1, we only maximise P_cond_y(Y(1),X(1)) % if N == 1, we only maximise P_cond_y(Y(1),X(1))
% if N == 2, we maximise P_cond_y(Y(2),X(2)) * P_x_Markov_simple(X(2),X(1)) * P_cond_y(Y(1),X(1)) with P_x_Markov_simple(X(2),X(1)) = 0 if delta_X is negative, and uniform proba otherwise % if N == 2, we maximise P_cond_y(Y(2),X(2)) * P_x_Markov_simple(X(2),X(1)) * P_cond_y(Y(1),X(1)) with P_x_Markov_simple(X(2),X(1)) = 0 if delta_X is negative, and uniform proba otherwise
...@@ -415,11 +428,37 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle ...@@ -415,11 +428,37 @@ classdef Dynamics_Model < matlab.mixin.Copyable %handle
ylabel(['Manifold coordinate Y_' i]) ylabel(['Manifold coordinate Y_' i])
hold on hold on
plot(obj.normalise_X(obj.X(start_frame:N)),obj.Y(start_frame:N,i),'kx') plot(obj.normalise_X(obj.X(start_frame:N)),obj.Y(start_frame:N,i),'kx')
end
%pour faire des gifs
%saveas(obj.display_screen, strcat('estimatedX_frame', int2str(N), '.png'))
end
end
function [im]=final_plot_estimated_X(obj)
if obj.display_screen ~= -1
N = size(obj.X,1);
start_frame = max(N - 50, 1);
figure(obj.display_screen)
for i=1:obj.num_dim_Y
subplot(obj.num_dim_Y,1,i)
hold off
im=imagesc([0 1],[obj.limits_Yi(i,1) obj.limits_Yi(i,2)],obj.marginal_X_Yi(:,:,i),'CDataMapping','scaled')
%set(gca,'YDir','normal')
hold on
plot(obj.normalise_X(obj.X(start_frame:N)),obj.Y(start_frame:N,i),'kx')
axis off
end end
%pour faire des gifs %pour faire des gifs
%saveas(obj.display_screen, strcat('estimatedX_frame', int2str(N), '.png')) %saveas(obj.display_screen, strcat('estimatedX_frame', int2str(N), '.png'))
end end
end end
function X = normalise_X(obj, X) function X = normalise_X(obj, X)
X(X<0) = 0; X(X<0) = 0;
X(X>1) = 1; X(X>1) = 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment