{"action":"created","issue":{"url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1420","repository_url":"https://api.github.com/repos/pymc-devs/pymc3","labels_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1420/labels{/name}","comments_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1420/comments","events_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1420/events","html_url":"https://github.com/pymc-devs/pymc3/issues/1420","id":180508183,"number":1420,"title":"NUTS sampler needs more than 6 GB RAM on model with just 26 unkowns","user":{"login":"bjornsing","id":3122051,"avatar_url":"https://avatars.githubusercontent.com/u/3122051?v=3","gravatar_id":"","url":"https://api.github.com/users/bjornsing","html_url":"https://github.com/bjornsing","followers_url":"https://api.github.com/users/bjornsing/followers","following_url":"https://api.github.com/users/bjornsing/following{/other_user}","gists_url":"https://api.github.com/users/bjornsing/gists{/gist_id}","starred_url":"https://api.github.com/users/bjornsing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjornsing/subscriptions","organizations_url":"https://api.github.com/users/bjornsing/orgs","repos_url":"https://api.github.com/users/bjornsing/repos","events_url":"https://api.github.com/users/bjornsing/events{/privacy}","received_events_url":"https://api.github.com/users/bjornsing/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-02T11:37:08Z","updated_at":"2016-10-02T17:52:52Z","closed_at":null,"body":"I'm trying to build a relatively simple model in pymc3 (version 3.0rc1) but my script (see below) hangs when instantiating the NUTS sampler. Top tells me it's because the python process needs more than 5.9 GB RAM, starts paging to disk and grinds to a halt. To me this seems like an extraordinary amount of memory given that the model contains only 26 unknowns.\r\n\r\nThe code:\r\n```\r\nimport numpy as np\r\nimport theano\r\nassert(theano.config.device == 'cpu'), \"This code should probably run on the cpu...\"\r\nassert(theano.config.floatX == 'float64'), \"This code need double precision floats...\"\r\nfrom pymc3 import Model, Uniform, Normal, Gamma, StudentT\r\n\r\n# Length of core in cm:\r\nL = 100\r\n\r\n# Radiocarbon dates (depth in cm and age in years):\r\nRCDs = [{'depth': 45.0, 'age': 3200.0, 'sd': 130},\r\n        {'depth': 60.0, 'age': 5700.0, 'sd': 130},\r\n        {'depth': 90.0, 'age': 7500.0, 'sd': 130},]\r\n\r\n# Number of segments:\r\nK = 25\r\n\r\n# Year core was retrieved:\r\nA = 2016\r\n\r\n# MODEL SETUP - Essentially and attempt to implement https://projecteuclid.org/euclid.ba/1339616472\r\n\r\n# Standard deviation in top layer age:\r\nsigma_A = 10\r\n\r\n# Gamma parameters:\r\n# TBD: Shouldn't these parameters be \"learnt\" from the data?\r\na_alpha = 2\r\nb_alpha = 2.0/1.1\r\n\r\nbacon_model = Model()\r\n\r\nwith bacon_model:\r\n    \r\n    # TBD: Shouldn't this be a truncated normal distribution?\r\n    theta = Normal('theta', mu=A, sd=sigma_A)\r\n    \r\n    # TODO: It seems prior on w shouldn't be uniform, but what should it be...?\r\n    w = Uniform('w', lower=0.0, upper=1.0)\r\n    \r\n    alpha = [Gamma('a_' + str(j), alpha=a_alpha, beta=b_alpha) for j in range(K)]\r\n    \r\n    def x(j):\r\n        if j <= K:\r\n            return w * x(j+1) + (1.0 - w) * alpha[j - 1]\r\n        else:\r\n            # TBD: Is this correct...?\r\n            return 0\r\n    \r\n    delta_c = float(L)/float(K)\r\n    \r\n    def t(z):\r\n        depth = 0\r\n        age   = theta\r\n        \r\n        j = 1\r\n        while depth < (z - delta_c):\r\n            depth += delta_c\r\n            age   += x(j) * delta_c\r\n            j     += 1\r\n    \r\n        age += x(j) * (z - depth)\r\n        \r\n        return age\r\n    \r\n    for RCD in RCDs:\r\n        # TODO: Switch from Normal to StudentT...\r\n        RCD['variable'] = Normal('RCD_' + str(RCD['depth']), mu=t(RCD['depth']), sd=RCD['sd'], observed=RCD['age'])\r\n\r\n# INFERENCE - Copy-pasted from https://peerj.com/preprints/1686.pdf\r\n\r\nfrom scipy import optimize\r\nfrom pymc3 import find_MAP, NUTS, sample\r\nimport datetime\r\n\r\nwith bacon_model:\r\n    \r\n    print \"*** Finding MAP (%s) ***\" % datetime.datetime.now()\r\n    \r\n    start = find_MAP(fmin=optimize.fmin_powell)\r\n\r\n    print \"MAP:\", start\r\n    \r\n    print \"*** Instantiating NUTS sampler (%s) ***\" % datetime.datetime.now()\r\n\r\n    step = NUTS(scaling=start)\r\n\r\n    # NOT REACHED,\r\n    # because NUTS._init_ seems to need more than 5.9 GB RAM and system starts swapping...\r\n    #\r\n    # Relevant output line from top:\r\n    #   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND\r\n    # 26290 xxxxx     20   0 10.233g 5.901g   2600 D  12.6 76.8  48:50.91 python\r\n    \r\n    print \"*** Ready to sample (%s) ***\" % datetime.datetime.now()\r\n    \r\n    trace = sample(2000, step, start=start)\r\n\r\n    print \"*** Done sampling (%s) ***\" % datetime.datetime.now()\r\n```\r\nSince I've never managed to run the model it may not be correct, but in any case I find it rather strange that it needs so much memory.\r\n\r\nThe version of pymc3 I'm using:\r\n```\r\n$ pip show pymc3\r\n---\r\nMetadata-Version: 2.0\r\nName: pymc3\r\nVersion: 3.0rc1\r\nSummary: PyMC3\r\nHome-page: http://github.com/pymc-devs/pymc\r\nAuthor: Thomas Wiecki\r\nAuthor-email: thomas.wiecki@gmail.com\r\nInstaller: pip\r\nLicense: Apache License, Version 2.0\r\nLocation: /home/coach/local/miniconda2/lib/python2.7/site-packages\r\nRequires: nbsphinx, CommonMark, joblib, numpy, patsy, sphinx, pandas, scipy, numpydoc, matplotlib, theano, recommonmark\r\nClassifiers:\r\n  Development Status :: 5 - Production/Stable\r\n  Programming Language :: Python\r\n  Programming Language :: Python :: 2\r\n  Programming Language :: Python :: 3\r\n  Programming Language :: Python :: 2.7\r\n  Programming Language :: Python :: 3.4\r\n  Programming Language :: Python :: 3.5\r\n  License :: OSI Approved :: Apache Software License\r\n  Intended Audience :: Science/Research\r\n  Topic :: Scientific/Engineering\r\n  Topic :: Scientific/Engineering :: Mathematics\r\n  Operating System :: OS Independent\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pymc-devs/pymc3/issues/comments/250984659","html_url":"https://github.com/pymc-devs/pymc3/issues/1420#issuecomment-250984659","issue_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1420","id":250984659,"user":{"login":"bjornsing","id":3122051,"avatar_url":"https://avatars.githubusercontent.com/u/3122051?v=3","gravatar_id":"","url":"https://api.github.com/users/bjornsing","html_url":"https://github.com/bjornsing","followers_url":"https://api.github.com/users/bjornsing/followers","following_url":"https://api.github.com/users/bjornsing/following{/other_user}","gists_url":"https://api.github.com/users/bjornsing/gists{/gist_id}","starred_url":"https://api.github.com/users/bjornsing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjornsing/subscriptions","organizations_url":"https://api.github.com/users/bjornsing/orgs","repos_url":"https://api.github.com/users/bjornsing/repos","events_url":"https://api.github.com/users/bjornsing/events{/privacy}","received_events_url":"https://api.github.com/users/bjornsing/received_events","type":"User","site_admin":false},"created_at":"2016-10-02T17:52:52Z","updated_at":"2016-10-02T17:52:52Z","body":"You're more than welcome!\r\n\r\nfind_MAP takes about 20 min on my machine (intel core i7 something)."}}
{"actor":{"display_login":"bjornsing"}}