How to use the anypytools.generate_macros.MacroGenerator function in anypytools

To help you get started, we’ve selected a few anypytools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AnyBody-Research-Group / AnyPyTools / anypytools / generate_macros.py View on Github external
raise ImportError('The pyDOE package must be install to use this class')

        # Only generate LHS values if user requested more than macros, since the
        # first macro is allways the mean value
        if self.number_of_macros > 1:
            # Create the Latin hyper cube sample matrix. This is used by the
            # individual macro generator functions when macros are created.
            self.lhd = pyDOE.lhs(self.LHS_factors,  samples=self.number_of_macros-1,
                                 criterion = self.criterion,
                                 iterations = self.iterations)

        return super(LatinHyperCubeMacroGenerator,self).generate_macros(batch_size)



class PertubationMacroGenerator(MacroGenerator):
    """ TODO: Make a class that can generate macros for pertubation studies


    """
    def __init__(self, pertubationfactor = 1e-4):
        super(self.__class__,self).__init__(number_of_macros = 1)

        self.pertubationfactor = pertubationfactor


    def _generator_set_value_designvar(self, var, value, i_designvar):
        for counter in range(self.number_of_macros):
            if counter == i_designvar:
                yield self._create_set_value_cmd(var, value+self.pertubationfactor)
            else:
                yield self._create_set_value_cmd(var, value)
github AnyBody-Research-Group / AnyPyTools / anypytools / generate_macros.py View on Github external
yield self._build_macro(i_macro)
            else:
                if self._new_batch_resets_counter:
                    macro_counter = i_macro % batch_size
                else:
                    macro_counter = i_macro
                macro_batch.append( self._build_macro(macro_counter) )
                if macro_counter+1 >= batch_size:
                    yield macro_batch
                    macro_batch = []

        if len(macro_batch):
            yield macro_batch


class MonteCarloMacroGenerator(MacroGenerator):
    """ Generates AnyScript macros for monte carlos studies.

    Class for building AnyScript macros for Monte Carlo parameter studies.
    This class extends the MacroGenerator class with methods, which can randomly
    vary parameters across the generated macros.

    The class contributes the following mehtods:

     - add_set_value_random_uniform()
         Create a set value macro with a uniform random distribution across
         macros

     - add_set_value_random_norm()
         Create a set value macro with a random distribution across
         macros
github AnyBody-Research-Group / AnyPyTools / anypytools / generate_macros.py View on Github external
raise TypeError('frozen_dist must be frozen distribtuion from \
                            scipy.stats.distributions' )
        mean_value = frozen_dist.mean()
        if isinstance(mean_value,np.ndarray):
            shape = mean_value.shape
        else:
            shape = None
        random_values = (frozen_dist.ppf(random(shape)) for _ in \
                                    range(self.number_of_macros-1) )
        macro_generator = self._generator_set_value(variable,
                                                    random_values,
                                                    special_first_values= mean_value)
        self.add_macro(macro_generator)


class LatinHyperCubeMacroGenerator(MacroGenerator):
    """ Generates AnyScript macros for parameter studies using Latin hyper cube
    sampling  .

    Class for building AnyScript macros for parameter studies with Latin
    Hypercube Sampling (LHS) of the parameter space. The number of generated
    macros determined the number of LHS samples.

    The class uses pyDOE package to generate the LHS data.

    This class extends the MacroGenerator class with the following methods:

     - add_set_value_LHS_uniform()
         Create a Set Value macro  command where the parameters are uniformly
         sampled using Latin Hypercube sampling across the macros

     - add_set_value_LHS()