From 4c339eb78b5e80fb0b4369508bc04851b348df04 Mon Sep 17 00:00:00 2001 From: Mirko Birbaumer <mirko.birbaumer@hslu.ch> Date: Mon, 14 Oct 2024 06:59:40 +0000 Subject: [PATCH] adapted smc monte carlo --- notebooks/Model Comparison/MC_2_1.ipynb | 37 ++++++++++--------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/notebooks/Model Comparison/MC_2_1.ipynb b/notebooks/Model Comparison/MC_2_1.ipynb index a774090..d66ef90 100644 --- a/notebooks/Model Comparison/MC_2_1.ipynb +++ b/notebooks/Model Comparison/MC_2_1.ipynb @@ -2,7 +2,9 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "tags": [] + }, "source": [ "# Bayes-Faktor für Münzwurf" ] @@ -20,20 +22,11 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 13, "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Matplotlib is building the font cache; this may take a moment.\n", - "WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.\n" - ] - } - ], + "outputs": [], "source": [ "%matplotlib inline\n", "import pymc as pm\n", @@ -49,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 14, "metadata": { "tags": [] }, @@ -126,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 12, "metadata": { "tags": [] }, @@ -135,13 +128,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "<xarray.DataArray 'log_marginal_likelihood' ()> Size: 8B\n", - "array(11.16)\n" + "11.16\n" ] } ], "source": [ - "print(np.round(np.exp(trace_smc_0.sample_stats[\"log_marginal_likelihood\"].mean() - trace_smc_1.sample_stats[\"log_marginal_likelihood\"].mean()),2))" + "BF_smc = np.exp(trace_smc_0.sample_stats[\"log_marginal_likelihood\"].mean() - trace_smc_1.sample_stats[\"log_marginal_likelihood\"].mean())\n", + "print(np.round(BF_smc.item(),2))" ] }, { @@ -158,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 15, "metadata": { "tags": [] }, @@ -229,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 16, "metadata": { "tags": [] }, @@ -238,13 +231,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "<xarray.DataArray 'log_marginal_likelihood' ()> Size: 8B\n", - "array(0.68)\n" + "11.21\n" ] } ], "source": [ - "print(np.round(np.exp(trace_BF_0.sample_stats[\"log_marginal_likelihood\"].mean() - trace_BF_1.sample_stats[\"log_marginal_likelihood\"].mean()),2))" + "BF_smc = np.exp(trace_smc_0.sample_stats[\"log_marginal_likelihood\"].mean() - trace_smc_1.sample_stats[\"log_marginal_likelihood\"].mean())\n", + "print(np.round(BF_smc.item(),2))" ] } ], -- GitLab