Skip to content

Commit

Permalink
Merge branch 'new-test' into pypar-check
Browse files Browse the repository at this point in the history
  • Loading branch information
bcdaniels committed Apr 13, 2022
2 parents 96b71bd + ebbfcbf commit 42e3f99
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SirIsaac depends on the latest
version of SloppyCell, available on GitHub.
In the simplest case, you can install with two steps. First download the git repository by running

https://github.com/GutenkunstLab/SloppyCell.git
git clone https://github.com/GutenkunstLab/SloppyCell.git

which will create a folder named `SloppyCell` in the current directory. Next, install SloppyCell by running setup.py. The easiest way to do this is using `pip`:

Expand Down
78 changes: 72 additions & 6 deletions test/test_fitting_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

import unittest

from SirIsaac.fittingProblem import *
import SirIsaac.fittingProblem as fp
import SloppyCell.ReactionNetworks as scrn
import numpy as np

def mock_net():
"""
Expand All @@ -20,9 +21,18 @@ def mock_net():

def mock_data():
"""
Create a simple mock dataset with a single datapoint
Create a mock dataset with a single datapoint
"""
return [ {'x': {1: (0.,1.) }}, ]

def simple_linear_data(N):
"""
Create a simple example dataset depending linearly on input and time,
with N datapoints.
"""
indepParamsList = [ [i,] for i in range(1,N+1) ]
data = [ {'y': {i[0]: (2.*i[0], 1.)}} for i in indepParamsList ]
return indepParamsList, data

class TestFittingProblem(unittest.TestCase):

Expand All @@ -31,7 +41,7 @@ def test_sloppycell_fitting_model_init(self):
Test that a basic SloppyCell fitting model can be initialized correctly
"""
net = mock_net()
mtest = SloppyCellFittingModel(net)
mtest = fp.SloppyCellFittingModel(net)

self.assertEqual([], mtest.getParameters())

Expand All @@ -40,11 +50,67 @@ def test_fitting_problem_init(self):
Test that a basic fitting problem can be initialized correctly
"""
net = mock_net()
m = SloppyCellFittingModel(net)
m = fp.SloppyCellFittingModel(net)
datatest = mock_data()
indepParamsList = [[]]
modellisttest = [m]
ftest = FittingProblem(datatest,modellisttest,
indepParamsList=indepParamsList)
ftest = fp.FittingProblem(datatest,modellisttest,
indepParamsList=indepParamsList)

self.assertEqual(None, ftest.getBestModel())

def test_fitAll(self):
"""
Test that fitAll produces reasonable results on an easy test problem.
"""
numDatapoints = 3
complexityList = [0,2]

# ensGen controls the generation of the initial ensemble of
# parameter starting points.
totalSteps = 5
keepSteps = 5
seeds = (1,1) # use a fixed random seed
ensTemperature = 100.
ensGen = fp.EnsembleGenerator( totalSteps, keepSteps,
temperature=ensTemperature, seeds=seeds )

# Parameters that control when local fitting stops.
avegtol = 1e-2
maxiter = 100

# set up simple linear data
indepParamNames = ['x',]
indepParamsList,data = simple_linear_data(numDatapoints)
outputNames = data[0].keys()

p = fp.PowerLawFittingProblem(
complexityList,
data,
outputNames=outputNames,
indepParamsList=indepParamsList,
indepParamNames=indepParamNames,
ensGen=ensGen,
avegtol=avegtol,
maxiter=maxiter)

p.fitAll()

# check that the correct number of models have been initialized
self.assertEqual(len(p.fittingModelNames),len(complexityList))
self.assertEqual(len(p.numParametersDict),len(complexityList))

# check that some models have indeed been fit
self.assertTrue(len(p.logLikelihoodDict) > 0)

# loop over models that have been fit
for modelName in p.logLikelihoodDict:
# check that all fit models have numerical log-likelihood
self.assertFalse(np.isnan(p.logLikelihoodDict[modelName]))

# check that costs (distance from data) are roughly what we expect
self.assertTrue(p.costDict[modelName] < 0.05)

# check we have the correct number of singular values
self.assertEqual(len(p.singValsDict[modelName]),p.numParametersDict[modelName])

0 comments on commit 42e3f99

Please sign in to comment.