Skip to content

Commit

Permalink
Deploying to gh-pages from @ cd95dd7 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneCmb committed Jul 4, 2024
1 parent f5b6e59 commit 14f5038
Show file tree
Hide file tree
Showing 52 changed files with 772 additions and 287 deletions.
Binary file not shown.
262 changes: 253 additions & 9 deletions _downloads/2a4afa62d27b153aa605e093f9600e6b/plot_sim_red_syn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
},
"outputs": [],
"source": [
"import numpy as np\n\nfrom hoi.metrics import Oinfo, GradientOinfo\n\nimport matplotlib.pyplot as plt\n\nnp.random.seed(42)\nplt.style.use(\"ggplot\")"
"import numpy as np\n\nfrom hoi.metrics import Oinfo, GradientOinfo\nfrom hoi.simulation import simulate_hoi_gauss\n\nimport matplotlib.pyplot as plt\n\nnp.random.seed(42)\nplt.style.use(\"ggplot\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Redundant and synergistic behavior\n\nIn this first part, we are going to create a random variable `x`, a network\ncomposed of three nodes (1, 2, 3). Then we need a function to estimate\nwhether the interactions between the three nodes are more redundant or more\nsynergistic. To estimate whether the interactions between the three nodes are\nredundant or # synergistic, we are gonig to use the\n:class:`hoi.metrics.Oinfo`. When the Oinfo is positive, it means that the\ninteractions are redundant and if the Oinfo is negative, the interactions are\nsynergistic.\n\n"
"## Redundant and synergistic behavior\n\nIn this first part, we are going to create a multivariate gaussian variable\n`x` with specific information patterns. Then we need a function to estimate\nwhether the interactions between the three nodes are more redundant or more\nsynergistic. To estimate whether the interactions between the three nodes are\nredundant or synergistic, we are gonig to use the\n:class:`hoi.metrics.Oinfo`. When the Oinfo is positive, it means that the\ninteractions are redundant and if the Oinfo is negative, the interactions are\nsynergistic.\n\n"
]
},
{
Expand All @@ -40,7 +40,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating redundant behavior\n\nThe redundancy means that the nodes (1, 2, 3) in the system `x` are receiving\nmultiple copies of the same information. A simple way to simulate redundancy\nconsists in taking the signal of one node, let's say the first one, and copy\nthis signal to the two other nodes.\n\n"
"### Simulating synergistic behavior\n\nIn gaussian multivariate data, it is possible to generate synergy and\nredundancy by setting the parameters of the covariance matrix. This is\nwhat can be done using the function\n:class:`hoi.simulation.simulate_hoi_gauss`, in the following way:\n\n"
]
},
{
Expand All @@ -51,7 +51,68 @@
},
"outputs": [],
"source": [
"# x = (n_samples, n_nodes)\nx = np.random.rand(1000, 3)\n\nx[:, 1] = x[:, 1] + x[:, 0] # 1 = 1 & 0\nx[:, 2] = x[:, 2] + x[:, 0] # 2 = 2 & 0"
"# x = (n_samples, n_nodes)\nx = simulate_hoi_gauss(\n target=False, n_samples=1000, triplet_character=\"synergy\"\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"compute hoi using the Oinfo\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"hoi = compute_hoi_beh(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Print HOI value\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(f\"HOI between nodes (1, 2, 3) : {hoi}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, the estimated HOI is negative which is the hallmark of\nsynergy when using the Oinfo. Be careful because some metrics are positive\nfor synergistic interactions.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating redundant behavior\n\nAs for the redundancy, we can generate three gaussian variables, presenting\nsynergistic behavior, using the funciton,\n:class:`hoi.simulation.simulate_hoi_gauss`, in the following way:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# x = (n_samples, n_nodes)\nx = simulate_hoi_gauss(\n target=False, n_samples=1000, triplet_character=\"redundancy\"\n)"
]
},
{
Expand Down Expand Up @@ -94,14 +155,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, the estimated HOI is positive which is the hallmark of\nredundancy when using the Oinfo. Be careful because some metrics are negative\nfor redundant interactions.\n\n"
"Now HOI is positive, therefore the interaction between the three nodes is\ndominated by redundancy.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating synergistic behavior\n\nA synergy is obtained when elements of a system work together to produce an\neffect that is greater than the sum of their individual contributions. A\nsimple example is the sum. When a variable `A` is defined as the sum of two\nother variables $A = B + C$ then we need both `B` and `C` to know `A`.\nThat's what we are going to use here to simulate synergy.\n\n"
"### Simulating synergistic behavior by sum operation\n\nA synergy is obtained when elements of a system work together to produce an\neffect that is greater than the sum of their individual contributions. A\nsimple example is the sum. When a variable `A` is defined as the sum of two\nother variables $A = B + C$ then we need both `B` and `C` to know `A`.\nThat's what we are going to use here to simulate synergy.\n\n"
]
},
{
Expand Down Expand Up @@ -158,6 +219,67 @@
"Now HOI is negative, therefore the interaction between the three nodes is\ndominated by synergy.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating redundant behavior by copy operator\n\nRedundancy can emerge when nodes (1, 2, 3) in the system `x` are receiving\nmultiple copies of the same information. A simple way to simulate redundancy\nconsists in taking the signal of one node, let's say the first one, and copy\nthis signal to the two other nodes.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# x = (n_samples, n_nodes)\nx = np.random.rand(1000, 3)\n\nx[:, 1] = x[:, 1] + x[:, 0] # 1 = 1 & 0\nx[:, 2] = x[:, 2] + x[:, 0] # 2 = 2 & 0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"compute hoi using the Oinfo\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"hoi = compute_hoi_beh(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Print HOI value\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(f\"HOI between nodes (1, 2, 3) : {hoi}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, the estimated HOI is positive which is the hallmark of\nredundancy when using the Oinfo.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -180,7 +302,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Redundant and synergistic encoding\n\nIn this second part, we are going to switch for encoding measure, in the sens\nthat elements of a network areg going to carry redundant or synergistic\ninformation about an external variable. To estimate HOI about a target\nvariable `y`, we're going to use the :class:`hoi.metrics.GradientOinfo`. To\nsimulate redundancy and synergy, we're going to use the same method as\nbefore.\n\n"
"## Redundant and synergistic encoding\n\nIn this second part, we are going to switch for encoding measure, in the sens\nthat elements of a network areg going to carry redundant or synergistic\ninformation about an external variable. To estimate HOI about a target\nvariable `y`, we're going to use the :class:`hoi.metrics.GradientOinfo`. To\nsimulate redundancy and synergy, we're going to use the same methods as\nbefore.\n\n"
]
},
{
Expand All @@ -198,7 +320,129 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating redundant encoding\n\nTo simulate redundancy, we copy the y variable into each node of x\n\n"
"### Simulating redundant encoding\n\nTo simulate redundancy, between a triplet of variable `x` and a target\nvariable `y`\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# x = (n_samples, n_nodes)\nx, y = simulate_hoi_gauss(\n target=True, n_samples=1000, triplet_character=\"redundancy\"\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"compute hoi\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"hoi = compute_hoi_enc(x, y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Print HOI value\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(f\"HOI between nodes (1, 2, 3) about y : {hoi}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"the estimated HOI is positive which represents redundant interactions between\nthe three nodes about y.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating synergistic encoding\n\nTo simulate synergy, between a triplet of variable `x` and a target\nvariable `y`\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# x = (n_samples, n_nodes)\nx, y = simulate_hoi_gauss(\n target=True, n_samples=1000, triplet_character=\"synergy\"\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"compute hoi\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"hoi = compute_hoi_enc(x, y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Print HOI value\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(f\"HOI between nodes (1, 2, 3) about y : {hoi}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"the estimated HOI is negative which represents synergistic interactions\nbetween the three nodes about y.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating redundant encoding by copy operation\n\nTo simulate redundancy, we copy the y variable into each node of x\n\n"
]
},
{
Expand Down Expand Up @@ -259,7 +503,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating synergistic encoding\n\nTo simulate synergy, we define the y variable as the sum of the three nodes\n\n"
"### Simulating synergistic encoding by sum operation\n\nTo simulate synergy, we define the y variable as the sum of the three nodes\n\n"
]
},
{
Expand Down
Binary file not shown.
Loading

0 comments on commit 14f5038

Please sign in to comment.