コード例 #1
0
    def _processor(self, model, setting_df):
        """
        Generate multi-processor for parameter estimation,
        registering theoretical data and phase units.

        Args:
            model (covsirphy.ModelBase): ODE model
            setting_df (pandas.DataFrame):
                Index reset index
                Columns
                    - (float): parameter values from 0 to 1.0
                    - Rt (float): reproduction number
                    - step_n (int): step number of simulation

        Returns:
            covsirphy.MPEstimator: multi-processor for parameter estimation
        """
        units = []
        # Instance to save theoretical data
        example_data = ExampleData(tau=self.tau, start_date="01Jan2020")
        # Population values
        population = model.EXAMPLE[self.N.lower()]
        population_data = PopulationData(filename=None)
        # Register data for each setting
        for (i,
             setting_dict) in enumerate(setting_df.to_dict(orient="records")):
            name = f"{model.NAME}_{i}"
            step_n = setting_dict[self.STEP_N]
            param_dict = {
                k: v
                for (k, v) in setting_dict.items() if k in model.PARAMETERS
            }
            # Add theoretical data
            example_data.add(model,
                             step_n=step_n,
                             country=name,
                             param_dict=param_dict)
            # Population
            population_data.update(population, country=name)
            # Phase unit
            snl = Scenario(example_data,
                           population_data,
                           country=name,
                           auto_complement=False)
            snl.add()
            unit = snl[self.MAIN].unit("last").del_id().set_id(country=name)
            units.append(unit)
        # Multi-processor for parameter estimation
        processor = MPEstimator(model,
                                jhu_data=example_data,
                                population_data=population_data,
                                tau=self.tau)
        return processor.add(units)
コード例 #2
0
 def _init_scenario(self):
     """
     Initialize the scenario classes of registered countries.
     """
     self.scenario_dict = {
         country: Scenario(
             self.jhu_data, self.population_data, country=country, tau=self.tau)
         for country in self._countries
     }
コード例 #3
0
    def _processor(self, model, setting_df, timeout, allowance):
        """
        Generate multi-processor for parameter estimation,
        registering theoretical data and phase units.

        Args:
            model (covsirphy.ModelBase): ODE model
            setting_df (pandas.DataFrame):
                Index reset index
                Columns
                    - (float): parameter values from 0 to 1.0
                    - Rt (float): reproduction number
                    - step_n (int): step number of simulation
            timeout (int): time-out of run
            allowance (tuple(float, float)): the allowance of the predicted value

        Returns:
            list[covsirphy.Scenario]: list of Scenario instances
        """
        scenarios = []
        # Instance to save theoretical data
        example_data = ExampleData(tau=self._tau, start_date="01Jan2020")
        # Population values
        population = model.EXAMPLE[self.N.lower()]
        population_data = PopulationData(filename=None)
        # Register data for each setting
        for (i, setting_dict) in enumerate(setting_df.to_dict(orient="records")):
            name = f"{model.NAME}_{i}"
            step_n = setting_dict[self.STEP_N]
            param_dict = {k: v for (k, v) in setting_dict.items() if k in model.PARAMETERS}
            # Add theoretical data
            example_data.add(model, step_n=step_n, country=name, param_dict=param_dict)
            # Population
            population_data.update(population, country=name)
            # Phase unit
            snl = Scenario(country=name, auto_complement=False)
            snl.register(example_data, population_data)
            snl.add()
            snl.estimate(model, timeout=timeout, allowance=allowance)
            scenarios.append(snl)
        return scenarios