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.0.tar.gz (32.2 kB view details)

Uploaded Source

Built Distribution

multisoc-0.1.0-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: multisoc-0.1.0.tar.gz
  • Upload date:
  • Size: 32.2 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.0.tar.gz
Algorithm Hash digest
SHA256 6c0e452281a8d8fd4360c9fa38b912e62891c0a4acb281e44b647693e6684df5
MD5 1550ed631e4417b2ca911f07b74d843e
BLAKE2b-256 ac08c9467f9a11cc6f0078690603d8756b40acbc685b252eefc343ea4c5e643e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: multisoc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 37.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27db7e52ac71a334bd56040214019f828e9527ecac86e0c6702cd619a6dc5632
MD5 985f9607ee7edf2a5483630ee8566871
BLAKE2b-256 0317790387a99f283f1ce3519ee1e8e4d881e63b7c5078bfa6feca095d1915c9

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