Exemplo n.º 1
0
def getValidationData(vargs, data, debug):
    """
    Structure data for validating the model. Modifies data['opts']

    Args:
        vargs: validation data valxdata, valzdata
        data: shared alamo data options
        debug: Additional options may be specified and will be applied
                to the .alm
    """

    if vargs != ():
        debug["validation"] = True
        xvaldata = vargs[0]
        zvaldata = vargs[1]
        temp = np.shape(xvaldata)
        data["opts"]["nvaldata"] = temp[0]
        if len(np.shape(zvaldata)) == 1:
            zvaldata = np.reshape(zvaldata, (data["opts"]["nvaldata"], 1))
        if temp[1] != data["opts"]["ninputs"]:
            raise almerror.AlamoInputError(
                "Number of input variables inconsistent between x and xval"
            )
        temp = np.shape(zvaldata)
        if temp[0] != data["opts"]["nvaldata"] or temp[1] != data["opts"]["noutputs"]:
            raise almerror.AlamoInputError(
                "Problem with zval"
            )
        return xvaldata, zvaldata
Exemplo n.º 2
0
def checkinput(data, debug, xdata, zdata, vargs, kwargs):
    """
    Check the input data into doalamo for errors.

    Args:
        data/debug: shared default options for .alm file
        xdata: (numpy.array or list[real])
        zdata: (numpy.array or list[real)
        vargs:  Validation data
        kwargs: Additional options may be specified and will be applied
                to the .alm
    """

    # t = np.zeros([1, 1])
    kk = kwargs.keys()
    # First check vargs for validation set viability
    if len(vargs) > 0 and len(vargs) != 2:
        raise almerror.AlamoInputError(
            "Validation Xdata and Zdata must be"
            "specified in the following form: "
            "alamopy.doalamo(x,z,xval,zval)"
        )

    for arg in kk:
        if arg not in data["pargs"]["opts"] + data["pargs"]["stropts"] + data["pargs"][
            "lstopts"
        ] + data["pargs"]["set4"] + debug["pargs"] + ["xlabels", "zlabels"] + [
            "xval",
            "zval",
        ]:
            raise almerror.AlamoInputError(
                "The following argument given to"
                "alamo() is not understood: {}".format(arg)
            )

    # read keys for debug
    for key in debug["pargs"]:
        if key in kk:
            debug[key] = kwargs[key]

    if kwargs.get("almname", None) is not None:
        data["stropts"]["almname"] += ".alm"
Exemplo n.º 3
0
def almplot(res, show=True):
    try:
        import matplotlib.pyplot as plt
        import numpy as np
    except Exception:
        raise almerror.AlamoInputError(
            "Cannot plot, possibly missing matplotlib package")

    model = res['model']

    if type(model) is dict:
        firstKey = list(res['model'].keys())[0]
        model = res['model'][firstKey].replace(' - ', ' + -')
    else:
        model = res['model'].replace(' - ', ' + -')

    model = model.split('=')[1]
    model = model.split(' + ')
    if model[
            0] == ' ':  # if there are more than one terms, the first split is ' '
        model = model[1:]
    ndp = 100
    t = np.linspace(0.08, 1.7, ndp)
    out = np.zeros([3, ndp])
    clo = np.zeros(ndp)
    chi = np.zeros(ndp)
    coeff = np.zeros(ndp)

    for i in range(len(model)):
        coeff[i] = float(model[i].split(' * ')[0])
        if 'conf_inv' in res.keys():
            if type(res['conf_inv']) is dict:
                firstKey = list(res['conf_inv'].keys())[0]
                clo[i] = coeff[i] - float(
                    res['conf_inv'][firstKey][i].split('+/-')[1])
                chi[i] = coeff[i] + float(
                    res['conf_inv'][firstKey][i].split('+/-')[1])
            else:
                clo[i] = coeff[i] - float(res['conf_inv'][i].split('+/-')[1])
                chi[i] = coeff[i] + float(res['conf_inv'][i].split('+/-')[1])

    for i in range(ndp):
        out[0, i] = float(coeff[0]) * t[i]**1.2 \
            - float(coeff[1]) * t[i]**2 - float(coeff[2])
        if 'conf_inv' in res.keys():  # If confidence intervals exist
            out[1, i] = clo[0] * t[i]**1.2 - chi[1] * t[i]**2 - chi[2]
            out[2, i] = chi[0] * t[i]**1.2 - clo[1] * t[i]**2 - clo[2]

    plt.plot(t, out[0], 'b-')
    if 'conf_inv' in res.keys():
        plt.plot(t, out[1], 'r--', t, out[2], 'r--')
    if show:
        plt.show()
Exemplo n.º 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