Skip to main content

A package to simulate and analyze networks with multidimensional interactions.

Project description

multisoc

multisoc is a python package to simulate and analyze networks with multidimensional interactions.

The code also reproduces the results from the paper The hidden architecture of connections: How do multidimensional identities shape our social networks?.
Preprint available at https://arxiv.org/abs/2406.17043.

Installation

Install the latest version:

pip install multisoc

Install from source:

git clone https://github.com/CSHVienna/multisoc
cd multisoc
pip install -e .

Examples

Multidimensional graph generation

In this example, we generate a graph, with two attributes and two categories per attribute, using the multidimensional_network_fix_av_degree function.
The graph is very homophilic in the first attribute, and slightly homophilic in the second one. Furthermore, the population distributions of the two attributes are slightly correlated.

import numpy as np
from multisoc.generate.multidimensional_network import multidimensional_network_fix_av_degree
from multisoc.generate.two_dimensional_population import consol_comp_pop_frac_tnsr

## List of 1d homophily matrices (2 for a two-dimensional system)
h_mtrx_lst = [ 
    np.array([[0.9,0.1],
              [0.1,0.9]]),
    np.array([[0.6,0.4],
              [0.4,0.6]])
]

## The marginals of the population distribution defined by comp_pop_frac_tnsr
## Each row has to sum 1 (100% of the population)
pop_fracs_lst = [
    [0.2,0.8],
    [0.4,0.6]
]

## Generate population distribution with certain level of correlation between the two attributes
## No correlation would correspond to the fraction of the largest minority
consol = 0.4 ## Level of correlation
comp_pop_frac_tnsr = consol_comp_pop_frac_tnsr(pop_fracs_lst,consol)

N = 200 ## Number of nodes
m = 20  ## Average number of connections per node

kind = "all" ## Aggregation function: {all->and, one->mean, any->or}
p_d = [0.5, 0.5] ## Weight of each dimension for "mean" aggregation function

G = multidimensional_network_fix_av_degree(
                h_mtrx_lst,
                comp_pop_frac_tnsr,
                kind,
                directed=False, ## Directed or undirected network
                pop_fracs_lst = pop_fracs_lst,
                N=N,
                m=m,
                v = 0,
                p_d = p_d
                )

Inference of multidimensional interactions

In this example, we infer the one-dimensional preferences and the aggregation function, given a dummy dataset that contains three attributes: number, color and shape. After the code, you can see how the input data is structured.
In particular, we print the value of AIC for the model that uses the AND aggregation function.

from multisoc.infer import data_loader
from multisoc.infer import wrappers
import pandas as pd

# Load the data
nodes_dummy = pd.read_csv("./dummy_data/nodes_dummy.csv",index_col="index",dtype='category')
edges_dummy = pd.read_csv("./dummy_data/edges_dummy.csv",dtype='category')

# Describe the type of data 
dimensions_list = ['number','color','shape']
shape_list = ["Circle","Square"]
color_list = ["Blue","Red"]
number_list = ["1","2","3","4","5","6"]
all_attributes_dict = {
    "shape":shape_list,
    "color":color_list,
    "number":number_list
}

# Compute the result dictionary, if we suppose that the data was generated using the AND aggregation function
nodes_input, edges_input = data_loader.build_nodes_edges_input_df(nodes_dummy, edges_dummy, dimensions=["shape","color","number"])
results_1d_dct = wrappers.infer_latent_preferences_1dSimple(
    nodes_input,
    edges_input,
    dimensions_list, 
    all_attributes_dict,
    type_p = "and" ## Type of aggregation function {and,or,mean}
    )

# Print the AIC
print(results_1d_dct['AIC'])

The nodes_dummy.csv file contains the information related to the nodes' attributes.
Each row contains the index of the node, and the corresponding attributes.

index shape color number
0 Square Blue 3
1 Circle Blue 3
2 Square Red 5
3 Square Blue 3
4 Square Red 1

The edges_dummy.csv file contains the information related to the connection among the individuals.
Each row contains one edge, with the corresponding source and target nodes.

source target
0 0 1
1 0 23
2 0 41
3 0 63
4 0 103

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multisoc-0.1.1.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

multisoc-0.1.1-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

Details for the file multisoc-0.1.1.tar.gz.

File metadata

  • Download URL: multisoc-0.1.1.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for multisoc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a6318b5df010dac98be8cfb31799668172465d2292876705434747aa087be380
MD5 be41a8c226977c9eec06d90a9fb668b0
BLAKE2b-256 e7747371611588bee946cada9f5b1374f364def36f5ac6c669fe18dee0b18bad

See more details on using hashes here.

File details

Details for the file multisoc-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: multisoc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for multisoc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b55931c9a4f8009dc23075c9be70ac91fbf874615dd44556c39c4f21eb9c48f3
MD5 486ad956fe84bc31af9d6514b999b6a8
BLAKE2b-256 898d812531a9bd7608295737e5b441d9e32ac0dc289e7c6f6aa27c816369e200

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page