Desolve package: How to pass thousand of parameters to C compiled code?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Desolve package: How to pass thousand of parameters to C compiled code?

MikeR
Hi,

I have used DeSolve package for my ODE problem regarding infectious disease transmission and currently am trying to pass lots (roughly a thousand) of model parameters to the C compiled model (I have to use C compiled code instead of R code purely because of the speed).

I can't go define it one by one as it gonna take ages to finish and also quite difficult to revise. I have read the instructions in "Writing Code in Compiled Languages", which is very well written, but still have no clue on how to proceed.

Please can anyone suggest the best way to go about this, and also the places where I can find examples of DeSolve C compiled code.

Thank you very much in advance.

Nar Pun
CMMU/MUTH

--
This message was sent on behalf of [hidden email] at openSubscriber.com
http://www.opensubscriber.com/messages/r-help@.../topic.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Desolve package: How to pass thousand of parameters to C compiled code?

Ben Bolker
 <cmmu_mile <at> yahoo.com> writes:

>
> Hi,
>
> I have used DeSolve package for my ODE problem regarding
> infectious disease transmission and currently am
> trying to pass lots (roughly a thousand) of model parameters
> to the C compiled model (I have to use C
> compiled code instead of R code purely because of the speed).
>
> I can't go define it one by one as it gonna take ages to finish
> and also quite difficult to revise. I have read
> the instructions in "Writing Code in Compiled Languages", which
> is very well written, but still have no
> clue on how to proceed.
>
> Please can anyone suggest the best way to go about this, and also the places
where I can find examples of
> DeSolve C compiled code.
>

  There's another example of compiled code in
http://www.jstatsoft.org/v33/i09/paper , but it probably
won't say anything the 'Writing Code' guide doesn't already
cover.  I found the guide pretty complete ...

  I would suggest that you pack your parameters into a single
numeric vector (or several, if that makes more sense) and pass
them that way.

  What kind of infectious disease data do you have that will
allow you to fit a model with thousands of parameters ... ??
(Just curious.)

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Desolve package: How to pass thousand of parameters to C compiled code?

Thomas Petzoldt-4
On 6/8/2010 2:03 PM, Ben Bolker wrote:

>   <cmmu_mile<at>  yahoo.com>  writes:
>
>>
>> Hi,
>>
>> I have used DeSolve package for my ODE problem regarding
>> infectious disease transmission and currently am
>> trying to pass lots (roughly a thousand) of model parameters
>> to the C compiled model (I have to use C
>> compiled code instead of R code purely because of the speed).
>>
>> I can't go define it one by one as it gonna take ages to finish
>> and also quite difficult to revise. I have read
>> the instructions in "Writing Code in Compiled Languages", which
>> is very well written, but still have no
>> clue on how to proceed.
>>
>> Please can anyone suggest the best way to go about this, and also the places
> where I can find examples of
>> DeSolve C compiled code.
>>
>
>    There's another example of compiled code in
> http://www.jstatsoft.org/v33/i09/paper , but it probably
> won't say anything the 'Writing Code' guide doesn't already
> cover.  I found the guide pretty complete ...
>
>    I would suggest that you pack your parameters into a single
> numeric vector (or several, if that makes more sense) and pass
> them that way.
>    What kind of infectious disease data do you have that will
> allow you to fit a model with thousands of parameters ... ??
> (Just curious.)


I agree in using vectors (and matrices) like recommended by Ben. In
addition, you may consider to use structures and unions instead of
#define macros:

union my_parms_vec {
   struct {double foo1, foo2, bar[15];};
   double value[18];
};

static my_parms_vec p;

// ...

// This structure has then to be initialized
// as vector 'value' in initmod:

/* initializer  */
void initmod(void (* odeparms)(int *, double *))
{
     int N=3;
     odeparms(&N, p.value);
}

// so that you can use constructs like

p.foo or p.bar[7] in your model (i.e. derivs) function.


With respect of the large number of parameters you may think whether
they are really "parameters" and not something like external forcings,
for which recent versions of deSolve have separate mechanisms to deal
with. See ?forcings

Hope it helps


Thomas Petzoldt

PS: There is also a dedicated mailing list for discussions like this:
https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.