{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Computing phi w/ pyphi\n", "Date: May. 11th \n", "Author: take.sei \n", "c.f. http://pyphi.readthedocs.io/en/stable/index.html" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pyphi" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# define network using tpm and connectivity matrix(optional).\n", "# docs for Network: http://pyphi.readthedocs.io/en/stable/api/network.html#pyphi.network.Network\n", "tpm = np.array([\n", " [0, 0, 0],\n", " [0, 0, 1],\n", " [1, 0, 1],\n", " [1, 0, 0],\n", " [1, 1, 0],\n", " [1, 1, 1],\n", " [1, 1, 1],\n", " [1, 1, 0]\n", "])\n", "\n", "cm = np.array([\n", " [0, 0, 1],\n", " [1, 0, 1],\n", " [1, 1, 0]\n", "])\n", "\n", "labels = (\"A\", \"B\", \"C\") # labels makes outputs easier\n", "\n", "network = pyphi.Network(tpm, cm=cm, node_labels=labels) # 3-node net." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# Define a subsystem. Use network and its state, indices of nodes subset.\n", "state = 1, 0, 0\n", "node_indices = 0, 1, 2\n", "\n", "subsystem = pyphi.Subsystem(network, state, node_indices)\n", "# labels can be used instead of indices.\n", "# pyphi.Subsystem(network, state, (\"B\", \"C\"))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [] }, { "data": { "text/plain": [ "2.3125" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# compute the phi of subsystem.\n", "pyphi.compute.phi(subsystem)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [] }, { "data": { "text/plain": [ "┌──────────────────────────────────────────────────────────────┐\n", "│ System irreducibility analysis: Φ = 37/16 │\n", "│ Cut [B, C] ━━/ /━━➤ [A] │\n", "│ Subsystem(A, B, C) │\n", "│ ════════════════════════════════════════════════════════════ │\n", "│ Cause-effect structure (4 concepts) │\n", "│ ════════════════════════════════════════════════════════════ │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ Concept: Mechanism = [B], φ = 1/4 │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ MIC MIE │\n", "│ ┌──────────────────────────┐┌──────────────────────────┐ │\n", "│ │ φ = 1/2 ││ φ = 1/4 │ │\n", "│ │ Purview = [C] ││ Purview = [A] │ │\n", "│ │ MIP: ││ MIP: │ │\n", "│ │ ∅ B ││ ∅ B │ │\n", "│ │ ─── ✕ ─── ││ ─── ✕ ─── │ │\n", "│ │ C ∅ ││ A ∅ │ │\n", "│ │ Repertoire: ││ Repertoire: │ │\n", "│ │ ┌────────────┐ ││ ┌────────────┐ │ │\n", "│ │ │ S P(S) │ ││ │ S P(S) │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴ │ ││ │ ╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ 0 1 │ ││ │ 0 1/2 │ │ │\n", "│ │ │ 1 0 │ ││ │ 1 1/2 │ │ │\n", "│ │ └────────────┘ ││ └────────────┘ │ │\n", "│ │ Partitioned repertoire: ││ Partitioned repertoire: │ │\n", "│ │ ┌────────────┐ ││ ┌────────────┐ │ │\n", "│ │ │ S P(S) │ ││ │ S P(S) │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴ │ ││ │ ╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ 0 1/2 │ ││ │ 0 1/4 │ │ │\n", "│ │ │ 1 1/2 │ ││ │ 1 3/4 │ │ │\n", "│ │ └────────────┘ ││ └────────────┘ │ │\n", "│ └──────────────────────────┘└──────────────────────────┘ │\n", "│ │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ Concept: Mechanism = [C], φ = 1/2 │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ MIC MIE │\n", "│ ┌──────────────────────────┐┌──────────────────────────┐ │\n", "│ │ φ = 1/2 ││ φ = 1/2 │ │\n", "│ │ Purview = [A, B] ││ Purview = [B] │ │\n", "│ │ MIP: ││ MIP: │ │\n", "│ │ ∅ C ││ ∅ C │ │\n", "│ │ ─── ✕ ─── ││ ─── ✕ ─── │ │\n", "│ │ A B ││ B ∅ │ │\n", "│ │ Repertoire: ││ Repertoire: │ │\n", "│ │ ┌─────────────┐ ││ ┌────────────┐ │ │\n", "│ │ │ S P(S) │ ││ │ S P(S) │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴╴ │ ││ │ ╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ 00 1/2 │ ││ │ 0 1 │ │ │\n", "│ │ │ 10 0 │ ││ │ 1 0 │ │ │\n", "│ │ │ 01 0 │ ││ └────────────┘ │ │\n", "│ │ │ 11 1/2 │ ││ Partitioned repertoire: │ │\n", "│ │ └─────────────┘ ││ ┌────────────┐ │ │\n", "│ │ Partitioned repertoire: ││ │ S P(S) │ │ │\n", "│ │ ┌─────────────┐ ││ │ ╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ S P(S) │ ││ │ 0 1/2 │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴╴ │ ││ │ 1 1/2 │ │ │\n", "│ │ │ 00 1/4 │ ││ └────────────┘ │ │\n", "│ │ │ 10 1/4 │ │└──────────────────────────┘ │\n", "│ │ │ 01 1/4 │ │ │\n", "│ │ │ 11 1/4 │ │ │\n", "│ │ └─────────────┘ │ │\n", "│ └──────────────────────────┘ │\n", "│ │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ Concept: Mechanism = [A, B], φ = 1/3 │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ MIC MIE │\n", "│ ┌──────────────────────────┐┌──────────────────────────┐ │\n", "│ │ φ = 1/3 ││ φ = 1/2 │ │\n", "│ │ Purview = [B, C] ││ Purview = [C] │ │\n", "│ │ MIP: ││ MIP: │ │\n", "│ │ A B ││ ∅ A,B │ │\n", "│ │ ─── ✕ ─── ││ ─── ✕ ─── │ │\n", "│ │ B C ││ C ∅ │ │\n", "│ │ Repertoire: ││ Repertoire: │ │\n", "│ │ ┌─────────────┐ ││ ┌────────────┐ │ │\n", "│ │ │ S P(S) │ ││ │ S P(S) │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴╴ │ ││ │ ╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ 00 0 │ ││ │ 0 0 │ │ │\n", "│ │ │ 10 1 │ ││ │ 1 1 │ │ │\n", "│ │ │ 01 0 │ ││ └────────────┘ │ │\n", "│ │ │ 11 0 │ ││ Partitioned repertoire: │ │\n", "│ │ └─────────────┘ ││ ┌────────────┐ │ │\n", "│ │ Partitioned repertoire: ││ │ S P(S) │ │ │\n", "│ │ ┌─────────────┐ ││ │ ╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ S P(S) │ ││ │ 0 1/2 │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴╴ │ ││ │ 1 1/2 │ │ │\n", "│ │ │ 00 1/3 │ ││ └────────────┘ │ │\n", "│ │ │ 10 2/3 │ │└──────────────────────────┘ │\n", "│ │ │ 01 0 │ │ │\n", "│ │ │ 11 0 │ │ │\n", "│ │ └─────────────┘ │ │\n", "│ └──────────────────────────┘ │\n", "│ │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ Concept: Mechanism = [A, B, C], φ = 1/2 │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ MIC MIE │\n", "│ ┌──────────────────────────┐┌──────────────────────────┐ │\n", "│ │ φ = 1/2 ││ φ = 1/2 │ │\n", "│ │ Purview = [A, B, C] ││ Purview = [A, B, C] │ │\n", "│ │ MIP: ││ MIP: │ │\n", "│ │ ∅ A,B,C ││ ∅ A,B,C │ │\n", "│ │ ─── ✕ ───── ││ ─── ✕ ───── │ │\n", "│ │ A B,C ││ B A,C │ │\n", "│ │ Repertoire: ││ Repertoire: │ │\n", "│ │ ┌──────────────┐ ││ ┌──────────────┐ │ │\n", "│ │ │ S P(S) │ ││ │ S P(S) │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴╴╴ │ ││ │ ╴╴╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ 000 0 │ ││ │ 000 0 │ │ │\n", "│ │ │ 100 0 │ ││ │ 100 0 │ │ │\n", "│ │ │ 010 0 │ ││ │ 010 0 │ │ │\n", "│ │ │ 110 1 │ ││ │ 110 0 │ │ │\n", "│ │ │ 001 0 │ ││ │ 001 1 │ │ │\n", "│ │ │ 101 0 │ ││ │ 101 0 │ │ │\n", "│ │ │ 011 0 │ ││ │ 011 0 │ │ │\n", "│ │ │ 111 0 │ ││ │ 111 0 │ │ │\n", "│ │ └──────────────┘ ││ └──────────────┘ │ │\n", "│ │ Partitioned repertoire: ││ Partitioned repertoire: │ │\n", "│ │ ┌──────────────┐ ││ ┌──────────────┐ │ │\n", "│ │ │ S P(S) │ ││ │ S P(S) │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴╴╴ │ ││ │ ╴╴╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ 000 0 │ ││ │ 000 0 │ │ │\n", "│ │ │ 100 0 │ ││ │ 100 0 │ │ │\n", "│ │ │ 010 1/2 │ ││ │ 010 0 │ │ │\n", "│ │ │ 110 1/2 │ ││ │ 110 0 │ │ │\n", "│ │ │ 001 0 │ ││ │ 001 1/2 │ │ │\n", "│ │ │ 101 0 │ ││ │ 101 0 │ │ │\n", "│ │ │ 011 0 │ ││ │ 011 1/2 │ │ │\n", "│ │ │ 111 0 │ ││ │ 111 0 │ │ │\n", "│ │ └──────────────┘ ││ └──────────────┘ │ │\n", "│ └──────────────────────────┘└──────────────────────────┘ │\n", "│ │\n", "│ ════════════════════════════════════════════════════════════ │\n", "│ Partitioned cause-effect structure (1 concept) │\n", "│ ════════════════════════════════════════════════════════════ │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ Concept: Mechanism = [C], φ = 1/2 │\n", "│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │\n", "│ MIC MIE │\n", "│ ┌──────────────────────────┐┌──────────────────────────┐ │\n", "│ │ φ = 1/2 ││ φ = 1/2 │ │\n", "│ │ Purview = [A, B] ││ Purview = [B] │ │\n", "│ │ MIP: ││ MIP: │ │\n", "│ │ ∅ C ││ ∅ C │ │\n", "│ │ ─── ✕ ─── ││ ─── ✕ ─── │ │\n", "│ │ A B ││ B ∅ │ │\n", "│ │ Repertoire: ││ Repertoire: │ │\n", "│ │ ┌─────────────┐ ││ ┌────────────┐ │ │\n", "│ │ │ S P(S) │ ││ │ S P(S) │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴╴ │ ││ │ ╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ 00 1/2 │ ││ │ 0 1 │ │ │\n", "│ │ │ 10 0 │ ││ │ 1 0 │ │ │\n", "│ │ │ 01 0 │ ││ └────────────┘ │ │\n", "│ │ │ 11 1/2 │ ││ Partitioned repertoire: │ │\n", "│ │ └─────────────┘ ││ ┌────────────┐ │ │\n", "│ │ Partitioned repertoire: ││ │ S P(S) │ │ │\n", "│ │ ┌─────────────┐ ││ │ ╴╴╴╴╴╴╴╴╴╴ │ │ │\n", "│ │ │ S P(S) │ ││ │ 0 1/2 │ │ │\n", "│ │ │ ╴╴╴╴╴╴╴╴╴╴╴ │ ││ │ 1 1/2 │ │ │\n", "│ │ │ 00 1/4 │ ││ └────────────┘ │ │\n", "│ │ │ 10 1/4 │ │└──────────────────────────┘ │\n", "│ │ │ 01 1/4 │ │ │\n", "│ │ │ 11 1/4 │ │ │\n", "│ │ └─────────────┘ │ │\n", "│ └──────────────────────────┘ │\n", "│ │\n", "│ │\n", "└──────────────────────────────────────────────────────────────┘" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# when you want to take deeper info, use sia()\n", "sia = pyphi.compute.sia(subsystem)\n", "sia" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }