コード例 #1
0
 def localInitialize(self):
   """
     Will perform all initialization specific to this Sampler. For instance,
     creating an empty container to hold the identified surface points, error
     checking the optionally provided solution export and other preset values,
     and initializing the limit surface Post-Processor used by this sampler.
     @ In, None
     @ Out, None
   """
   Grid.localInitialize(self)
   if   self.factOpt['algorithmType'] == '2levelfract':
     self.designMatrix = doe.fracfact(' '.join(self.factOpt['options']['orderedGen'])).astype(int)
   elif self.factOpt['algorithmType'] == 'pb':
     self.designMatrix = doe.pbdesign(len(self.gridInfo.keys())).astype(int)
   if self.designMatrix is not None:
     self.designMatrix[self.designMatrix == -1] = 0 # convert all -1 in 0 => we can access to the grid info directly
     self.limit = self.designMatrix.shape[0]        # the limit is the number of rows
コード例 #2
0
ファイル: uq_gsa.py プロジェクト: strespi/chemics-reactors
    def _generate_doe_design(self):
        """
        This function is responsible for generating the matrix of operating
        conditions used in the design of experiments. It supports all of the
        design types implemented by pyDOE with the exception of general full
        factorials (including mixed level factorials). Full factorials are only
        permitted to have two levels at the moment.

        Parameters
        ----------
        None

        Returns
        -------
        None, but updates the self object to have the needed auxiliary data
        """

        # Unpack the dictionary of DOE design parameters
        doe_type = self.doe_design['doe_args']['type']
        kwargs = self.doe_design['doe_args']['args']

        # Get the list of parameters to iterate over
        try:
            param_list = self.doe_design['doe_params']
        except:
            self._generate_doe_param_list()
            param_list = self.doe_design['doe_params']
        n = len(param_list)

        # Create the design matrix in coded units
        if doe_type == 'full2':  # Two level general factorial
            coded_design_matrix = pyDOE.ff2n(n)
        elif doe_type == 'frac':  # Fractional factorial
            gen = kwargs.pop('gen', None)
            if gen is None:
                raise ValueError(
                    'No generator sequence specified for a fractional factorial design.'
                )
            coded_design_matrix = pyDOE.fracfact(gen)
        elif doe_type == 'pb':  # Plackett-Burman
            coded_design_matrix = pyDOE.pbdesign(n)
        elif doe_type == 'bb':  # Box-Behnken
            coded_design_matrix = pyDOE.bbdesign(n, **kwargs)
        elif doe_type == 'cc':  # Central composite
            coded_design_matrix = pyDOE.ccdesign(n, **kwargs)
        elif doe_type == 'lh':  # Latin hypercube
            coded_design_matrix = pyDOE.lhs(n, **kwargs)
        elif doe_type == 'sob':  # Sobol' Lp-tau low discrepancy sequence
            samples = kwargs.pop('samples')
            coded_design_matrix = sobol_seq.i4_sobol_generate(n, samples)
        else:
            raise ValueError('Unrecognized DOE design option ' + doe_type)

        # Convert the coded design matrix into an uncoded design matrix (i.e.,
        # in terms of the raw operating conditions). This takes the minimum and
        # maximum values from the distributions and places the points
        # accordingly.
        a_array = np.zeros(n)  # Minimum
        b_array = np.zeros(n)  # Maximum
        for i in range(n):
            pkey = param_list[i]
            a_array[i] = self.doe_design['doe_param_dist'][pkey].a
            b_array[i] = self.doe_design['doe_param_dist'][pkey].b
        r_array = b_array - a_array  # Ranges for each dimension
        if doe_type in ['pb', 'bb', 'cc', 'frac', 'full2']:
            # These designs all have points clustered around a distinct center.
            # The coded matrix is in terms of unit perturbations from the
            # center, so we can just scale them by the ranges before adding the
            # center value. For these designs, we actually want to use half the
            # range so that the points that are supposed to be at the min/max
            # values end up there.
            c_array = (a_array + b_array) / 2  # Center is average of min, max
            doe_op_conds = coded_design_matrix * r_array / 2 + c_array
        elif doe_type in ['lh', 'sob']:
            # The Latin hypercube and Sobol' sequences space points between a
            # range. This means the coded design matrix has all elements on
            # (0, 1). Since we don't have a center point, we place the operating
            # conditions with respect to the minimum values.
            doe_op_conds = coded_design_matrix * r_array + a_array
        self.doe_design['doe_op_conds'] = doe_op_conds