{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Supreme court: Analysis in the original basis" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Imports\n", "from mcmpy import Data, MCM, MCMSearch" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Initialization" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The dataset contains 895 datapoints, of which 128 different ones.\n" ] } ], "source": [ "# Data object\n", "\n", "n = 9 # Number of variables\n", "q = 2 # Number of states\n", "data = Data('../../input/US_SupremeCourt_n9_N895.dat', n, q)\n", "\n", "print(\"The dataset contains %i datapoints, of which %i different ones.\" %(data.N, data.N_unique))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# MCMSearch object\n", "searcher = MCMSearch()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Search for the optimal MCM" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "MCM contains 9 variables divided into 2 components\n", "Total log-evidence: -3300.4\n", "Component 0 : \t101110100\t Size: 5\t Log-evidence: -1754.41\n", "Component 1 : \t010001011\t Size: 4\t Log-evidence: -1545.98\n" ] } ], "source": [ "# The system is small enough to perform an exhaustive search\n", "opt_mcm = searcher.exhaustive(data)\n", "opt_mcm.print_details()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Analysis\n", "\n", "##### Log-evidence" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The log-evidence of the complete model: -3305.546575913696\n", "The log-evidence of the independent model: -5258.100240438084\n", "The log-evidence of the optimal MCM: -3300.395469673639\n" ] } ], "source": [ "# Writing the partition as a 1D gray code array\n", "print(\"The log-evidence of the complete model: \", data.log_evidence([0,0,0,0,0,0,0,0,0])) # All variables in component 0\n", "print(\"The log-evidence of the independent model: \", data.log_evidence([0,1,2,3,4,5,6,7,8])) # All variables in a different component\n", "\n", "print(\"The log-evidence of the optimal MCM: \", data.log_evidence(opt_mcm))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note** that it is advised to used MCM objects as input parameters as there is no check if a given array is a valid partition.
\n", "The same results can be obtained in the following way:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The log-evidence of the complete model: -3305.546575913696\n", "The log-evidence of the independent model: -5258.100240438084\n", "The log-evidence of the optimal MCM: -3300.395469673639\n" ] } ], "source": [ "print(\"The log-evidence of the complete model: \", data.log_evidence(MCM(n, \"complete\")))\n", "print(\"The log-evidence of the independent model: \", data.log_evidence(MCM(n, \"independent\")))\n", "\n", "print(\"The log-evidence of the optimal MCM: \", data.log_evidence(opt_mcm))" ] } ], "metadata": { "kernelspec": { "display_name": "mcm_discrete", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 4 }