Skip to content

Commit

Permalink
changes for final sub
Browse files Browse the repository at this point in the history
  • Loading branch information
hneutr committed Mar 7, 2019
1 parent 84649fa commit d0990ff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
6 changes: 3 additions & 3 deletions examples/matlab/kitchen_sink.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Network 2 of 3: the Zachary Karate Club %
% Feature: a network w/ node names and additional metadata for 2 nodes %
% Feature: a network w/ node names and additional (binary ) metadata %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Directly specify an edge list.
Expand Down Expand Up @@ -87,7 +87,7 @@

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Display parameters choices and defaults %
% Demonstrates: how to fix default behavior for webweb on opening the html %
% Demonstrates: how to set default behavior for webweb on opening the html %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ww.display.networkName = 'tree';
Expand All @@ -102,4 +102,4 @@
ww.display.scaleLinkWidth = 1;

% call webweb
webweb(ww);
webweb(ww);
61 changes: 46 additions & 15 deletions examples/python/kitchen_sink.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,78 @@
from webweb import Web
import random

# Give the webweb a title.
web = Web(title='kitchen_sink')

################################################################################
# Stochastic Block Model network
# Network 1 of 3: a stochastic block model (SBM)
# Features: a network w/ metadata
################################################################################
# let's generate a graph using the Stochastic Block Model

# choose sizes of communities
c1, c2, c3 = 15, 20, 25
# Create an empty edge list, to be populated during network construction
edge_list = []

# group sizes
group_sizes = [15, 20, 25]

# group memberships, z
z = [0 for _ in range(c1)] + [1 for _ in range(c2)] + [2 for _ in range(c3)]
# probability of edges between groups
node_group = [0 for _ in range(group_sizes[0])]
node_group += [1 for _ in range(group_sizes[1])]
node_group += [2 for _ in range(group_sizes[2])]

# group affinity matrix
M = [[ 0.25, 0.02, 0 ],
[ 0.02, 0.2, 0.02 ],
[ 0, 0.02, 0.15 ]]

# SBM
edge_list = []
for i in range(c1 + c2 + c3):
for i in range(sum(group_sizes)):
for j in range(i):
if random.random() < M[z[i]][z[j]]:
if random.random() < M[node_group[i]][node_group[j]]:
edge_list.append([i,j])

web.networks.sbm(adjacency=edge_list, metadata={'community': {'values' : z}})
# create a network called sbm
web.networks.sbm(
# assign its edgelist
adjacency=edge_list,
# give it the community metadata
metadata={'community':
{
'values' : node_group,
# tell webweb to display the groups categorically
'type' : 'categorical',
},
}
)

################################################################################
# Zachary Karate Club
# Network 2 of 3: the Zachary Karate Club
# Feature: a network w/ node names and additional (binary) metadata
################################################################################

web.networks.zkc(
adjacency=[[2,1],[3,1],[3,2],[4,1],[4,2],[4,3],[5,1],[6,1],[7,1],[7,5],[7,6],[8,1],[8,2],[8,3],[8,4],[9,1],[9,3],[10,3],[11,1],[11,5],[11,6],[12,1],[13,1],[13,4],[14,1],[14,2],[14,3],[14,4],[17,6],[17,7],[18,1],[18,2],[20,1],[20,2],[22,1],[22,2],[26,24],[26,25],[28,3],[28,24],[28,25],[29,3],[30,24],[30,27],[31,2],[31,9],[32,1],[32,25],[32,26],[32,29],[33,3],[33,9],[33,15],[33,16],[33,19],[33,21],[33,23],[33,24],[33,30],[33,31],[33,32],[34,9],[34,10],[34,14],[34,15],[34,16],[34,19],[34,20],[34,21],[34,23],[34,24],[34,27],[34,28],[34,29],[34,30],[34,31],[34,32],[34,33]],
# assign some metadata to nodes by their id
nodes={1 : { 'headHoncho' : True}, 34 : {'headHoncho' : True}},
metadata={
# use the reserved keyword 'name' to give names to nodes for displaying
'name' : {
'values' : ["Bernita Blizzard", "Lauran Lenahan", "Kallie Kerr", "Yun Yearsley", "Krystina Kehr", "Marisa Mccullough", "Sandra Soderquist", "Latisha Luczynski", "Gertrudis Guadarrama", "Ramonita Raley", "Tessa Tuff", "Michell Murphey", "Juliana Jenny", "Imogene Ivie", "Ricky Revis", "Tonia Tighe", "Lyle Lamanna", "Michael Motto", "Charlie Cartwright", "Aimee Aschenbrenner", "Vi Vallery", "Shaquana Stocking", "Penelope Percival", "Bari Barrentine", "Janie Jeske", "Breann Brodie", "Carmel Clara", "Nada Nicol", "Francisca Fu", "Shyla Schranz", "Clarissa Crooks", "Hilario Holzwarth", "Huong Hodge", "Lavonne Leng",]
}
}
)

################################################################################
# Tree/Ring network (N-Cayley tree)
# Network 3 of 3: Tree/Ring network (N-Cayley tree)
# Features: a multilayer network with different metadata for each layer
################################################################################
# let's make a tree network with 4 layers and a branching factor of 5

tree_layers = 4
branching_factor = 5

nodes_queue = [0]

# Create an empty edge list, to be populated during layer construction
edge_list = []
nodes = {}
for tree_layer in range(tree_layers):
Expand All @@ -57,7 +81,8 @@
while len(nodes_queue):
node = nodes_queue.pop(0)
nodes[node] = { 'ring' : tree_layer }
for _ in range(branching_factor):
branches = branching_factor if tree_layer == 0 else branching_factor - 1
for _ in range(branches):
new_node = max(nodes.keys()) + 1
edge_list.append([node, new_node])
new_nodes_queue.append(new_node)
Expand All @@ -66,12 +91,18 @@
nodes_queue = new_nodes_queue
web.networks.tree.add_layer(adjacency=edge_list, nodes=nodes)

# tell webweb to display the metdata categorically
web.display.metadata = {
'ring' : {
'type' : 'categorical',
}
}

################################################################################
# Display parameters choices and defaults
# Demonstrates: how to set default behavior for webweb on opening the html
################################################################################

web.display.networkName = 'tree'
web.display.networkLayer = 3
web.display.colorBy = 'ring'
Expand All @@ -80,7 +111,7 @@
web.display.charge = 30
web.display.linkLength = 15
web.display.colorPalette = 'Greens'
web.display.scaleLinkOpacity = True
web.display.scaleLinkOpacity = False
web.display.scaleLinkWidth = True

# show the visualization
Expand Down

0 comments on commit d0990ff

Please sign in to comment.