Skip to content

Commit

Permalink
PyPi Release
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum9Innovation committed Aug 30, 2020
1 parent 279911d commit ec756b5
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 4 deletions.
4 changes: 3 additions & 1 deletion build/lib/epispot/__init__.py
Expand Up @@ -8,13 +8,15 @@
# imports
import warnings
import random
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import colors

# local
from . import comps
from . import models
from . import plots
from . import fitters

# version info
__version__ = 'v1.0.0'
__version__ = 'v1.1.0'
82 changes: 82 additions & 0 deletions build/lib/epispot/fitters.py
@@ -0,0 +1,82 @@
"""
This module contains all available fitting algorithms.
These operate separately from the `Model` class.
STRUCTURE:
- grad_des
"""

from . import np


def grad_des(get_model_pred, real_data, model_params, mu, epochs, N, samples, delta=0.0001):
"""
The gradient descent fitter. This is not stochastic.
For long timespans, this may take a long time to converge.
:param get_model_pred: function in the form:
param: parameters, parameters for model
return: model predictions (use the integrate() method)
:param real_data: .csv file in the form:
HEADER: ...layer #s
CONTENTS: ...people in layers
:param model_params: list of model parameters
:param mu: the learning rate (adjust so that loss decreases after every epoch)
:param epochs: number of training sessions to run
(more epochs = more accuracy + more time running)
:param N: the total population
:param samples: array of timestamps to use for training
:param delta: =0.0001, use small values for more precision--increase if gradients are 0
:return: optimized `model_params`
"""

# get real data
file = real_data.readlines()
layers_to_opt = [int(char) for char in file[0].split(',')]

# quadratic cost

def cost(pred, real):

p_samp = []
r_samp = []

for sample in samples:
p_samp.append(pred[sample][1] / N)
r_samp.append(real[sample][1] / N)

return np.sum((np.array(p_samp) - np.array(r_samp)) ** 2)

data = [file[l].split(',') for l in range(1, len(file))]
for line in range(len(data)):
for char in range(len(data[line])):
data[line][char] = float(data[line][char])
for char in range(len(data[0])):
data[0][char] = int(data[0][char])

# training iterations
for epoch in range(epochs):

predictions = get_model_pred(model_params)
base_cost = cost(predictions, data[1:])
print('Epoch %s: Loss at %s' % (epoch, base_cost))

gradients = []

# parameter gradients
for param in range(len(model_params)):

model_params[param] += delta
pred = get_model_pred(model_params)

gradients.append((cost(pred, data[1:]) - base_cost) / delta)

model_params[param] -= delta

# print(gradients)
# print(model_params)
model_params = model_params - mu * np.array(gradients)
# print(model_params)
# predictions = get_model_pred(model_params)
# print(cost(predictions, data[1:]))

return model_params
Binary file added dist/epispot-1.1.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/epispot-1.1.0.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion epispot.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: epispot
Version: 1.0.0
Version: 1.1.0
Summary: A tool for modelling infectious diseases.
Home-page: https://quantum9innovation.github.io/epispot
Author: quantum9innovation
Expand Down
1 change: 1 addition & 0 deletions epispot.egg-info/SOURCES.txt
Expand Up @@ -2,6 +2,7 @@ README.md
setup.py
epispot/__init__.py
epispot/comps.py
epispot/fitters.py
epispot/models.py
epispot/plots.py
epispot.egg-info/PKG-INFO
Expand Down
1 change: 1 addition & 0 deletions epispot.egg-info/requires.txt
@@ -1 +1,2 @@
matplotlib
numpy
2 changes: 1 addition & 1 deletion epispot/__init__.py
Expand Up @@ -19,4 +19,4 @@
from . import fitters

# version info
__version__ = 'v1.0.0'
__version__ = 'v1.1.0'
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="epispot",
version="v1.0.0",
version="v1.1.0",
author="quantum9innovation",
description="A tool for modelling infectious diseases.",
long_description=long_description,
Expand Down

0 comments on commit ec756b5

Please sign in to comment.