← Back to Book Detail

Social Network Simulation (17/11) -- Digital Humanities Tools and Techniques ...

Browse
154%

Social Network Simulation

Social Network Simulation INTRODUCTION Network visualizations are increasingly important in the digital humanities, as they exhibit relationships between people, groups, ideas, places, and things. For instance, social network analysis is an active area of research, and applications abound in humanities scholarship. Networks are a type of graph. A graph is mathematical model consisting of nodes, which represent entities (or people, groups, places, ideas, and other objects objects), and edges, or links, which represent the relationships between and among these nodes. This section discusses networks, and specifically visualizing networks using Python. Throughout this section, the focus is on social networks, representing them mathematically with an adjacency matrix, visualizing the adjacency matrix, and visualizing the network. READING, GENERATING, AND PROCESSING THE DATA FOR THE NETWORK VISUALIZATION To illustrate the concepts of a social network visualization, a simple example will be demonstrated. For simplicity, it is assumed that the names of individuals in the network are stored in CSV format. The weights, or social connections between these individuals, will be assigned randomly, providing additional experience in working with random numbers, which is essential in simulation. After importing Numpy for numerical calculations and Pandas for data frames and data manipulation, the names are read from the CSV file. Ensure that the correct file path is specified so that the CSV file can be located. import numpy as np import pandas as pd ## File path/directory. Add the correct path to the input CSV file... path = 'File Path' ## File name.... fn0 = 'firstNames.csv' ## Full file path.... fpath = path + fn0 ## Read the CSV file into a dataframe. names_df = pd.read_csv(fpath) ## Get the number of names in total.... NNAMES_TOTAL = len(names_df) The names are shuffled to increase randomness. ## Get a random permutation of the names. The permutation ranges from 0 to NNAMES_TOTAL - 1. randomIndex = np.random.permutation(NNAMES_TOTAL) For illustrative purposes, only a subset of the names will be used in the network – 12 individuals in this case. The names are then extracted from the data frame. ## Number of people/names in the social network.... NNames = 12 ## Get the first NNames names from the random permutation.... NAMES = names_df.iloc[0:NNames] Now, weights will be assigned randomly. A minimum weight and maximum weight are first specified. ## Minimum and maximum weights.... minWT = 0.5 maxWT = 3.0 ADJANCENCY MATRIX An adjacency matrix is then generated. An adjacency matrix is a 2D grid of values, or matrix, that is used to denote a relationship between a row element and its corresponding column element, as will be seen below. Each element in the adjacency matrix has a row position and column position that denotes the strength of the relationship (randomly generated in this example) between the person indicated in the row and the person indicated in the
← Previous Chapter Next Chapter →