def sampling(self, nx, xlimits, method='LHS', random_seed=10000):
     '''
     create nx samples bounded by xlimits using specified method.
     xlimits defines lb and ub, in np.array([[LB1, UB1], [LB2, UB2], ...]) format.
     method = 'LHS': Latin hypercube sampling, 'CCD': centralized composite design,
              'PBD': Plackett-Burman design, 'PB-CCD': Plackett-Burman centralized composite design
     '''
     n_var = xlimits.shape[0]
     # Sampling
     if method.lower() == 'lhs':
         x = DOE.lhs(n_var,
                     samples=nx,
                     criterion='correlation',
                     random_state=random_seed) * 2.0 - 1.0
     elif method.lower() == 'ccd':
         if n_var > 8:
             raise ValueError(
                 'number of variables is TOO LARGE for centralized composite design (CCD).'
             )
         if n_var > 7:
             warnings.warn(
                 'number of variables is TOO LARGE for centralized composite design (CCD).'
             )
         x = DOE.ccdesign(n_var,
                          center=(0, 1),
                          alpha='rotatable',
                          face='inscribed')
     elif method.lower() == 'pbd':
         x = DOE.pbdesign(n_var)
     elif method.lower() in ['pb-ccd', 'pbccd']:
         l = np.sqrt(n_var)
         x = DOE.pbdesign(n_var) / l
         x = np.append(x, -x / 2.0, axis=0)
         for idx in range(0, n_var):
             z = np.zeros((1, n_var))
             z[0, idx] = 1.0
             x = np.append(x, z, axis=0)
             z[0, idx] = -1.0
             x = np.append(x, z, axis=0)
         x = np.append(x, np.zeros((1, n_var)), axis=0)
     # Scale
     for idx in range(0, xlimits.shape[0]):
         x[:, idx] = (x[:, idx] + 1.0) / 2.0 * (
             xlimits[idx, 1] - xlimits[idx, 0]) + xlimits[idx, 0]
     # Return
     return x
Beispiel #2
0
def genDoe(nDV, doeMethod):
    if doeMethod == 'lhs':
        doeTable = DOE.lhs(nDV, samples=nDV * 10)
    elif doeMethod == 'pbdesign':
        doeTable = DOE.pbdesign(nDV)
    elif doeMethod == 'bbdesign':
        doeTable = DOE.bbdesign(nDV)
    else:
        print("Error, You have to check a parameter")
    return doeTable
Beispiel #3
0
    def pbd(self):
        """
        Get experiments corresponding to a Plackett-Burman design.
        """

        pb = pd.DataFrame(pbdesign(len(self.levels)), columns=self.names)
        pb = Data(pb)
        pb.standardize(scaler='minmax', target=None)

        self.design = pb.data
Beispiel #4
0
 def genDoe(self):
     if self.doeMethod == 'lhs':
         doeTable = DOE.lhs(self.nDV, samples=self.nDV * 10)
     elif self.doeMethod == 'pbdesign':
         doeTable = DOE.pbdesign(self.nDV)
         temp = len(doeTable) - 1
         for j in range(self.nDV):
             doeTable[temp, j] = 0
     elif self.doeMethod == 'bbdesign':
         doeTable = DOE.bbdesign(self.nDV, center=1)
     else:
         print("Error, You have to check a parameter")
     return doeTable
Beispiel #5
0
    def _generate_design(self, size):
        """
        Generate a Plackett-Burman DOE design.

        Parameters
        ----------
        size : int
            The number of factors for the design.

        Returns
        -------
        ndarray
            The design matrix as a size x levels array of indices.
        """
        doe = pyDOE2.pbdesign(size)

        doe[doe < 0] = 0  # replace -1 with zero

        return doe
Beispiel #6
0
def opmsens_write_cases(basefile, header, factors, scenario):
    """ Main Function for Writing out Scenario Cases

    This is the main function that controls the writing out of the various requested scenario cases (jobs). The
    function first calls the opmsens_checkerr routine to check for errors and then the opmsens_clean routine to
    remove previously created scenario files. After which the opmsens_write_param and opmsens_write_data functions are
    called to create the scenario PARAM and DATA files

    Parameters
    ----------
    basefile : str
        The basefile used to generate all the cases
    header : list
        A list of of header names
    factors : table
        A table of design factors
    scenario : str
        The type of scenario to be generated

    Returns
    ------
    None
    """

    # Check for Errors and Return if Errors Found
    checkerr = opmsens_check(basefile, header, factors, scenario)
    if checkerr:
        return ()
    #
    # Cleanup Existing Files
    #
    opmsens_clean(basefile)
    #
    # Define Factor and Job Data Frame
    #
    df = pd.DataFrame(factors, columns=header)
    df = df[df != ''].dropna()
    jobdf = pd.DataFrame()
    jobdf[header[1]] = df[header[1]]
    for slevel in ['Low', 'Best', 'High']:
        if slevel in scenario:
            jobdf[slevel] = df[slevel]

    nfactor = jobdf.shape[0]
    nlevel = jobdf.shape[1]
    #
    # Write PARAM and DATA Files
    #
    jobs = []
    jobstart = 1
    joberr = False
    jobdata = Path(basefile)
    jobparam = Path(basefile).with_suffix('.param')
    jobque = Path(basefile).with_suffix('.que')
    print('Scenario:  ' + scenario + ' Start')
    #
    # Low, Best and High Scenario
    #
    if 'Scenario' in scenario:
        jobnum = 0
        for joblevel in range(1, nlevel):
            (joberr, jobs) = opmsens_write_param(jobstart, jobnum, jobparam,
                                                 jobdata, jobs)
            if joberr:
                break
            joberr = opmsens_write_data(scenario, joblevel, nfactor, jobdf,
                                        jobstart, jobnum, jobdata)
            if joberr:
                break
            jobstart = jobstart + joblevel
    #
    # One Job per Factor
    #
    elif 'One Job per Factor' in scenario:
        for joblevel in range(1, nlevel):
            for jobnum in range(0, nfactor):
                (joberr, jobs) = opmsens_write_param(jobstart, jobnum,
                                                     jobparam, jobdata, jobs)
                if joberr:
                    break
                joberr = opmsens_write_data(scenario, joblevel, nfactor, jobdf,
                                            jobstart, jobnum, jobdata)
                if joberr:
                    break
            jobstart = jobstart + nfactor
    #
    # Factorial Low and High Full
    #
    elif 'Factorial' in scenario:
        #
        # Obtain DOE Matrix and Convert to Data Frame
        #
        doedata = pd.DataFrame()
        if 'Factorial Low and High Full' in scenario:
            doedata = pyDOE2.ff2n(nfactor) + 2

        if 'Factorial Low and High Plackett-Burman' in scenario:
            doedata = pyDOE2.pbdesign(nfactor) + 2

        if 'Factorial Low, Best and High Full' in scenario:
            doedata = (pyDOE2.fullfact([nlevel - 1] * nfactor)) - 1

        if 'Factorial Low, Best and High Box-Behnken' in scenario:
            doedata = pyDOE2.bbdesign(nfactor)

        doedf = pd.DataFrame(data=doedata).transpose()
        doedf = doedf.rename(columns=lambda x: 'RUN' + str(x + 1).zfill(3),
                             inplace=False)
        #
        # Set Factor Values
        #
        for n in range(0, nfactor):
            doedf.iloc[n, :] = doedf.iloc[n, :].replace(
                [1.0, 2.0, 3.0], [df.iloc[n, 2], df.iloc[n, 3], df.iloc[n, 4]])
        #
        # Merge Data Frames and Write Out Files
        #
        jobdf = pd.DataFrame()
        jobdf[header[1]] = df[header[1]]
        jobdf = pd.concat([jobdf, doedf], axis=1)
        nfactor = jobdf.shape[0]
        nlevel = jobdf.shape[1]
        jobstart = 0
        for joblevel in range(1, nlevel):
            jobnum = joblevel
            (joberr, jobs) = opmsens_write_param(jobstart, jobnum, jobparam,
                                                 jobdata, jobs)
            if joberr:
                break
            joberr = opmsens_write_data(scenario, joblevel, nfactor, jobdf,
                                        jobstart, jobnum, jobdata)
            if joberr:
                break

    print('Scenario:  ' + scenario + ' End')
    if not joberr:
        print('WriteQueu: Start')
        opmsens_write_queue(jobs)
        print('WriteQueu: End')

    return ()