You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**swarm_it** is a python utility designed to abstract away some of the effort in setting up Particle Swarm Optimization (PSO)-based calibrations of biological models in the [PySB](http://pysb.org/) format using [simplePSO](https://github.com/LoLab-VU/ParticleSwarmOptimization).
9
9
@@ -77,6 +77,7 @@ data = np.load('my_data.npy')
77
77
data_sd = np.load('my_data_sd.npy')
78
78
observable_data =dict()
79
79
time_idxs =list(range(len(timespan)))
80
+
# my_observable is the name of an Observable in the model.
SwarmIt constructs the PSO object to sample all of a model's kinetic rate parameters. It assumes that the priors are uniform with size 4 orders of magnitude and centered on the values defined in the model.
95
+
#### SwarmParam
96
+
By default SwarmIt constructs the PSO object to sample all of a model's kinetic rate parameters; it assumes that the priors are uniform with size 4 orders of magnitude and centered on the values defined in the model. However, the swarm_it module has a built-in helper class, SwarmParam, which can be used in conjunction of with SwarmIt class to set which model parameters are sampled and the corresponding sampling ranges. SwarmParam can be used at the level of PySB model definition to log which parameters to include in a Particle Swarm Optimization run, or it can be used after model definition at as long as it is defined before defining a SwarmIt object. It can be imported from swarm_it:
97
+
```python
98
+
from swarm_it import SwarmParam
99
+
```
100
+
It is passed at instantiation of the SwarmIt class via the `swarm_param` input parameter,
which uses it to build the set of parameters to sample, their staring PSO position and bounds, as well as the parameter mask for use with built-in cost functions.
95
105
96
-
In addition, SwarmIt crrently has three pre-defined loglikelihood functions with different estimators, specified with the keyword parameter cost_type:
106
+
Note that if you flag a parameter for sampling without setting sampling bounds, SwarmParam will by default assign the parameter bounds centered on the parameter's value (as defined in the model) with a width of 4 orders of magnitude.
107
+
108
+
For a more in depth example usage of SwarmParam, see the [simplepso_dimerization_model_SwarmIt_SwarmParam example](./examples/pysb_dimerization_model/simplepso_dimerization_model_SwarmIt_SwarmParam.py) and corresponding model [dimerization_model_swarmit](./examples/pysb_dimerization_model/dimerization_model_swarmit.py).
109
+
110
+
##### Built-in cost functions
111
+
SwarmIt currently has three pre-defined cost functions with different estimators, specified with the keyword parameter cost_type:
97
112
```python
98
113
# Now build the PSO object.
99
114
pso = swarmit(cost_type='mse')
100
115
```
101
116
The options are
102
-
* 'norm_logpdf'=> (default) Compute the cost a the negative sum of normal distribution logpdf's over each data point
103
-
* 'mse'=>Compute the cost using the mean squared error estimator
104
-
* 'sse'=>Compute the cost using the sum of squared errors estimator.
117
+
* 'norm_logpdf'=> (default) Compute the cost as the negative sum of normal distribution logpdf's over each timecourse data points and each given model observable.
118
+
* 'mse'=>Compute the cost using the mean squared error estimator over the timecourse data and each given model observable.
119
+
* 'sse'=>Compute the cost using the sum of squared errors estimator over the timecourse data and each given observable.
105
120
106
121
Each of these functions computes the cost estimate using the timecourse output of a model simulation for each observable defined in the `observable_data` dictionary.
107
-
If you want to use a different or more complicated likelihood function with SwarmIt then you'll need to subclass it and either override one of the existing cost functions or define a new one.
108
122
109
-
#### SwarmParam
110
-
The swarm_it module has a built-in helper class, SwarmParam, which can be used in conjunction of with SwarmIt class. SwarmParam can be used at the level of PySB model definition to log which parameters to include in
111
-
a Particle Swarm Optimization run, or it can be used after model definition at as long as it is defined before defining a SwarmIt object. It can be imported from swarm_it:
123
+
##### Custom cost function
124
+
If you want to use a different or more complicated cost function than the built-ins, the `SwarmIt` class object can also accept a custom cost function defined by the user with the parameters `cost_type='custom'` and `custom_cost`:
112
125
```python
113
-
from swarm_it import SwarmParam
126
+
# Now build the PSO object with a custom cost function.
127
+
defuser_cost(model, simulation_output):
128
+
# Do something and compute the cost for this model and its evaluation.
It is passed at instantiation to the SwarmIt class, which uses it
116
-
to build the set of parameters to use, their staring PSO position and bounds, as well as the parameter mask for the cost function.
117
-
118
-
Note that if you flag a parameter for sampling without setting sampling bounds, SwarmParam will by default assign the parameter bounds centered on the parameter's value (as defined in the model) with a width of 4 orders of magnitude.
132
+
Note that the custom cost function defined by the user, `user_cost`, should accept two parameters: the model itself and the simulation output (or trajectory). The user can then define how to compute the cost using these input objects or using other data/objects defined outside `user_cost`.
119
133
120
134
### Examples
121
135
Additional example scripts that show how to setup and launch PSO runs using **swarm_it** can be found under [examples](./examples).
0 commit comments