On 2011-06-16 17:20, B. Santos wrote:
> Hello everyone,
>
> I am trying to use rpy2 to estimate the parameters of a specified function.
> But I am failing miserable to understand how I can do this using rpy2. I
> have the following R code: alphabeta<-function(alphabeta,x,dicerAcc) {
>    alpha<-alphabeta[1]
>    beta<-alphabeta[2]
>    if (any(alphabeta<0))
>      return(NA)
>    sum((alpha*log(beta) + lgamma(alpha + x) + x * log(dicerAcc) -
> lgamma(alpha) - (alpha + x) * log(beta+dicerAcc) - lfactorial(x))[dicerAcc
>> noiseT]) ab<- optim(c(1,100), alphabeta, control=list(fnscale=-1), x =
> x, dicerAcc = dicerAcc)$par
>
> Is there anyway to do this. I would imagine the easy way would be to 
> import
> the function from R but I imagine that means I would have to create a
> package just for the function which is less than ideal.
>

You can just parse and evaluate a string as R code as an anonymous R 
function.
http://rpy.sourceforge.net/rpy2/doc-2.2/html/rinterface.html#parsing-and-evaluating-r-code
and then use base.eval().

You can also consider writing your cost function in Python:
http://rpy.sourceforge.net/rpy2/doc-2.2/html/rinterface.html#calling-python-functions-from-r


HTH,


L.
> Looking forward to your suggestion. Thank you very much in advance,
> Bruno Santos
>
> ------------------------------------------------------------------------------
> EditLive Enterprise is the world's most technically advanced content
> authoring tool. Experience the power of Track Changes, Inline Image
> Editing and ensure content is compliant with Accessibility Checking.
> http://p.sf.net/sfu/ephox-dev2dev
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list


------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to