python statsmodel WLS memory / gc" leak"在n = 1024边界

时间:2015-05-30 06:57:29

标签: python memory-leaks garbage-collection statsmodels

我使用循环运行作业,每个循环调用statsmodels.api.WLS(版本0.6.1)几次。似乎statsmodels尽管我最好的尝试拒绝放弃记忆并最终占用我的所有记忆(32Gb)。我编写了以下示例代码来演示此问题。

有趣的是,如果问题的维度在1024(n = <1024)之内,则没有问题。 但是,如果n&gt; = 1025,则此脚本的内存使用量会线性增加而不会受到限制。在statsmodel.api中看起来像是一个错误,但可能是我对python的不了解。

(交叉发布于:https://github.com/statsmodels/statsmodels/issues/2428

#!/usr/bin/python

import resource
import numpy as np
import statsmodels.api as sm

if __name__ == "__main__":
    n = 1025
    mu, sigma = 0.0, 1.0
    i = 0
    print('i,memory')
    while True:
        x = np.random.normal(mu, sigma, n)
        y = np.random.normal(mu, sigma, n)
        w = np.random.random(n)
        w /= w.sum()
        regr1 = sm.WLS(y, x, w)
        print(`i` + ',' + `resource.getrusage(resource.RUSAGE_SELF).ru_maxrss`)
        i+=1

前10个值n = 1024且n = 1025:

i   N_1024  N_1025
0   60680   60812
1   60680   60848
2   60816   60988
3   60816   60996
4   60816   61016
5   60816   61028
6   60816   61040
7   60816   61064
8   60816   61080
9   60816   61084
10  60816   61092

1 个答案:

答案 0 :(得分:0)

我升级到numpy 1.9.1(从1.7.1开始),问题自动消失