{"id":17202053,"url":"https://github.com/colcarroll/sampled","last_synced_at":"2025-04-13T21:11:11.794Z","repository":{"id":57463745,"uuid":"93004178","full_name":"ColCarroll/sampled","owner":"ColCarroll","description":"Decorator for PyMC3","archived":false,"fork":false,"pushed_at":"2021-06-11T02:53:57.000Z","size":12,"stargazers_count":50,"open_issues_count":2,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-12T00:02:59.085Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ColCarroll.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-01T01:32:37.000Z","updated_at":"2024-01-04T16:14:33.000Z","dependencies_parsed_at":"2022-09-14T16:40:48.523Z","dependency_job_id":null,"html_url":"https://github.com/ColCarroll/sampled","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fsampled","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fsampled/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fsampled/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fsampled/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ColCarroll","download_url":"https://codeload.github.com/ColCarroll/sampled/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782261,"owners_count":21160717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T02:13:31.690Z","updated_at":"2025-04-13T21:11:11.766Z","avatar_url":"https://github.com/ColCarroll.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"|Build Status| |Coverage Status|\n\n========\nsampled\n========\n\n\n*Decorator for reusable models in PyMC3*\n\nProvides syntactic sugar for reusable models with PyMC3.  This lets you separate creating a generative model from using the model.\n\nHere is an example of creating a model:\n::\n\n    import numpy as np\n    import pymc3 as pm\n    from sampled import sampled\n    import theano.tensor as tt\n\n    @sampled\n    def linear_model(X, y):\n        shape = X.shape\n        X = pm.Normal('X', mu=tt.mean(X, axis=0), sd=np.std(X, axis=0), shape=shape)\n        coefs = pm.Normal('coefs', mu=tt.zeros(shape[1]), sd=tt.ones(shape[1]), shape=shape[1])\n        pm.Normal('y', mu=tt.dot(X, coefs), sd=tt.ones(shape[0]), shape=shape[0])\n\nNow here is how to use the model:\n::\n\n    X = np.random.normal(size=(1000, 10))\n    w = np.random.normal(size=10)\n    y = X.dot(w) + np.random.normal(scale=0.1, size=1000)\n\n    with linear_model(X=X, y=y):\n        sampled_coefs = pm.sample(draws=1000, tune=500)\n\n    np.allclose(sampled_coefs.get_values('coefs').mean(axis=0), w, atol=0.1) # True\n\nYou can also use this to build graphical networks -- here is a continuous version of the `STUDENT` example from Koller and Friedman's \"Probabilistic Graphical Models\", chapter 3:\n::\n\n    import pymc3 as pm\n    from sampled import sampled\n    import theano.tensor as tt\n\n    @sampled\n    def student():\n        difficulty = pm.Beta('difficulty', alpha=5, beta=5)\n        intelligence = pm.Beta('intelligence', alpha=5, beta=5)\n        SAT = pm.Beta('SAT', alpha=20 * intelligence, beta=20 * (1 - intelligence))\n        grade_avg = 0.5 + 0.5 * tt.sqrt((1 - difficulty) * intelligence)\n        grade = pm.Beta('grade', alpha=20 * grade_avg, beta=20 * (1 - grade_avg))\n        recommendation = pm.Binomial('recommendation', n=1, p=0.7 * grade)\n\nObservations may be passed into any node, and we can observe how that changes posterior expectations:\n\n::\n\n    # no prior knowledge\n    with student():\n        prior = pm.sample(draws=1000, tune=500)\n\n    prior.get_values('recommendation').mean()  # 0.502\n\n    # 99th percentile SAT score --\u003e higher chance of a recommendation\n    with student(SAT=0.99):\n        good_sats = pm.sample(draws=1000, tune=500)\n\n    good_sats.get_values('recommendation').mean()  # 0.543\n\n    # A good grade in a hard class --\u003e very high chance of recommendation\n    with student(difficulty=0.99, grade=0.99):\n        hard_class_good_grade = pm.sample(draws=1000, tune=500)\n\n    hard_class_good_grade.get_values('recommendation').mean()  # 0.705\n\n\n**References**\n\n*  Koller, Daphne, and Nir Friedman. *Probabilistic graphical models: principles and techniques.* MIT press, 2009.\n\n.. |Build Status| image:: https://travis-ci.org/ColCarroll/sampled.svg?branch=master\n   :target: https://travis-ci.org/ColCarroll/sampled\n.. |Coverage Status| image:: https://coveralls.io/repos/github/ColCarroll/sampled/badge.svg?branch=master\n   :target: https://coveralls.io/github/ColCarroll/sampled?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolcarroll%2Fsampled","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolcarroll%2Fsampled","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolcarroll%2Fsampled/lists"}