Ejemplo n.º 1
0
 def testMerge(self):
     if IGNORE_TEST:
         return
     NUM = 4
     statistics = self.mkStatistics(NUM)
     statistic = TimeseriesStatistic.merge(statistics)
     statistic.calculate()
     self.evaluateStatistic(statistic, count=NUM)
Ejemplo n.º 2
0
    def merge(cls, bootstrapResults, fitter=None):
        """
        Combines a list of BootstrapResult. Sets a fitter.

        Parameter
        ---------
        bootstrapResults: list-BootstrapResult
        fitter: ModelFitter

        Return
        ------
        BootstrapResult
        """
        if len(bootstrapResults) == 0:
            raise ValueError("Must provide a non-empty list")
        parameterDct = {p: [] for p in bootstrapResults[0].parameterDct}
        numIteration = sum([r.numIteration for r in bootstrapResults])
        bootstrapError = sum([b.bootstrapError for b in bootstrapResults])
        fittedStatistic = None
        if numIteration > 0:
            # Merge the logs
            logger = Logger.merge([b.logger for b in bootstrapResults])
            # Merge the statistics for fitted timeseries
            fittedStatistics = [
                b.fittedStatistic for b in bootstrapResults
                if b.fittedStatistic is not None
            ]
            fittedStatistic = TimeseriesStatistic.merge(fittedStatistics)
            # Accumulate the results
            for bootstrapResult in bootstrapResults:
                for parameter in parameterDct.keys():
                    parameterDct[parameter].extend(
                        bootstrapResult.parameterDct[parameter])
            #
        fitter.logger = Logger.merge([fitter.logger, logger])
        bootstrapResult = BootstrapResult(fitter,
                                          numIteration,
                                          parameterDct,
                                          fittedStatistic,
                                          bootstrapError=bootstrapError)
        bootstrapResult.setFitter(fitter)
        return bootstrapResult