models package¶
Stochastic Search - Learning models¶
-
class
models.stochastic_search.
SIR
(pop=2000000, focus=['I', 'R'], algorithm='differential_evolution', simulation='discrete', stochastic_search=False, forced_search_pop=False, ode_full_output=False, verbose=True)¶ Bases:
object
This model concentrate all the developed algorithms to represent data driven SIR model. Using the Scipy default model structure.
-
cost_wrapper
(*args)¶ The method responsible for wrapping the cost function. This allows differential evolution algorithm to run with parallel processing.
Parameters: *args (tuple) – cost function parameters
Returns: the cost function outputs Return type: float
-
fit
(dataset, t, search_pop=True, Ro_bounds=None, pop_sens=[0.001, 0.0001], Ro_sens=[0.8, 15], D_sens=[5, 50], sigma_sens=None, mu_sens=[0.0001, 0.02], notified_sens=None, sample_ponder=None, optim_verbose=False, **kwargs)¶ The method responsible for estimating a set of beta and r parameters for the provided data set. It assumes that in the data there is only one epidemic period.
Parameters: - dataset (array) – list with the respective arrays of Suceptible, Infected, Recovered and Deaths.
- t (array) – The time respective to each set of samples.
- search_pop (bool) – Flag to set the exposed population search, for better Suceptible extimation values. Default is
True
. - Ro_bounds (list) – The bounds to build the constraints for
Ro = Beta / r
. With minimun and maximun values, respectivelly. - pop_sens (list) – The sensibility (boudaries) for the proportion of
N
to be found by the pop parameters. - beta_sens (list) – The beta parameter sensibility minimun and maximun boundaries, respectivelly. Default is
[100,100]
. - r_sens (list) – The r parameter sensibility minimun and maximun boundaries, respectivelly. Default is
[100,1000]
. - sample_ponder (bool) – The flag to set the pondering of the non informative recovered data.
- optim_verbose (bool) – If
True
, after fitting will show the optimization summary. - **kwargs (dict) –
The optimization search algorithms options.
-
fit_multiple
(Sd, Id, Bd, td, threshold_prop=1, cases_before=10, filt_estimate=False, filt_window=55, beta_sens=[100, 10], r_sens=[100, 10], out_type=0, **kwargs)¶ The method responsible for estimating a set of beta and r parameters for each epidemy period existent in the provided dataset. It assumes that in the data there are several epidemic periods.
Parameters: - Sd (array) – Array with the suceptible data.
- Id (array) – Array with the infected data.
- Bd (array) – Array with the births data.
- td (array) – The time respective to each set of samples.
- threshold_prop (float) – The standard deviation proportion used as threshold for windowing. Default is
1.0
. - cases_before (int) – The number of back samples to check for the initial window point. Default is
10
. - filt_estimate (bool) – Flag to use filtered data to estimate the model parameters. Default is
False
. - filt_window (int) – The window size used on the filtering technique, only if
filt_estimate=True
. Default is55
. - beta_sens (list) – The beta parameter sensibility minimun and maximun boundaries, respectivelly. Default is
[100,100]
. - r_sens (list) – The r parameter sensibility minimun and maximun boundaries, respectivelly. Default is
[100,1000]
. - out_type (int) – The output type, it can be
1
or0
. Default is0
.
Returns: If the
out_type=0
, it returns a tuple with the estimated beta and r, estimated, with the year of each respective window. If out_type=1 it returns the self.data of the model, a summary with all model information.Return type: tuple
-
monteCarlo_multiple
(Sd, Id, Bd, td, threshold_prop=1, cases_before=10, minimum_days=60, steps_indays=10, filt_estimate=False, filt_window=55, beta_sens=[1000, 10], r_sens=[1000, 10], out_type=0, **kwargs)¶ The method responsible for estimating a set of beta and r parameters for each epidemy period existent in the provided dataset. It assumes that in the data there are several epidemic periods.
Parameters: - Sd (array) – Array with the suceptible data.
- Id (array) – Array with the infected data.
- Bd (array) – Array with the births data.
- td (array) – The time respective to each set of samples.
- threshold_prop (float) – The standard deviation proportion used as threshold for windowing. Default is
1.0
. - cases_before (int) – The number of back samples to check for the initial window point. Default is
10
. - filt_estimate (bool) – Flag to use filtered data to estimate the model parameters. Default is
False
. - filt_window (int) – The window size used on the filtering technique, only if
filt_estimate=True
. Default is55
. - beta_sens (list) – The beta parameter sensibility minimun and maximun boundaries, respectivelly. Default is
[100,100]
. - r_sens (list) – The r parameter sensibility minimun and maximun boundaries, respectivelly. Default is
[100,1000]
. - out_type (int) – The output type, it can be
1
or0
. Default is0
.
Returns: If the
out_type=0
, it returns a tuple with the estimated beta and r, estimated, with the year of each respective window. If out_type=1 it returns the self.data of the model, a summary with all model information.Return type: tuple
-
predict
(initial, t)¶ The function that uses the estimated parameters of the SIR model to predict the epidemy outputs (Suceptible, Infected and Recoverd) for the time samples provided, provided the initial conditions.
Parameters: - initial (array) – The initial values of the infected, suceptible and recovered data.
- time (array) – The time points to simulate the model.
Returns: The values of the suceptible, infected and recovered, at time, respectivelly.
Return type: tuple
-
result_summary
(out_plot=False, plot_size=[600, 400], save_results=False, folder_path='./', file_name='SIR_result_summary.png')¶ Method responsible for building a proper summary plot of the estimate process of the SIR model.
Parameters: - out_plot (bool) – Flag to output the bokeh.figure object.
- plot_size (list) – List with the plot size as [width, height].
- save_results (bool) – Flag to save the results as a .png image.
- folder_path (string) – The path to the folder the user wants to save resulted image.
- file_name (string) – The name of the resulted image that will be saved.
Returns: If out_plot=True, it returns a bokeh.figure object with the builded plots.
Return type: bokeh.figure
-
simulate
(initial, time, theta)¶ The function that simulate the differential SIR model, by computing the integration of the differential equations.
Parameters: - initial (array) – The initial values of the infected and suceptible data.
- time (array) – The time points to simulate the model.
- theta (array) – The Beta parameter, and r parameter, respectivelly.
Returns: The values of the suceptible and infected, at time, respectivelly.
Return type: tuple
-
-
models.stochastic_search.
findEpidemyBreaks
(cases, threshold_prop=1.0, cases_before=10)¶ The function responsible for determining the initial and final points of the epidemies windows.
Parameters: - cases (array) – The array with the cases values along time.
- threshold_prop (float) – The standard deviation proportion used as threshold for windowing. Default is 1.0.
- cases_before (int) – The number of back samples to check for the initial window point. Default is 10.
Returns: With the list of window’s starting points and window’s final points, respectively.
Return type: tuple
Cost Functions¶
-
models.cost_functions.
PrintException
(e)¶
-
models.cost_functions.
cost_NSIR
(self, pars, dataset, initial, t, w)¶
-
models.cost_functions.
cost_SEIR
(self, pars, dataset, initial, t, w)¶ The function to compute the error to guide the learning algorithm. It computes the quadratic error.
Parameters: - pars (tuple) – Tuple with Beta and r parameters, respectivelly.
- dataset (list) – The dataset with the respective S, I and R arrays.
- initial (array) – The initial values of suceptible and infected, respectivelly.
- t (array) – The time respective to each sample.
- w (array) – The weight respective to the suceptible and infected errors.
Returns: The sum of the quadratic error, between simulated and real data.
Return type: float
-
models.cost_functions.
cost_SIR
(self, pars, dataset, initial, t, w)¶ The function to compute the error to guide the learning algorithm. It computes the quadratic error.
Parameters: - p (tuple) – Tuple with Beta and r parameters, respectivelly.
- S (array) – The suceptible data values.
- I (array) – The infected data values.
- initial (array) – The initial values of suceptible and infected, respectivelly.
- t (array) – The time respective to each sample.
- w (array) – The weight respective to the suceptible and infected errors.
Returns: The sum of the quadratic error, between simulated and real data.
Return type: float
-
models.cost_functions.
cost_SIRD
(self, pars, dataset, initial, t, w)¶ The function to compute the error to guide the learning algorithm. It computes the quadratic error.
Parameters: - p (tuple) – Tuple with Beta and r parameters, respectivelly.
- S (array) – The suceptible data values.
- I (array) – The infected data values.
- initial (array) – The initial values of suceptible and infected, respectivelly.
- t (array) – The time respective to each sample.
- w (array) – The weight respective to the suceptible and infected errors.
Returns: The sum of the quadratic error, between simulated and real data.
Return type: float
-
models.cost_functions.
cost_dSIR
(self, pars, dataset, initial, t, w)¶ The function to compute the error to guide the learning algorithm. It computes the quadratic error.
Parameters: - p (tuple) – Tuple with Beta and r parameters, respectivelly.
- S (array) – The suceptible data values.
- I (array) – The infected data values.
- initial (array) – The initial values of suceptible and infected, respectivelly.
- t (array) – The time respective to each sample.
- w (array) – The weight respective to the suceptible and infected errors.
Returns: The sum of the quadratic error, between simulated and real data.
Return type: float
Differential Models¶
-
models.differential_models.
NSIR
(self, y, t, beta, r, betan, alpha, rn, *args)¶
-
models.differential_models.
SEIR
(self, y, t, Beta, r, sigma)¶ The function that computes the diferential set of equations of the SEIR Epidemic Model.
Parameters: - y (tuple) – Tuple with the suceptible and infected data.
- t (array) – The time respective to each y set of samples.
- Beta (float) – The Beta parameter.
- r (float) – The r parameter.
- sigma (float) – The sigma parameter.
Returns: The derivative of the suceptible and infected data.
Return type: tuple
-
models.differential_models.
SIR
(self, y, t, parameters, *args)¶ The function that computes the diferential set of equations of the SIR Epidemic Model.
Parameters: - y (tuple) – Tuple with the suceptible and infected data.
- t (array) – The time respective to each y set of samples.
- Beta (float) – The Beta parameter.
- r (float) – The r parameter.
Returns: The derivative of the suceptible and infected data.
Return type: tuple
-
models.differential_models.
SIRD
(self, y, t, parameters)¶ The function that computes the diferential set of equations of the SIRD Epidemic Model.
Parameters: - y (tuple) – Tuple with the suceptible and infected data.
- t (array) – The time respective to each y set of samples.
- Beta (float) – The Beta parameter.
- r (float) – The r parameter.
- mi (float) – The mi parameter.
Returns: The derivative of the suceptible and infected data.
Return type: tuple
Module contents¶
copyright: | 2010 Marcelo Lima |
---|---|
license: | BSD-3-Clause |