Re: [Rpy] kill RPy process and start over

2006-08-28 Thread Tim Churches
Ben Stabler wrote:
> I'm rather new to RPY, but have a lot of experience with R and Python.  What
> I want to do is something like this.
>  
> import rpy
>  
> #do a bunch of R calls that use up a bunch of memory like x <-
> matrix(0,2000,2000) 200 times.  
> #then R eventually says that it cannot allocate a vector of X size because
> of memory fragmentation.
> #so then I kill the rpy process and start over.
>  
> #to remove it?
> del(rpy.r)
>  
> #or 
> del(rpy)
>  
> #then maybe?
> import rpy 
>  
> #and/or
> rpy.r = rpy.R()
>  
> #but then I get RuntimeError: Only one R object may be instantiated per
> session
>  
> #Basically the problem is that I need to get ride of my R object and start
> over.  Can I do this?  Thanks.

I don't think you can get gid of the R object, except by closing the
Python process which hosts it. You may need to use fork to create
subprocesses.

Tim C


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list


Re: [Rpy] rpy and lattice

2006-08-31 Thread Tim Churches
Ernst O Ahlberg Helgee wrote:
> Hi!
> Im trying to get rpy to produce a levelplot using package lattice, but it 
> fails. I dont get error messages, just a r object or python dict.
> This is the code:
> from rpy import *
> import Numeric as N
> r.library('lattice')
> a = [[1,2,3],[4,5,6],[7,8,9]]
> A = N.array(a,N.Float)
> r.levelplot(A)
> 
> I use R 2.2.1 from last of 2005, but with recently updated pkgs
> python 2.4.3 enthought 1.0.0beta4
> 
> but I have also confirmed the problem under linux (similar conditions)
> 
> 
> so if you know how to solve this please give me a hint

You need to user the print() or rather print_() function around teh
lattice function.

Tim C

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list


Re: [Rpy] cluster.stats results differ

2006-10-12 Thread Tim Churches
Myles English wrote:
> Hello,
> 
> rpy 1.25
> ubuntu 6.10
> python 2.4
> 
> The code below can be copied and pasted in the R interpreter or an empty
> file, as appropriate, to be run easily.  The python code imports
> dataframe.py that is included as an example in the rpy distribution.
> 
> My question is:
>
> Running the R code in the interpreter prints the list of hubertgamma
> values as:
> 0.6982304 0.6501113 0.5739095 0.5301628 0.4861548 0.4826513   
> 0.4579655 0.4465557 0.4329692 0.4092727
> 
> Running the RPy code in a shell prints the list of hubertgamma values
> as:
>  [0.052761567599982385, -0.0045159859941235163, -0.047153537691912426,
> -0.018242422413064344, -0.022733831895949543, -0.0033926040834361161,
> -0.020580660750514498, -0.018014109040888696, -0.012575979384130119]
>  
> Why aren't these two lists the same?  I think I am missing something in
> the conversion.

It doesn't look like you are setting the seed to the R random number
generator to 1 in the Python code - are you? If not, you will be using
two different sets of input values -> two different sets of answers.

Tim C

> # R code
> #
> # from http://addictedtor.free.fr/packages
> require(fpc)
> require(A2R)
> d.usa <- dist(USArrests, "euc")
> h.usa <- hclust(d.usa, method="ward")
> set.seed(1)
> some.factor <- letters[1:4][rbinom(50, prob=0.5, size=3)+1]
> hubertgamma <- rep(0,10)
> for(i in 1:10){
>   hubertgamma[i] <- cluster.stats(d.usa, 
>   cutree(h.usa, k=i+1),
>   G2 = FALSE,
>   G3 = FALSE,
>   silhouette = FALSE)$hubertgamma
> }
> A2Rplot(h.usa, 
> k=3, 
> fact.sup=some.factor, 
> criteria=hubertgamma,
> boxes = FALSE,
> col.up = "gray",
> col.down = c("orange","royalblue","green3"))
> hubertgamma
> #prints 0.6982304 0.6501113 0.5739095 0.5301628
> # 0.4861548 0.4826513 0.4579655
> # 0.4465557 0.4329692 0.4092727
> 
> # python code using RPy to put in a module
> #=
> from rpy import *
> from dataframe import * # dataframe.py comes with the rpy
> distribution
> class_table['data.frame'] = DataFrame
> 
> class A(object):
> def build(self):
> set_default_mode(NO_CONVERSION) # so that, hclust finds more
> than one item in rdist
> d = r('USArrests')
> self.rdist = r.dist(d, method = "euclidean")
> self.dend = r.hclust(self.rdist, method="ward")
> r.require('fpc')
> r.require('A2R')
> hubertgamma = []
> set_default_mode(CLASS_CONVERSION)
> f=['a','b','c','d']
> self.somefactor = [f[int(i)] for i in r.rbinom(50, prob=0.5,
> size=3)]
> self.hubertgamma = []
> for i in range(1,10):   # not zero-based, could cause a problem
> self.hubertgamma.append(r.cluster_stats(self.rdist, 
>   r.cutree(self.dend, k=i+1),
>   G2 = False,
>   G3 = False,
>   silhouette = False)['hubertgamma'])
> r.x11()
> r.A2Rplot(self.dend,
>   k = 3,
>   fact_sup=self.somefactor,
>   criteria=self.hubertgamma,
>   boxes = True,
>   col_up = "gray",
>   col_down = ["orange","royalblue", "green3"])
> #r.dev_off()
> return self.hubertgamma
> 
> if __name__ == '__main__':
> obj = A()
> print obj.build()
> #prints [0.052761567599982385, -0.0045159859941235163,
> # -0.047153537691912426, -0.018242422413064344,
> # -0.022733831895949543, -0.0033926040834361161,
> # -0.020580660750514498, -0.018014109040888696,
> # -0.012575979384130119]
> 
> 
> -
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> ___
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list
> 


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
rpy-list mailing list
rpy-list@lists.source