基于Scilab的Lotka Volterra模型的参数估计 [英] Parameters estimation on Lotka Volterra model with Scilab

查看:204
本文介绍了基于Scilab的Lotka Volterra模型的参数估计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Scilab对Lotka-Volterra模型进行参数估计(我是新手).当我尝试运行脚本时,Scilab会警告不要进行相干减法.我想我的问题与此主题中的问题相同,但是那里的解决方案使用了Matlab函数.

I'm trying to make a parameters estimation on Lotka-Volterra model with Scilab (I am a total neophyte). When I try to run the script, Scilab warns about incoherent subtraction. I guess my problem is the same as in this topic, but the solution there uses a Matlab function.

这是我的剧本:

// 1. Create Lotka Volterra function

function [dY]=LotkaVolterra(t,X,c,n,m,e)
    IngestC = c * X(1) * X(2)
    GrowthP = n * X(1)
    MortC = m * X(2)
    dY(1) = GrowthP - IngestC
    dY(2) = IngestC * e - MortC
endfunction

// 2. Define the Nonlinear Least Squares functions

function f = Differences ( x ) 
    // Returns the difference between the simulated differential 
    // equation and the experimental data.
    c = x(1) ;n = x(2);m = x(3);e = x(4);y0 = y_exp(1,:);t0 = 0
    y_calc=ode(y0',t0,t,list(LotkaVolterra,c,n,m,e)) 
    diffmat = y_calc' - y_exp
    f = diffmat(:)
endfunction 

function val = L_Squares ( x ) 
    // Computes the sum of squares of the differences.
    f = Differences ( x ) 
    val = sum(f.^2)
endfunction 

// Experimental data 
t = [0:19]'; 
H=[20,20,20,12,28,58,75,75,88,61,75,88,69,32,13,21,30,2,153,148];
L=[30,45,49,40,21,8,6,5,10,20,33,34,30,21,14,8,4,4,14,38];
y_exp=[H',L'];


// compute the model cost function
function [f, g, ind] = modelCost (x, ind)
    f = L_Squares ( x )
    g = derivative ( L_Squares , x )
endfunction

// use of optim function with loops to avoid local minimum 
tic
i=0
fitminx=zeros(4,100);
fitminy=zeros(1,100);
for c=[0:0.1:1]
    for n=[0:0.1:1]
        for m=[0:0.1:1]
            for e=[0:0.1:1]
                i=i+1
                x0 = [c;n;m;e]
                [ fopt , xopt , gopt ] = optim ( modelCost , x0 )
                fitminx(:,i)=xopt;
                fitminy(:,i)=fopt;
            end
        end
    end 
end
[a,b]=min(fitminy)
fitminx(:,a)
toc

错误消息是:

lsoda--  at t (=r1), mxstep (=i1) steps   
needed before reaching tout
      where i1 is :        500                                                  
      where r1 is :   0.4145715729197D+01                                       
Attention : Le résultat est peut être inexact.

 !--error 9 
Soustraction incohérente.
at line       4 of function Differences called by :  
at line       2 of function L_Squares called by :  
at line      16 of function %R_ called by :  
at line      15 of function %deriv1_ called by :  
at line      58 of function derivative called by :  
at line       3 of function modelCost called by :  
                [ fopt , xopt , gopt ] = optim ( modelCost , x0 )

感谢您对我的问题的兴趣和时间(对不起我的英语)

thanks for the interest and the time you give to my problem (and sorry for my english)

推荐答案

您的问题是,在优化过程中,c,n,m,e参数将得到负值.只需在optim调用中添加约束,如下所示:

Your problem is that during the optimization c,n,m,e parameters get negative values. Just add constraints in your optim call, like this:

[fopt, xopt, gopt] = optim(modelCost, 'b', zeros(4,1), %inf*ones(4,1), x0)

这篇关于基于Scilab的Lotka Volterra模型的参数估计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆