Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating sensitivity analysis class to be general for any model parameters #426

Merged
merged 12 commits into from Apr 17, 2019
Merged
Changes from 8 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,12 +1,13 @@
from pysb.tools.sensitivity_analysis import \
InitialsSensitivity
PairwiseSensitivity, InitialsSensitivity
from pysb.examples.tyson_oscillator import model
import numpy as np
import numpy.testing as npt
import os
from pysb.simulator.scipyode import ScipyOdeSimulator
import tempfile
import shutil
from nose.tools import *
This conversation was marked as resolved by alubbock

This comment has been minimized.

Copy link
@alubbock

alubbock Apr 2, 2019

Member

Should be from nose.tools import raises. I know there are wildcard imports in other tests - we should replace those in the future too. PEP8 says to avoid them.



class TestSensitivityAnalysis(object):
@@ -24,7 +25,7 @@ def setUp(self):
integrator_options={'rtol': 1e-8,
'atol': 1e-8,
'mxstep': 20000})
self.sens = InitialsSensitivity(
self.sens = PairwiseSensitivity(
solver=self.solver,
values_to_sample=self.vals,
objective_function=self.obj_func_cell_cycle,
@@ -65,15 +66,21 @@ def obj_func_cell_cycle(self, out):
local_freq = np.average(local_times) / len(local_times) * 2
return local_freq

def test_vode_run(self):
solver_vode = ScipyOdeSimulator(self.model,
tspan=self.tspan,
integrator='vode',
integrator_options={'rtol': 1e-8,
'atol': 1e-8,
'nsteps': 20000})
def test_run(self):

sens_vode = PairwiseSensitivity(
solver=self.solver,
values_to_sample=self.vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable
)
sens_vode.run()
npt.assert_almost_equal(self.sens.p_matrix, self.p_simulated,
decimal=3)

def test_old_class_naming(self):
sens_vode = InitialsSensitivity(
solver=solver_vode,
solver=self.solver,
values_to_sample=self.vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable
@@ -89,9 +96,6 @@ def test_p_matrix(self):
npt.assert_almost_equal(self.sens.p_matrix, self.p_simulated,
decimal=3)

def test_num_simulations(self):
assert len(self.sens.simulation_initials) == 25

def test_pmatrix_outfile_exists(self):
self.sens.run(save_name=self.savename,
out_dir=self.output_dir)
@@ -121,21 +125,91 @@ def test_create_png(self):
'test3_P_H_P_prime.png'))

def test_unique_simulations_only(self):
vals = [.8, .9, 1.1, 1.2, 1.3]
sens = PairwiseSensitivity(
values_to_sample=vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable,
solver=self.solver
)
sens.run()
self.sens.create_plot_p_h_pprime(save_name='test4',
out_dir=self.output_dir)
assert os.path.exists(os.path.join(self.output_dir,
'test4_P_H_P_prime.png'))

def test_param_pair(self):
vals = [.9, 1.0, 1.1]
sens = PairwiseSensitivity(
values_to_sample=vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable,
solver=self.solver,
sample_list=['k1', 'cdc0']
)
sens.run()
self.sens.create_plot_p_h_pprime(save_name='test4',
out_dir=self.output_dir)
assert os.path.exists(os.path.join(self.output_dir,
'test4_P_H_P_prime.png'))

def test_all_params(self):
vals = [.9, 1.1]

sens = PairwiseSensitivity(
values_to_sample=vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable,
solver=self.solver,
sens_type='all'
)
sens.run()
self.sens.create_plot_p_h_pprime(save_name='test4',
out_dir=None)
assert os.path.exists('test4_P_H_P_prime.png')

@raises(Exception)
This conversation was marked as resolved by alubbock

This comment has been minimized.

Copy link
@alubbock

alubbock Apr 2, 2019

Member

Use a more specific exception class. Otherwise, unrelated errors can end up getting missed. Likewise for the other tests in this file.

def test_param_not_in_model(self):
vals = [.8, .9, 1.1, 1.2, 1.3]
solver = ScipyOdeSimulator(self.model,
tspan=self.tspan,
integrator='lsoda',
integrator_options={'rtol': 1e-8,
'atol': 1e-8,
'mxstep': 20000})
sens = InitialsSensitivity(
sens = PairwiseSensitivity(
values_to_sample=vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable,
solver=solver
solver=solver, sample_list=['a0']
)

@raises(Exception)
def test_sens_type_and_list_none(self):
vals = [.8, .9, 1.1, 1.2, 1.3]
sens = PairwiseSensitivity(
values_to_sample=vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable,
solver=self.solver, sample_list=None, sens_type=None
)

@raises(Exception)
def test_sens_type_and_list_none(self):
vals = [.8, .9, 1.1, 1.2, 1.3]
sens = PairwiseSensitivity(
values_to_sample=vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable,
solver=self.solver, sample_list=None, sens_type=None
)

@raises(TypeError)
def test_bad_solver(self):
vals = [.8, .9, 1.1, 1.2, 1.3]
sens = PairwiseSensitivity(
values_to_sample=vals,
objective_function=self.obj_func_cell_cycle,
observable=self.observable,
solver=None, sample_list=None, sens_type=None
)
sens.run()
self.sens.create_plot_p_h_pprime(save_name='test4',
out_dir=self.output_dir)
assert os.path.exists(os.path.join(self.output_dir,
'test4_P_H_P_prime.png'))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.