Exemplo n.º 1
0
    def __init__(self, problem, dims, w=0.2):
        """
        Arguments
        ---------
        problem : Problem
            Pointer to the Problem object being wrapped.
        dims : int or list/tuple of ints
            Either the number of dimensions or a list of the dimension indices that this
            problem uses.
        w : float
            The value to use for all unaccounted for inputs where 0/1 is lower/upper bound.
        """
        self.problem = problem
        self.w = w

        if isinstance(dims, int):
            self.dims = np.arange(dims)
            assert dims <= problem.options["ndim"]
        elif isinstance(dims, (list, tuple, np.ndarray)):
            self.dims = np.array(dims, int)
            assert np.max(dims) < problem.options["ndim"]
        else:
            raise ValueError("dims is invalid")

        self.options = OptionsDictionary()
        self.options.declare("ndim", len(self.dims), types=int)
        self.options.declare("return_complex", False, types=bool)
        self.options.declare("name",
                             "R_" + self.problem.options["name"],
                             types=str)

        self.xlimits = np.zeros((self.options["ndim"], 2))
        for idim, idim_reduced in enumerate(self.dims):
            self.xlimits[idim, :] = problem.xlimits[idim_reduced, :]
Exemplo n.º 2
0
    def __init__(self, **kwargs):
        """
        Constructor where values of options can be passed in.

        For the list of options, see the documentation for the problem being used.

        Parameters
        ----------
        **kwargs : named arguments
            Set of options that can be optionally set; each option must have been declared.

        Examples
        --------
        >>> from smt.problems import Sphere
        >>> prob = Sphere(ndim=3)
        """
        self.options = OptionsDictionary()
        self.options.declare("ndim", 1, types=int)
        self.options.declare("return_complex", False, types=bool)
        self._initialize()
        self.options.update(kwargs)

        self.xlimits = np.zeros((self.options["ndim"], 2))

        self._setup()
def globalSurrogateModel(data, pr):
    pr.callingFunction = "globalSurrogate"
    data["prediction"] = pr.predict(data)

    ttdE = testTrainData(data, pr, encoded=True)
    ttdNE = testTrainData(data, pr, encoded=False)

    options = OptionsDictionary()
    options.declare("ndim", 1.0, types=float)
    options.declare("return_complex", False, types=bool)
    xlimits = np.zeros((int(options["ndim"]), 4))
    xlimits[:, 0] = -2.0
    xlimits[:, 1] = 2.0
    funXLimits = xlimits
    ndim = 4

    # models retrieved from https://github.com/SMTorg/smt/blob/master/tutorial/SMT_Tutorial.ipynb
    models = pd.Series()
    models["linear"] = Model(linearModel, ttdE)
    models["quadratic"] = Model(quadraticModel, ttdE)
    # models["kriging"] = Model(kriging, ttdE, ndim=ndim)
    # models["KPLSK"] = Model(kPLSK, ttdE)
    models["IDW"] = Model(iDW, ttdE)
    models["RBF"] = Model(rBF, ttdE)
    #models["RMTBSimba"] = Model(rMTBSimba, ttdNE,  xL = funXLimits)
    #models["GEKPLS"] = Model(gEKPLS, ttdNE, xL = funXLimits, ndim = ndim)
    #models["DEKPLS"] = Model(dEKPLS, ttdNE, xL = funXLimits, ndim = ndim)

    for model in models:
        compareToOrig(model.t, model.title, model.xtest, model.ytest)
Exemplo n.º 4
0
    def __init__(self, **kwargs):
        """
        Constructor where values of options can be passed in.

        For the list of options, see the documentation for the surrogate model being used.

        Parameters
        ----------
        **kwargs : named arguments
            Set of options that can be optionally set; each option must have been declared.

        Examples
        --------
        >>> from smt.surrogate_models import RBF
        >>> sm = RBF(print_global=False)
        """
        self.options = OptionsDictionary()

        self.supports = supports = {}
        supports["training_derivatives"] = False
        supports["derivatives"] = False
        supports["output_derivatives"] = False
        supports["adjoint_api"] = False
        supports["variances"] = False

        declare = self.options.declare

        declare(
            "print_global",
            True,
            types=bool,
            desc="Global print toggle. If False, all printing is suppressed",
        )
        declare(
            "print_training",
            True,
            types=bool,
            desc="Whether to print training information",
        )
        declare(
            "print_prediction",
            True,
            types=bool,
            desc="Whether to print prediction information",
        )
        declare(
            "print_problem",
            True,
            types=bool,
            desc="Whether to print problem information",
        )
        declare("print_solver",
                True,
                types=bool,
                desc="Whether to print solver information")

        self._initialize()
        self.options.update(kwargs)
        self.training_points = defaultdict(dict)
        self.printer = Printer()
Exemplo n.º 5
0
    def __init__(self, **kwargs):
        """
        Constructor where values of options can be passed in.

        For the list of options, see the documentation for the problem being used.

        Parameters
        ----------
        **kwargs : named arguments
            Set of options that can be optionally set; each option must have been declared.

        Examples
        --------
        >>> import numpy as np
        >>> from smt.sampling_methods import Random
        >>> sampling = Random(xlimits=np.arange(2).reshape((1, 2)))
        """
        self.options = OptionsDictionary()
        self.options.declare(
            "xlimits",
            types=np.ndarray,
            desc=
            "The interval of the domain in each dimension with shape nx x 2 (required)",
        )
        self._initialize()
        self.options.update(kwargs)
Exemplo n.º 6
0
    def __init__(self, problem, dims, w=0.2):
        """
        Arguments
        ---------
        problem : Problem
            Pointer to the Problem object being wrapped.
        dims : int or list/tuple of ints
            Either the number of dimensions or a list of the dimension indices of problem
            that this problem uses.
        w : float
            The value to use for all unaccounted for inputs where 0/1 is lower/upper bound.
        """
        self.problem = problem
        self.w = w

        if isinstance(dims, int):
            self.dims = np.arange(dims)
            assert dims <= problem.options['ndim']
        elif isinstance(dims, (list, tuple)):
            self.dims = np.array(dims, int)
            assert numpy.max(dims) < problem.options['ndim']
        else:
            raise ValueError('dims is invalid')

        self.options = OptionsDictionary()
        self.options.declare('ndim', len(self.dims), types=int)
        self.options.declare('name',
                             'R_' + self.problem.options['name'],
                             types=str)

        self.xlimits = np.zeros((self.options['ndim'], 2))
        for idim in self.dims:
            self.xlimits[idim, :] = problem.xlimits[self.dims[idim], :]
Exemplo n.º 7
0
    def __init__(self, ndim=1, width=10.0):
        self.problem = TensorProduct(ndim=ndim, func="tanh", width=width)

        self.options = OptionsDictionary()
        self.options.declare("ndim", ndim, types=int)
        self.options.declare("return_complex", False, types=bool)
        self.options.declare("name", "NdimStepFunction", types=str)

        self.xlimits = self.problem.xlimits
Exemplo n.º 8
0
    def __init__(self, ndim=1, w=0.2):
        self.problem = ReducedProblem(CantileverBeam(ndim=3*ndim), np.arange(1, 3*ndim, 3), w=w)

        self.options = OptionsDictionary()
        self.options.declare('ndim', ndim, types=int)
        self.options.declare('return_complex', False, types=bool)
        self.options.declare('name', 'NdimCantileverBeam', types=str)

        self.xlimits = self.problem.xlimits
Exemplo n.º 9
0
    def __init__(self, **kwargs):
        self.mtx = None
        self.rhs = None

        self.options = OptionsDictionary()
        self.options.declare('print_init', True, types=bool)
        self.options.declare('print_solve', False, types=bool)
        self._declare_options()
        self.options.update(kwargs)
Exemplo n.º 10
0
    def __init__(self, ndim=1, width=10.0):
        self.problem = TensorProduct(ndim=ndim, func='tanh', width=width)

        self.options = OptionsDictionary()
        self.options.declare('ndim', ndim, types=int)
        self.options.declare('return_complex', False, types=bool)
        self.options.declare('name', 'NdimStepFunction', types=str)

        self.xlimits = self.problem.xlimits
Exemplo n.º 11
0
    def __init__(self, **kwargs):
        self.mtx = None
        self.rhs = None

        self.options = OptionsDictionary()
        self.options.declare("print_init", True, types=bool)
        self.options.declare("print_solve", True, types=bool)
        self._initialize()
        self.options.update(kwargs)
Exemplo n.º 12
0
    def __init__(self, **kwargs):
        self.options = OptionsDictionary()
        self.options.declare('ndim', 1, types=int)
        self._declare_options()
        self.options.update(kwargs)

        self.xlimits = np.zeros((self.options['ndim'], 2))

        self._initialize()
Exemplo n.º 13
0
    def __init__(self, ndim=1, w=0.2):
        self.problem = ReducedProblem(Rosenbrock(ndim=ndim + 1),
                                      np.arange(1, ndim + 1),
                                      w=w)

        self.options = OptionsDictionary()
        self.options.declare("ndim", ndim, types=int)
        self.options.declare("return_complex", False, types=bool)
        self.options.declare("name", "NdimRosenbrock", types=str)

        self.xlimits = self.problem.xlimits
Exemplo n.º 14
0
    def __init__(self, ndim=1, w=0.2):
        self.problem = ReducedProblem(RobotArm(ndim=2 * (ndim + 1)),
                                      np.arange(3, 2 * (ndim + 1), 2),
                                      w=w)

        self.options = OptionsDictionary()
        self.options.declare('ndim', ndim, types=int)
        self.options.declare('return_complex', False, types=bool)
        self.options.declare('name', 'NdimRobotArm', types=str)

        self.xlimits = self.problem.xlimits
Exemplo n.º 15
0
    def __init__(self, **kwargs):
        '''
        Constructor.

        Arguments
        ---------
        **kwargs : named arguments
            Set of options that can be optionally set; each option must have been declared.
        '''
        self.options = OptionsDictionary()
        self._declare_options()
        self.options.update(kwargs)

        self.training_pts = {'exact': {}}

        self.printer = Printer()
Exemplo n.º 16
0
    def __init__(self, **kwargs):
        """

        Examples
        --------
        >>> from methods import localGEKPLS
        >>> local1 = localGEKPLS(para_file='data/local1.npy')
        """
        self.options = OptionsDictionary()
        declare = self.options.declare
        declare(
            'para_file',
            values=None,
            types=str,
            desc=
            'Directory for loading / saving cached data; None means do not save or load'
        )

        self.options.update(kwargs)
        self._readPara()
Exemplo n.º 17
0
    def __init__(self, **kwargs):
        """
        Constructor where values of options can be passed in.

        For the list of options, see the documentation for the surrogate model being used.

        Parameters
        ----------
        **kwargs : named arguments
            Set of options that can be optionally set; each option must have been declared.

        Examples
        --------
        >>> from smt.applications import VFM
        >>> extension = VFM(type_bridge = 'Additive', name_model_LF = QP, name_model_bridge =
                           LS, X_LF = xLF, y_LF = yLF, X_HF = xHF, y_HF = yHF, options_LF =
                           dictOptionLFModel, options_bridge = dictOptionBridgeModel)
        """
        self.options = OptionsDictionary()

        self._initialize()
        self.options.update(kwargs)
Exemplo n.º 18
0
    def __init__(self, **kwargs):
        """

        Examples
        --------
        >>> from methods import localGEKPLS
        >>> clmodel = MoE(func='cl',nlocal=20)
        """
        self.options = OptionsDictionary()
        declare = self.options.declare
        declare('func',
                values=('Cl', 'Cd', 'Cm'),
                types=str,
                desc='Which model to construct')
        declare('nlocal',
                values=None,
                types=int,
                desc='How many local models to use')

        self.options.update(kwargs)
        self.models = []
        self.posteriors = []

        self._setup()
Exemplo n.º 19
0
 def __init__(self, **kwargs):
     self.options = OptionsDictionary()
     self.options.declare('xlimits', types=np.ndarray)
     self._declare_options()
     self.options.update(kwargs)