René's URL Explorer Experiment


Title: Problem to reproduce Figure 1.5 · Issue #211 · BayesianModelingandComputationInPython/BookCode_Edition1 · GitHub

Open Graph Title: Problem to reproduce Figure 1.5 · Issue #211 · BayesianModelingandComputationInPython/BookCode_Edition1

X Title: Problem to reproduce Figure 1.5 · Issue #211 · BayesianModelingandComputationInPython/BookCode_Edition1

Description: Hello, I'm trying to reproduce the figure 1.5 from the book but since Pymc current version is different from the book, I'm struggling. My problem is with the Prior and Posterior predictive distribution (2nd and 4th graphs). I have define...

Open Graph Description: Hello, I'm trying to reproduce the figure 1.5 from the book but since Pymc current version is different from the book, I'm struggling. My problem is with the Prior and Posterior predictive distribu...

X Description: Hello, I'm trying to reproduce the figure 1.5 from the book but since Pymc current version is different from the book, I'm struggling. My problem is with the Prior and Posterior predictive ...

Opengraph URL: https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Problem to reproduce Figure 1.5","articleBody":"Hello,\r\nI'm trying to reproduce the figure 1.5 from the book but since Pymc current version is different from the book, I'm struggling.\r\nMy problem is with the Prior and Posterior predictive distribution (2nd and 4th graphs).\r\n\r\nI have defined the model as in the book:\r\n\r\n```\r\nimport numpy as np\r\nimport pymc as pm\r\nimport matplotlib.pyplot as plt\r\nimport pandas as pd\r\nimport scipy\r\nimport scipy.stats as stats\r\nimport arviz as az\r\n\r\naz.style.use(\"arviz-grayscale\")\r\nplt.rcParams['figure.dpi'] = 300\r\nnp.random.seed(521)\r\nviridish = [(0.2823529411764706, 0.11372549019607843, 0.43529411764705883, 1.0),\r\n            (0.1450980392156863, 0.6705882352941176, 0.5098039215686274, 1.0),\r\n            (0.6901960784313725, 0.8666666666666667, 0.1843137254901961, 1.0)]\r\n\r\nY = stats.bernoulli(0.7).rvs(20)\r\n# Declare a model in PyMC3\r\nwith pm.Model() as model:\r\n    # Specify the prior distribution of unknown parameter\r\n    θ = pm.Beta(\"θ\", alpha=1, beta=1)\r\n\r\n    # Specify the likelihood distribution and condition on the observed data\r\n    y_obs = pm.Binomial(\"y_obs\", n=1, p=θ, observed=Y)\r\n\r\n    # Sample from the posterior distribution\r\n    idata = pm.sample(1000, return_inferencedata=True)\r\n\r\npred_dists = (pm.sample_prior_predictive(1000, model=model),\r\n              pm.sample_posterior_predictive(idata,model=model))\r\n```\r\nAnd next I separate the variables I want to plot:\r\n\r\n```\r\n# Prior\r\nprior_samples = pred_dists[0]['prior']['θ'].values # Prior observed\r\nprior_pred_samples = pred_dists[0]['prior_predictive'] # Prior predictions\r\n\r\n# Posterior\r\npost_distribution = idata.posterior[\"θ\"] # Posterior observed\r\nposterior_pred_samples = pred_dists[1]['posterior_predictive'] # Posterior Predictions\r\n\r\nposterior_pred_graph = posterior_pred_samples['y_obs'].sum(dim=['draw','chain'])\r\nprior_pred_samples_graph = prior_pred_samples['y_obs'].sum(dim=['draw','chain'])\r\n\r\nfig,axes =plt.subplots(4,1,gridspec_kw={'hspace': 0.1})\r\n\r\naz.plot_dist(prior_samples, plot_kwargs={\"color\":\"0.5\"},\r\n             fill_kwargs={'alpha':1}, ax=axes[0])\r\naxes[0].set_title(\"Prior distribution\", fontweight='bold',fontsize=10)\r\naxes[0].set_xlim(0, 1)\r\naxes[0].set_ylim(0, 4)\r\naxes[0].tick_params(axis='both', pad=7)\r\naxes[0].set_xlabel(\"θ\")\r\n\r\n\r\naz.plot_dist(prior_pred_samples_graph, plot_kwargs={\"color\":\"0.5\"},\r\n             fill_kwargs={'alpha':1}, ax=axes[1])\r\naxes[1].set_title(\"Prior predictive distribution\", fontweight='bold',fontsize=10)\r\n# axes[1].set_xlim(-1, 21)\r\n# axes[1].set_ylim(0, 0.15)\r\naxes[1].tick_params(axis='both', pad=7)\r\naxes[1].set_xlabel(\"number of success\")\r\n\r\naz.plot_dist(post_distribution, plot_kwargs={\"color\":\"0.5\"},\r\n             fill_kwargs={'alpha':1},ax=axes[2])\r\naxes[2].set_title(\"Posterior distribution\", fontweight='bold',fontsize=10)\r\naxes[2].set_xlim(0, 1)\r\naxes[2].set_ylim(0, 5)\r\naxes[2].tick_params(axis='both', pad=7)\r\naxes[2].set_xlabel(\"θ\")\r\n\r\naz.plot_dist(posterior_pred_graph, plot_kwargs={\"color\":\"0.5\"},\r\n             fill_kwargs={'alpha':1}, ax=axes[3])\r\naxes[3].set_title(\"Posterior predictive distribution\", fontweight='bold',fontsize=10)\r\n# axes[3].set_xlim(-1, 21)\r\n# axes[3].set_ylim(0, 0.15)\r\naxes[3].tick_params(axis='both', pad=7)\r\naxes[3].set_xlabel(\"number of success\") ```\r\n\r\n![img](https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/assets/42352209/9d24af6a-2fd3-4a48-9b96-49822ae005d7)\r\n\r\n\r\n\r\nAnd I guess I'm not evaluating the posterior_pred_graph and prior_pred_samples_graph correctly? shouldn't be this sum? Could someone help me on this?","author":{"url":"https://github.com/jc-barreto","@type":"Person","name":"jc-barreto"},"datePublished":"2023-08-07T15:46:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/211/BookCode_Edition1/issues/211"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:764d1bd2-4087-ff4a-7313-7b0cb32eae2b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8E50:C6FAD:15909:1CB75:698F9660
html-safe-nonce020bf398fd5d4bbc73d3db558b1adb608adbc504124cac8cb4638e9f3def38a3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTUwOkM2RkFEOjE1OTA5OjFDQjc1OjY5OEY5NjYwIiwidmlzaXRvcl9pZCI6IjcwMzE0OTM5NDY1MDE5OTQwODAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8b1156408b1933a14c309032c3a3dcb499a28e743c7331ba4548c9554867141a
hovercard-subject-tagissue:1839758459
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/BayesianModelingandComputationInPython/BookCode_Edition1/211/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f67c2bfe1d8364b909c74ebbaaf2580c0973bf20c40abe2b431f4443b8aabfba/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f67c2bfe1d8364b909c74ebbaaf2580c0973bf20c40abe2b431f4443b8aabfba/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211
og:image:altHello, I'm trying to reproduce the figure 1.5 from the book but since Pymc current version is different from the book, I'm struggling. My problem is with the Prior and Posterior predictive distribu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejc-barreto
hostnamegithub.com
expected-hostnamegithub.com
None5f47eb8d0aaafbfcb6a8220a40bd81431acf688857c575e6489670c394cfa36f
turbo-cache-controlno-preview
go-importgithub.com/BayesianModelingandComputationInPython/BookCode_Edition1 git https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1.git
octolytics-dimension-user_id84690770
octolytics-dimension-user_loginBayesianModelingandComputationInPython
octolytics-dimension-repository_id397286760
octolytics-dimension-repository_nwoBayesianModelingandComputationInPython/BookCode_Edition1
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id397286760
octolytics-dimension-repository_network_root_nwoBayesianModelingandComputationInPython/BookCode_Edition1
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release09a8136f6e8f8fd3078d54ce5f8b7adb493d44a7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FBayesianModelingandComputationInPython%2FBookCode_Edition1%2Fissues%2F211
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FBayesianModelingandComputationInPython%2FBookCode_Edition1%2Fissues%2F211
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=BayesianModelingandComputationInPython%2FBookCode_Edition1
Reloadhttps://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211
Reloadhttps://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211
Reloadhttps://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211
BayesianModelingandComputationInPython https://github.com/BayesianModelingandComputationInPython
BookCode_Edition1https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1
Please reload this pagehttps://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211
Notifications https://github.com/login?return_to=%2FBayesianModelingandComputationInPython%2FBookCode_Edition1
Fork 153 https://github.com/login?return_to=%2FBayesianModelingandComputationInPython%2FBookCode_Edition1
Star 562 https://github.com/login?return_to=%2FBayesianModelingandComputationInPython%2FBookCode_Edition1
Code https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1
Issues 43 https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues
Pull requests 2 https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/pulls
Actions https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/actions
Projects 0 https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/projects
Security 0 https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/security
Insights https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/pulse
Code https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1
Issues https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues
Pull requests https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/pulls
Actions https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/actions
Projects https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/projects
Security https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/security
Insights https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/pulse
New issuehttps://github.com/login?return_to=https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211
New issuehttps://github.com/login?return_to=https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211
Problem to reproduce Figure 1.5https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211#top
https://github.com/jc-barreto
https://github.com/jc-barreto
jc-barretohttps://github.com/jc-barreto
on Aug 7, 2023https://github.com/BayesianModelingandComputationInPython/BookCode_Edition1/issues/211#issue-1839758459
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.