#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Example of the reconstruction of a Converge / Divergence network.
For a theoretical background, please refer to the paper:
Understanding diseases as increased heterogeneity: a complex network computational framework
Massimiliano Zanin, Juan Manuel TuĂ±as, Ernestina Menasalvas
arXiv:1806.01367 [physics.soc-ph]
"""
import numpy as np
import ConvDivNetworks as cdn
# First, let's fix the random seed, in order to fix the initial data set.
np.random.seed( 999 )
# Initialisation of the data set. We need 8 subjects, divided into two classes.
numSubj = 8
subjClass = np.zeros( (numSubj) )
subjClass[ int(numSubj / 2): ] = 1
# Afterwards, we create the example data set. Please refer to the main paper
# for a discussion of how data are generated.
rawFeatures = np.random.normal( 0.0, 0.2, (numSubj, 4) )
for subj in range( int( numSubj / 2 ), numSubj ):
alpha = np.random.uniform( 0, 2.0 * np.pi )
rawFeatures[ subj, :2 ] = np.random.normal( 1.0, 0.2 ) * np.array( [ np.cos( alpha ), np.sin( alpha ) ] )
for subj in range( int( numSubj / 2 ) ):
alpha = np.random.uniform( 0, 2.0 * np.pi )
rawFeatures[ subj, 2:4 ] = np.random.normal( 1.0, 0.2 ) * np.array( [ np.cos( alpha ), np.sin( alpha ) ] )
# Given the initial data set, we obtain the two sets of features opimising the
# construction of the network. Note that we use an Euclidean distance.
setConv, setDiv = cdn.GetFeatureSelection( rawFeatures, subjClass, distance = ['euclidean', 0] )
# Now we have the two sets of features - which, given how the data have been created, should
# be [0, 1] and [2, 3]. We then use them to create the two networks, and get the centrality
# of all subjects. Note that we are just interested in the eigenvector centrality: in order
# to reduce the computational cost, the two other centralities are deactivated.
_, eigvCentrality, _ = cdn.GetConvDiv( rawFeatures[ :, setConv[1] ], \
rawFeatures[ :, setDiv[1] ], enableCloseness = False, \
enableEigv = True, enableBetweenness = False, \
distance = ['euclidean', 0] )