I fixed a problem with rpy2 (the fix is in SVN)
It does seem to fit happily a lot of linear models without problems now.

For the moment rpy-1.x, calling R's gc() is the only known workaround, I think.


##---


#
# brutal and naive strategy for model selection:
#   fit all possible two-variable models
#
# The purpose is of this is code to try reproducing
# an elusive bug when iteratively fitting a lot of models.
#
# Here, we are iterating nvariable * (nvariables-1) times.
#

import rpy2.robjects as ro
import array
import random

# build pool of variables
nvariables = 75
variables = {}
for v_i in range(nvariables):
    a_i = array.array('f', [random.random() for i in xrange(1000)])
    rv_i = ro.RVector(a_i)
    variables['v%i' %v_i] = rv_i

# create a dummy response variable
y = variables['v1'].r + variables['v2']


# fit all pairwise combinations
dataframe = ro.r['data.frame']
lm = ro.r['lm']

res = []
for v1_i in range(nvariables):
    for v2_i in xrange(v1_i+1):
        subvarnames = ['v%i' %x for x in [v1_i, v2_i]]
        subvar = dict([(x, variables[x]) for x in subvarnames])
        subvar['y'] = y
        dataf = dataframe(**subvar)
        fit = lm('y ~ %s + %s' %(subvarnames[0], subvarnames[1]),
                 data=dataf)
        sumfit = ro.r.summary(fit)
        rsq = sumfit.r['adj.r.squared'][0][0]

        res.append((v1_i, v2_i, rsq))

## check R2 == 1 for the pair (v1, v2)
[x for x in res if x[2] == 1]




L.






2008/7/18 Laurent Gautier <[EMAIL PROTECTED]>:
> 2008/7/18 Laurent Gautier <[EMAIL PROTECTED]>:
>> 2008/7/17 laurent oget <[EMAIL PROTECTED]>:
>>>
>>>
>>> 2008/7/17 Laurent Gautier <[EMAIL PROTECTED]>:
>>>>
>
>> It might not really be a race condition, but more an overzealous
>> garbage collection.
>> R does not have reference counting, and objects without an associated
>> symbol/name
>> in the R space can be flagged as "protected" from garbage collection.
>> The removal of
>> the protection is recursive, I think,
>
> Just a work of caution: I I might not be thinking right. After
> checking R's source, I am
> not sure that contained elements in a "preserved" container are
> recursively unprotected.
> There is more that I do not know about R's memory management than I thought...
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to