On Wed, Oct 21, 2009 at 2:02 PM, Thomas Petzoldt <
Thomas.Petzoldt@tu-dresden.de> wrote:

> Rainer M Krug wrote:
>
>> Hi
>>
>> I have a problem with simecol, particularly with the logistic growth model
>> with harvesting: with the parameters as given below, it crashes R.
>>
>> When I change h to values below 100, it works, changing the solver to
>> "euler" or "rk4", it works
>>
>> Any idea what is happening, or am I doing something wrong?
>>
>
> Hi Rainer,
>
> as you see yourself, this is not a problem of package simecol, it is a
> problem of lsoda from the deSolve package. The reason is, that with the
> parameters given, your simulation runs to minus infinity.
>

agreed here.


> As a result, former versions of deSolve/lsoda produced a buffer overflow
> and this resulted in a "stack smashing" error.
>
> The "stack smashing" bug was solved in version 1.5 of deSolve, available
> from CRAN since last weekend. Instead of breaking R lsoda now issues an
> error message. I admit that this error message is not very helpful, but
>

Well - actually not. I updated after I send the email already, and tried it
again:

> library(simecol)
Loading required package: deSolve
> sessionInfo()
R version 2.9.2 (2009-08-24)
i486-pc-linux-gnu

locale:
LC_CTYPE=en_ZA.UTF-8;LC_NUMERIC=C;LC_TIME=en_ZA.UTF-8;LC_COLLATE=en_ZA.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_ZA.UTF-8;LC_PAPER=en_ZA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_ZA.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] simecol_0.6-9 deSolve_1.5
> library(simecol)
> lgH <- new(
+           "odeModel",
+           main = function (time, init, parms) {
+             with(
+                  as.list(c(init, parms)),
+                  {
+                    dn <-  r * N * (1 - (N/K)) - h
+                    list(dn)
+                  }
+                  )
+           },
+           parms  = c(r = 0.1, K = 10000, h=200),
+           times  = c(from = 0, to = 100, by = 0.5),
+           init   = c(N = 2000),
+           solver = "lsoda"
+ )
> lgH <-  sim(lgH)
*** stack smashing detected ***: /usr/lib/R/bin/exec/R terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7b94138]

It still seems to have the problem.


> there are several possibilities to diagnose the problem:
>
> One option is to use a fixed step solver (rk4, euler) as you did, or a
> different variable time step solver (rk alias ode45, vode, lsode or
> daspk). Given your model and parameters, try:
>
> solver(lgH) <- "vode"
> plot(sim(lgH))
>
>
OK - makes sense.


> lsoda seems the only one that fails completely, but even that case can
> be solved (in the diagnostic sense, i.e. by potentially loosing
> accuracy) if you limit hmin, e.g.:
>
> solver(lgH) <- "lsoda"
> plot(sim(lgH, hmin = 1e-12))
>
> actually, that also crashes R:

Same Model...

> sessionInfo()
R version 2.9.2 (2009-08-24)
i486-pc-linux-gnu

locale:
LC_CTYPE=en_ZA.UTF-8;LC_NUMERIC=C;LC_TIME=en_ZA.UTF-8;LC_COLLATE=en_ZA.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_ZA.UTF-8;LC_PAPER=en_ZA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_ZA.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] simecol_0.6-9 deSolve_1.5
> sim(lgH, hmin = 1e-12)
*** stack smashing detected ***: /usr/lib/R/bin/exec/R terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7c6b138]
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb7c6b0f0]


Cheers,

Rainer


>
> Hope it helps and please update deSolve.
>

Done, but did not solve the problem?


>
> Thomas Petzoldt
>
>
>
>
>
>


-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:           +27 - (0)83 9479 042
Fax:            +27 - (0)86 516 2782
Fax:            +49 - (0)721 151 334 888
email:          Rainer@krugs.de

Skype:          RMkrug
Google:         R.M.Krug@gmail.com

	[[alternative HTML version deleted]]

