Skip to content

Commit

Permalink
style: format with isort and black
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry committed May 2, 2022
1 parent d39e9e4 commit cfd3781
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 69 deletions.
2 changes: 1 addition & 1 deletion hypercontagion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from hypercontagion import simulation
from hypercontagion.simulation import *

__version__ = pkg_resources.require("hypercontagion")[0].version
__version__ = pkg_resources.require("hypercontagion")[0].version
2 changes: 1 addition & 1 deletion hypercontagion/classes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import hypercontagion.classes.epi_contagion
from hypercontagion.classes import epi_contagion
from hypercontagion.classes import epi_contagion
25 changes: 13 additions & 12 deletions hypercontagion/classes/epi_contagion.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
from collections import defaultdict

import networkx as nx
from sklearn import neighbors

from hypercontagion import SamplingDict
import networkx as nx
from collections import defaultdict
from hypercontagion.exception import HyperContagionError


class DiscreteStochasticEpiModel:
def __init__(self):
self.transition_network = nx.DiGraph()
self.hypergraph = None
self.state = None

def add_transition_process(self, start_state, end_state, transition_function):
self.transition_network.add_edge(start_state, end_state, function=transition_function)
self.transition_network.add_edge(
start_state, end_state, function=transition_function
)

def add_hypergraph(self, H):
self.hypergraph = H

def set_initial_state(self, state):
self.state = state

Expand All @@ -26,16 +31,13 @@ def remaining_transitions(self, state_dict):
num_trans += state_dict[state][-1]
return num_trans



def simulate(self, tmin, tmax, dt=1):
state = dict(self.state)
if self.state is None:
raise HyperContagionError("Initial state was never set!")
else:
state_dict = dict(self.state)


state_dict = dict()
for s in self.transition_network.nodes:
state_dict[s] = [0]
Expand All @@ -48,7 +50,6 @@ def simulate(self, tmin, tmax, dt=1):

new_state = state


while t <= tmax and self.remaining_transitions(state_dict) != 0:
for s in self.transition_network.nodes:
state_dict[s].append(state_dict[s][-1])
Expand All @@ -61,20 +62,20 @@ def simulate(self, tmin, tmax, dt=1):

t += dt


# # assumes all transitions are Markovian
# class GillespieStochasticEpiModel:
# def __init__(self):
# self.simulate = False
# self.rates = dict()
# self.transition_functions = dict()
# self.hypergraph = None

# def add_transition_process(self, start_state, end_state, transition_function):
# self.rates[(start_state, end_state)] = SamplingDict(weighted=True)
# self.transition_functions[(start_state, end_state)] = transition_function

# def add_hypergraph(self, H):
# self.hypergraph = H

# # def simulate(tmin, tmax, return_events):

3 changes: 2 additions & 1 deletion hypercontagion/simulation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from hypercontagion.simulation import epidemics, functions, opinions, utilities
from .opinions import *

from .functions import *
from .opinions import *
from .utilities import *
8 changes: 5 additions & 3 deletions hypercontagion/simulation/epidemics.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import random
import numpy as np
from collections import defaultdict

import numpy as np
import xgi

from hypercontagion.exception import HyperContagionError
from hypercontagion.simulation.functions import majority_vote, threshold
from hypercontagion.simulation.utilities import (
SamplingDict,
EventQueue,
SamplingDict,
_process_trans_SIR_,
_process_trans_SIS_,
)
import xgi


def discrete_SIR(
Expand Down
1 change: 1 addition & 0 deletions hypercontagion/simulation/functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random


# built-in functions
def collective_contagion(node, status, edge):
for i in set(edge).difference({node}):
Expand Down
6 changes: 3 additions & 3 deletions hypercontagion/simulation/opinions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import random
import heapq
import random
from collections import Counter, defaultdict

import numpy as np
from collections import defaultdict
from collections import Counter

# built-in functions

Expand Down
7 changes: 4 additions & 3 deletions hypercontagion/simulation/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
github.com/gstonge/SamplableSet but is less efficient.
"""

import numpy as np
import random
from collections import defaultdict, Counter
import heapq
import random
from collections import Counter, defaultdict

import numpy as np


class EventQueue:
Expand Down
7 changes: 4 additions & 3 deletions hypercontagion/visualization/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .vis import *
import hypercontagion.visualization.colors
import hypercontagion.visualization.layout
import hypercontagion.visualization.vis

from .colors import *
import hypercontagion.visualization.colors
from .layout import *
import hypercontagion.visualization.layout
from .vis import *
8 changes: 3 additions & 5 deletions hypercontagion/visualization/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
Visualizations of simulations with pyglet.
"""

from sys import platform

from copy import deepcopy
from itertools import chain
from sys import platform

import numpy as np

import pyglet
from pyglet import shapes
from pyglet.window import key, mouse, Window
from pyglet.gl import *
from pyglet.window import Window, key, mouse

from hypercontagion.visualization.colors import colors
import hypercontagion.visualization.colors as cols
from hypercontagion.visualization.colors import colors

_colors = list(colors.values())

Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from setuptools import setup
import setuptools
import sys

import setuptools
from setuptools import setup

__version__ = "0.1"

if sys.version_info < (3, 7):
Expand Down
24 changes: 21 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
import pytest


@pytest.fixture
def func_args_1():
return {"node": 1, "status": {1: "S", 2: "S", 3: "I"}, "edge": [1, 2, 3]}


@pytest.fixture
def func_args_2():
return {"node": 1, "status": {1: "S", 2: "I", 3: "I"}, "edge": [1, 2, 3]}


@pytest.fixture
def func_args_3():
return {"node": 2, "status": {1: "S", 2: "I", 3: "I", 4: "R"}, "edge": [1, 2, 3, 4]}


@pytest.fixture
def func_args_4():
return {"node": 5, "status": {1: "S", 2: "I", 3: "I", 4: "R", 5: "S"}, "edge": [1, 2, 3, 4, 5]}
return {
"node": 5,
"status": {1: "S", 2: "I", 3: "I", 4: "R", 5: "S"},
"edge": [1, 2, 3, 4, 5],
}


@pytest.fixture
def func_args_5():
return {"node": 3, "status": {1: "I", 2: "I", 3: "S", 4: "I", 5: "I"}, "edge": [1, 2, 3, 4, 5]}
return {
"node": 3,
"status": {1: "I", 2: "I", 3: "S", 4: "I", 5: "I"},
"edge": [1, 2, 3, 4, 5],
}


@pytest.fixture
def func_args_6():
return {"node": 3, "status": {1: "S", 2: "S", 3: "S", 4: "R", 5: "R"}, "edge": [1, 2, 3, 4, 5]}
return {
"node": 3,
"status": {1: "S", 2: "S", 3: "S", 4: "R", 5: "R"},
"edge": [1, 2, 3, 4, 5],
}
Loading

0 comments on commit cfd3781

Please sign in to comment.