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 """ if self.respOpt['algorithmType'] == 'boxbehnken': self.designMatrix = doe.bbdesign( len(self.gridInfo.keys()), center=self.respOpt['options']['ncenters']) elif self.respOpt['algorithmType'] == 'centralcomposite': self.designMatrix = doe.ccdesign( len(self.gridInfo.keys()), center=self.respOpt['options']['centers'], alpha=self.respOpt['options']['alpha'], face=self.respOpt['options']['face']) gridInfo = self.gridEntity.returnParameter('gridInfo') stepLength = {} for cnt, varName in enumerate(self.axisName): self.mapping[varName] = np.unique(self.designMatrix[:, cnt]).tolist() gridInfo[varName] = (gridInfo[varName][0], gridInfo[varName][1], InterpolatedUnivariateSpline( np.array([ min(self.mapping[varName]), max(self.mapping[varName]) ]), np.array([ min(gridInfo[varName][2]), max(gridInfo[varName][2]) ]), k=1)(self.mapping[varName]).tolist()) stepLength[varName] = [ round(gridInfo[varName][-1][k + 1] - gridInfo[varName][-1][k], 14) for k in range(len(gridInfo[varName][-1]) - 1) ] self.gridEntity.updateParameter("stepLength", stepLength, False) self.gridEntity.updateParameter("gridInfo", gridInfo) Grid.localInitialize(self) self.limit = self.designMatrix.shape[0]
def ccd(n, MAX, MIN): #modelo ccd rotable centrado en 0,0 de dimension n model = ccdesign(n,face='cci', alpha='r') # Escalado del modelo con A la coordenada escalada y B la coordenada sin escalar. # # Ax - Amin Bx - -1 #---------- = --------- # Amax-Amin 2 # # # (Bx - -1) x (Amax-Amin) # Ax = ----------- + Amin # 2 scaledmodel = ((model + 1)/2) * (np.subtract(MAX, MIN)) + MIN print(scaledmodel.shape) print(scaledmodel) return scaledmodel
def central_composite(parameters, translator, tile_fixed_values): """ This function generates the doe plan for the experiment. Parameters: - parameters: the list of parameters generated by build_doe_space - translator: the translator dictionary generated by build_doe_space Return: - the plan of the execution composed as a dictionary: keys: the name of the application build values: a list of tuples, where each tuple represents a single experiment """ # enforce that all the parameters have at least 5 levels for index, p in enumerate(parameters): # we assume that the first five value are for training if len(p) > 5: parameters[index] = [ p[0], p[1], p[2], p[3], p[4] ] # fix the input for fewer values if len(p) == 4: parameters[index] = [ p[0], p[1], p[2], p[3], p[3] ] if len(p) == 3: parameters[index] = [ p[0], p[0], p[1], p[2], p[2] ] if len(p) == 2: parameters[index] = [ p[0], p[0], p[0], p[1], p[1] ] # count how many parameters have two levels dynamic_parameters = [] constant_parameters = [] for index, p in enumerate(parameters):# NOTE: if I only give the option OMP or MPI as value, this will be a constant parameter if len(p) == 1: constant_parameters.append(index) else: dynamic_parameters.append(index) # prune the tile space constrained_parameters = {} for tile_p in tile_fixed_values: try: # consider the case where the tile size is fixed value = int(tile_fixed_values[tile_p]) if translator['optimizations'][tile_p] in dynamic_parameters: dynamic_parameters.remove(translator['optimizations'][tile_p]) constant_parameters.append(translator['optimizations'][tile_p]) parameters[translator['optimizations'][tile_p]] = [value] except ValueError: # consider the case where the tile value depends on another tile if translator['optimizations'][tile_p] in dynamic_parameters: dynamic_parameters.remove(translator['optimizations'][tile_p]) constrained_parameters[tile_p] = translator['optimizations'][tile_fixed_values[tile_p]] # generate the experiment matrix experiments_suggested = list(doe.ccdesign(len(dynamic_parameters))) # TODO: should MPIbuild end up in constant because it only have a single possible value: MPI ? experiments = [] for e_proposed in experiments_suggested: is_ok = True for e_accepted in experiments: equal = True for index, element in enumerate(e_accepted): if e_proposed[index] != element: equal = False break if equal: is_ok = False break if is_ok: experiments.append(e_proposed) # compose the plan plan = {} for e in experiments: # get the value of all the dynamic values values = {} for index, v in enumerate(e): real_index = dynamic_parameters[index] if v < -1: values[real_index] = str(parameters[real_index][0]) elif v == -1: values[real_index] = str(parameters[real_index][1]) elif v == 0: values[real_index] = str(parameters[real_index][2]) elif v == 1: values[real_index] = str(parameters[real_index][3]) elif v > 1: values[real_index] = str(parameters[real_index][4]) # add back the tile values for tile_p in constrained_parameters: values[translator['optimizations'][tile_p]] = values[constrained_parameters[tile_p]] # add the constants for c in constant_parameters: values[c] = str(parameters[c][0]) # TODO: MPIbuild, take from MPI ? if values[c] == 'omp_threads': values[c] = values[translator['omp_threads']['omp']] if values[c] == 'mpi_procs': values[c] = values[translator['mpi_procs']['mpi']] # create the run list with the right values run = ['' for x in values] for key in values: run[int(key)] = values[key] # perform the flag translation make_args, exe_args, openmp_flag, mpi_command, name1, name2 = value_to_flag_translation(run, translator) # add it to the plan try: plan[make_args].append((exe_args, openmp_flag, mpi_command, name1, name2)) except KeyError as itsok: plan[make_args] = [(exe_args, openmp_flag, mpi_command, name1, name2)] except: raise # return the plan return plan
def factor_to_value(x, min_val, max_val): d = max_val - min_val x = x * (d / 2.0) x = x + min_val + (d / 2.0) return x uniformity_df = pd.read_csv("uniformity.csv") min_pressure = 4 # torr max_pressure = 80 # torr min_h2_wf6 = 2 # ratio max_h2_wf6 = 10 # ratio # Experimenters used central composite inscribed (CCI) w/ 3 centerpoint runs design = ccdesign(2, center = (2, 1), alpha = 'r', face='cci') design_df = pd.DataFrame(design, columns = ['coded_pressure', 'coded_h2_wf6']) design_df = np.round(design_df, 2) # to match example data hand_rolled = (design_df.groupby(['coded_pressure', 'coded_h2_wf6']) .size() .reset_index() .rename(columns={0:'count'})) from_article = (uniformity_df.groupby(['coded_pressure', 'coded_h2_wf6']) .size() .reset_index() .rename(columns={0:'count'})) assert(hand_rolled.equals(from_article))
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