{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Supreme court: Analysis in the best basis" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Imports\n", "import numpy as np\n", "from mcmpy import Data, MCM, MCMSearch, Basis, BasisSearch" ] }, { "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": [ "# Search objects\n", "basis_searcher = BasisSearch()\n", "mcm_searcher = MCMSearch()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Search for the best basis representation" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Operator 1: \t000100100\t Indices: 3\t6\t\n", "Operator 2: \t000001010\t Indices: 5\t7\t\n", "Operator 3: \t000000011\t Indices: 7\t8\t\n", "Operator 4: \t100010000\t Indices: 0\t4\t\n", "Operator 5: \t100000100\t Indices: 0\t6\t\n", "Operator 6: \t101000000\t Indices: 0\t2\t\n", "Operator 7: \t010000010\t Indices: 1\t7\t\n", "Operator 8: \t001000001\t Indices: 2\t8\t\n", "Operator 9: \t000000100\t Indices: 6\t\n" ] } ], "source": [ "# The system is small enough to perform an exhaustive search\n", "opt_basis = basis_searcher.exhaustive(data)\n", "opt_basis.print_details()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Entropy of operator 0 :\t 0.25176\n", "Entropy of operator 1 :\t 0.32138\n", "Entropy of operator 2 :\t 0.37267\n", "Entropy of operator 3 :\t 0.37486\n", "Entropy of operator 4 :\t 0.38776\n", "Entropy of operator 5 :\t 0.41832\n", "Entropy of operator 6 :\t 0.44482\n", "Entropy of operator 7 :\t 0.52134\n", "Entropy of operator 8 :\t 0.58803\n" ] } ], "source": [ "# These operators are ranked from low to high entropy\n", "for i in range(n):\n", " # Take the ith column of the matrix\n", " spin_op_i = opt_basis.matrix[:,i]\n", " print(\"Entropy of operator\", i, \":\\t\", np.round(data.entropy_of_spin_operator(spin_op_i), 5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Basis transformation" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "transformed_data = opt_basis.gauge_transform_data(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Search for the optimal MCM" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "MCM contains 9 variables divided into 3 components\n", "Total log-evidence: -3154.42\n", "Component 0 : \t100000000\t Size: 1\t Log-evidence: -228.947\n", "Component 1 : \t011000100\t Size: 3\t Log-evidence: -970.39\n", "Component 2 : \t000111011\t Size: 5\t Log-evidence: -1955.08\n" ] } ], "source": [ "# The system is small enough to perform an exhaustive search\n", "opt_mcm = mcm_searcher.exhaustive(transformed_data)\n", "opt_mcm.print_details()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Analysis\n", "\n", "##### Log-evidence" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The log-evidence of the complete model: -3305.546575913697\n", "The log-evidence of the independent model: -3327.0799458467227\n", "The log-evidence of the optimal MCM: -3154.421230299753\n" ] } ], "source": [ "print(\"The log-evidence of the complete model: \", transformed_data.log_evidence(MCM(n, \"complete\")))\n", "print(\"The log-evidence of the independent model: \", transformed_data.log_evidence(MCM(n, \"independent\")))\n", "\n", "print(\"The log-evidence of the optimal MCM: \", transformed_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 }