Exemple #1
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']))
Exemple #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']))
Exemple #3
0
def test_basic():

    has_alamo_flag = alamopy.multos.has_alamo()

    x = [[0.17361977, -0.44326123], [-0.30192964, 0.68955226],
         [-1.98112458, -0.75686176], [0.68299634, 0.65170551],
         [-1.45317364, 0.15018666], [1.56528782, -0.58159576],
         [-1.25868712, -0.78324622], [-1.12121003, 0.95724757],
         [1.2467326, -0.65611797], [1.26489899, -0.45185251]]
    z = [
        -0.58978634828943055, -0.85834512885363479, 4.0241154669754113,
        0.91057814668811488, 1.9147616212616931, 0.29103827202206878,
        2.4290896722960778, 0.99199475534877579, 0.59688699266830847,
        1.167850366995701
    ]
    xival = [[5, 5], [2, 2]]
    zival = [5, 2]

    if not has_alamo_flag:
        alamo(x, z, savepyfcn=False)  #, xval=xival, zval=zival, mock=True)

    # alamo(x, z, xlabels=["T", "V"], zlabels= ["P"], savepyfcn=False)

    #doalamo(x, z, xval=xival, zval=zival, lmo=3, savepyfcn=False)

    else:
        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)
Exemple #4
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