示例#1
0
    def asynchronousFinalize(self, batch):
        """
        Method updating all global estimators with the contributions of the new batch.
        """

        # Postprocess on finished batches
        for level in range(len(self.batchIndices[batch])):
            # update global estimators
            mda.updateGlobalMomentEstimator_Task(
                self.indices[level].qoiEstimator,
                self.batchIndices[batch][level].qoiEstimator,
                self.indices[level].costEstimator,
                self.batchIndices[batch][level].costEstimator,
                batch,
            )
            # delete COMPSs future objects no longer needed
            delete_object(
                self.batchIndices[batch][level].costEstimator,
                *self.batchIndices[batch][level].qoiEstimator,
            )
            # Update model coefficients for cost, bias, variance with new observations
            self.updatePredictors()

        for level in range(len(self.indices)):
            # synchronize estimator needed for checking convergence and updating hierarchy
            self.indices[level].qoiEstimator = get_value_from_remote(
                self.indices[level].qoiEstimator
            )
            self.indices[level].costEstimator = get_value_from_remote(
                self.indices[level].costEstimator
            )
示例#2
0
    def estimation(self, assemblerCoordinates=None):
        """
        For an entry of assembler, collect estimations from all indices corresponding to
        the same entry of estimatorsForAssembler. Then, pass this list to the assembleEstimation
        method of that entry of assembler.
        """

        # If nothing is specified, assemble all estimations
        if assemblerCoordinates is None:
            assemblerCoordinates = range(len(self.assemblers))

        # Extract current hierarchy from list of indices
        hierarchy = self.hierarchy()

        ## Get list of estimations for assemblers without duplicate calls

        # List of which assembler needs what estimations
        args = [self.estimatorsForAssembler[c] for c in assemblerCoordinates]
        # Convert nested list to nested tuple
        mapArg = [
            ((i, j), (v[0], tuple(v[1]))) for i, a in enumerate(args) for j, v in enumerate(a)
        ]
        # Create dictionary of {argument: [coord1, ...], ...}
        # such that args[coord1[0]][coord1[1]] = argument
        argMap = defaultdict(list)
        for t in mapArg:
            argMap[t[1]].append(t[0])
        # Initialise and fill list of estimations for assemblers
        estimations = [[[] for _ in a] for a in args]
        for estArgs, coords in argMap.items():
            # Compute this unique estimation
            est = self.indexEstimation(*estArgs)
            # Distribute it wherever is appeared in args
            for c in coords:
                estimations[c[0]][c[1]] = est

        # Run the corresponding estimation methods on this
        globalEstimations = []
        # Iterate over couples (coord,estimation)
        for c, e in zip(assemblerCoordinates, estimations):
            ge = self.assemblers[c].assembleEstimation(hierarchy, e)
            globalEstimations.append(ge)

        # Delete COMPSs objects
        # Flatten list of depth 2 then unpack
        delete_object(
            *chain.from_iterable(hierarchy),
            *chain.from_iterable(chain.from_iterable(estimations)),
        )

        return globalEstimations