MBB-team / VBA-toolbox

The VBA toolbox
GNU General Public License v3.0
129 stars 67 forks source link

Is it possible to deal with data that are not sampled on a regular grid? #3

Closed zjwufei closed 8 years ago

zjwufei commented 9 years ago

Dear developers,

My data is sampled irregularly ( frequently in the first several days, then the frequency dropped to once a week until once a month), is it possible for the VBA toolbox to deal with data like that?

If it is possible, could you please show how to set up the settings, please?

Thanks!

Yan

lionel-rigoux commented 9 years ago

Depending on the size of your data, one simple solution would be to sample all your data-points at "high" frequency, (eg n points a day) and set the inversion to discard the missing data points using the options.isYout field (see the wiki). This solution could however increase the size of your data to an intractable level... Maybe should you then try and express your dynamical system as a nonlinear function of time.

jdaunize commented 9 years ago

Dear Yan, I have created a demo for identifying a dynamical system, which is sampled on an irreguar grid: demo_irregular.m. It is in VBA if you use GITHUB. If you don't, I've copied and pasted the demo below:

% this demo inverts a dynamical system that is sampled on an irregular grid

clear all close all

nt = 2e2; f_fname = @f_2dwu; g_fname = @g_Id;

in.A = [-4 -16 4 -4]; in.dt = 1e-1; x0 = [1;1]; theta = [1;2]; phi = []; alpha = Inf; sigma = 1; u =randn(2,nt);

% Build options and dim structures for model inversion options.inF = in; options.inG = in; dim.n_theta = 2; dim.n_phi = 0; dim.n = 2; dim.p = 2;

% Build time series of hidden states and observations [y,x,x0,eta,e] = simulateNLSS(nt,f_fname,g_fname,theta,phi,u,alpha,sigma,options,x0); displaySimulations(y,x,eta,e)

% Invert deterministic model options.priors.SigmaTheta = 1e2*eye(2); [posterior,out] = VBA_NLStateSpaceModel(y,u,f_fname,g_fname,dim,options); displayResults(posterior,out,y-e,x,x0,theta,phi,alpha,sigma);

% Now resample data on an irregular grid by 'removing' data in = zeros(1,nt); in(2.^[1:floor(log(nt)./log(2))]) = 1; % exponential sampling grid isout = repmat(1-in,size(y,1),1); % point sto remove y(isout==1) = 0; options.isYout = isout; [posterior,out] = VBA_NLStateSpaceModel(y,u,f_fname,g_fname,dim,options); displayResults(posterior,out,y-e,x,x0,theta,phi,alpha,sigma);

jdaunize commented 9 years ago

Oh and you need this evolution function:

function [fx] = f_2dwu(x,P,u,in) xdot = in.A_x + diag(P)_u; fx = x + in.dt*xdot;

zjwufei commented 9 years ago

Thank you very much for your help. The code works well in my computer. :)