Exemplo n.º 1
0
def test_basic():

    if has_alamo_flag:
        ndata = 10
        x = np.random.uniform([-2, -1], [2, 1], (ndata, 2))
        z = [0] * ndata
        # specify simulator as examples.sixcamel
        sim = examples.sixcamel
        for i in range(ndata):
            z[i] = sim(x[i][0], x[i][1])

        # Use alamopy's python function wrapper to avoid using ALAMO's I/O format
        almsim = wrapwriter(sim)
        # Call alamo through the alamopy wrapper
        res = alamo(x,
                    z,
                    almname='cam6',
                    monomialpower=(1, 2, 3, 4, 5, 6),
                    multi2power=(1, 2),
                    simulator=almsim,
                    expandoutput=True,
                    maxiter=20)  #,cvfun=True)
        #conf_inv = almconfidence(res)

        #print('Model: {}'.format(res['model']))
        #print('Confidence Intervals : {}'.format(conf_inv['conf_inv']))
        almplot(res, show=False)
Exemplo n.º 2
0
def main():
    # Specify number of poitns to be used in the training set
    # Validation data can be provided optionally
    ndata= 50
    nval = 500
    lb = [-15,-15]
    ub = [15,15]
    x = np.random.uniform(lb,ub,(ndata,2))
    xval = np.random.uniform(lb,ub,(nval,2))
    z = [0]*ndata
    zval = [0]*nval
    # specify simulator as examples.sixcamel
    sim = examples.ackley
    for i in range(ndata):
        z[i]=sim(x[i][0],x[i][1])
    for i in range(nval):
        zval[i] = sim(xval[i][0],xval[i][1])

    # Use alamopy's python function wrapper to avoid using ALAMO's I/O format
    almsim = alamopy.wrapwriter(sim)
    # Call alamo through the alamopy wrapper
    res = alamopy.doalamo(x,z,xval=xval,zval=zval,almname='ackley',monomialpower=(1,2,3,4,5,6),expfcns=1,multi2power=(1,2),expandoutput=True)
    # Calculate confidence intervals
    conf_inv = alamopy.almconfidence(res)

    print('Model: {}'.format(res['model']))
    print('Confidence Intervals : {}'.format(conf_inv['conf_inv']))
Exemplo n.º 3
0
def test_single_input_CV():

    if not alamopy.has_alamo():
        return False

    # Specify number of points to be used in the training set
    # Validation data can be provided optionally
    ndata = 10
    x = np.random.uniform([-2, -1], [2, 1], (ndata, 2))
    z = np.zeros((ndata, 1))
    # specify simulator as examples.sixcamel
    sim = sixcamel
    for i in range(ndata):
        z[i, 0] = sim(x[i][0], x[i][1])
        # z[i,1] = sim(x[i][0], x[i][1])

    # # Use alamopy's python function wrapper to avoid using ALAMO's I/O format
    almsim = alamopy.wrapwriter(sim)

    # NON GENERIC
    alamo_settings = {
        'almname': "cam6",
        'monomialpower': (1, 2, 3, 4, 5, 6),
        'multi2power': (1, 2),
        'simulator': almsim,
        'maxiter': 20,
        'cvfun': True
    }

    res = alamopy.doalamo(x, z, lmo=3)
Exemplo n.º 4
0
def _main():
    # Specify number of poitns to be used in the training set
    # Validation data can be provided optionally
    ndata = 10
    x = np.random.uniform([-2, -1], [2, 1], (ndata, 2))
    z = [0] * ndata
    # specify simulator as examples.sixcamel
    sim = examples.sixcamel
    for i in range(ndata):
        z[i] = sim(x[i][0], x[i][1])

    # Use alamopy's python function wrapper to avoid using ALAMO's I/O format
    almsim = alamopy.wrapwriter(sim)
    # Call alamo through the alamopy wrapper
    res = alamopy.doalamo(
        x,
        z,
        almname="cam6",
        monomialpower=(1, 2, 3, 4, 5, 6),
        multi2power=(1, 2),
        simulator=almsim,
        expandoutput=True,
        maxiter=20,
        cvfun=True,
    )
    #    print res
    print("Model: {}".format(res["model"]))
Exemplo n.º 5
0
def buildSimWrapper(data, debug):
    """ Builds an executable simulator to sample for data 
      
      Args:
        data:  shared alamo data options
        debug: Additional options may be specified and will be applied
                to the .alm
    """

    if not isinstance(data["stropts"]["simulator"], type("string")):
        try:
            data["stropts"]["simulator"] = data["stropts"][
                "simulator"].__name__
        except Exception:
            raise almerror.AlamoInputError(
                "Simulator must be provided as a string"
                "and obey ALAMOs simulator conventions"
                "OR must be a python function whose name"
                "can be obtained via .__name__")
        data["stropts"]["simulator"] = alamopy.wrapwriter(
            data["stropts"]["simulator"])
        debug["simwrap"] = True