Exemplo n.º 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
Exemplo n.º 2
0
 def doematrix(self):
     nf = self.spinBox.value()
     self.appExcel = xw.App()
     wb = xw.books.active
     sht = wb.sheets[0]
     if self.factorialradioButton.isChecked():
         mdoe = ff2n(nf)
     elif self.fullradioButton.isChecked():
         seq = self.lineEdit.text
         seq = seq.split(',')
         factors = len(seq)
         levels = []
         for i in range(factors):
             levels.extend({int(float(seq[i]))})
         mdoe = fullfact(levels)
     elif self.pbradioButton.isChecked():
         mdoe = pbdesign(nf)
     sht.range('A1').value = mdoe
Exemplo n.º 3
0
 def get_orthogonal_stacking_voting(self, given_modalities, clf):
     estimators = []
     ort = pbdesign(len(given_modalities))
     #print(ort)
     for id, trial in enumerate(ort):
         mods = []
         for idx, val in enumerate(trial):
             if val == 1:
                 mods.append(given_modalities[idx])
         if len(mods) > 0:
             text_pipe = Pipeline([
                 ('select',
                  filter_cols(self.modalities_df.loc[
                      self.modalities_df.modality.isin(mods), 'feature'])),
                 ('pred', clf)
             ])
             estimators.append((str(id) + str(trial), text_pipe))
     clf_stacking = StackingClassifier(estimators=estimators,
                                       final_estimator=LogisticRegression(),
                                       n_jobs=-1)
     clf_voting = VotingClassifier(estimators=estimators, voting='soft')
     return clf_voting, clf_stacking
Exemplo n.º 4
0
 def get_orthogonal_large_voting_stacking(self, given_modalities):
     given_modalities = list(given_modalities)
     estimators = []
     for i in range(3):
         random.shuffle(given_modalities)
         ort = pbdesign(len(given_modalities))
         #print(ort)
         for id, trial in enumerate(ort):
             mods = []
             for idx, val in enumerate(trial):
                 if val == 1:
                     mods.append(given_modalities[idx])
             if len(mods) > 0:
                 multinomal = make_pipeline(  # improves
                     Normalizer(norm="max"),
                     MultinomialNB(alpha=0.01, fit_prior=True))
                 logistic = make_pipeline(  # improve
                     MaxAbsScaler(),
                     LogisticRegression(C=10.0, dual=False, penalty="l2"))
                 for cl in [
                         ExtraTreesClassifier(n_jobs=-1), multinomal,
                         logistic
                 ]:
                     text_pipe = Pipeline([
                         ('select',
                          filter_cols(self.modalities_df.loc[
                              self.modalities_df.modality.isin(mods),
                              'feature'])), ('pred', cl)
                     ])
                     estimators.append(
                         (str(id) + str(trial) + str(cl) + str(i),
                          text_pipe))
     clf_stacking = StackingClassifier(estimators=estimators,
                                       final_estimator=LogisticRegression(),
                                       n_jobs=-1)
     clf_voting = VotingClassifier(estimators=estimators, voting='soft')
     return clf_voting, clf_stacking
Exemplo n.º 5
0
def plackett_burmann(parameters, translator, tile_fixed_values):
	"""
	This function generates the doe plan for the experiment. If a parameters
	has more than two values, this function takes the first and the last
	elements.

	Parameters:
		- parameters:      the list of parameters generated by build_doe_space
		- translator:      the translator dictionary generated by build_doe_space
		- tile_same_value: if True, than the tiling value is propagated on all the dimensions

	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 most two levels
	for index, p in enumerate(parameters):
		if len(p) > 2:
			parameters[index] = [p[0], p[-1]]

	# count how many parameters have two levels
	dynamic_parameters = []
	constant_parameters = []
	for index, p in enumerate(parameters):
		if len(p) == 2:
			dynamic_parameters.append(index)
		else:
			constant_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 = doe.pbdesign(len(dynamic_parameters))

	# 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])


		# 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

		print('\n')

	# return the plan
	return plan
Exemplo n.º 6
0
    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