Ejemplo n.º 1
0
def EvalPred(argsList):
    '''
    Function for multiprocessing of combo evaluation outside library
    argsList : ( args, combo, embedding, colNames, target )
    '''
    args = argsList[0]
    combo = argsList[1]
    embedding = argsList[2]
    colNames = argsList[3]
    target = argsList[4]

    # Extract the variable combination
    # Note that we prepend the time column (0,) as Prediction() requires
    embed = np.take(embedding, (0, ) + combo, axis=1)
    Names = [colNames[i] for i in combo]

    # Evaluate prediction skill
    rho, rmse, mae, header, output, smap_output = Prediction(
        embed, colNames, target, args)
    Result = {
        'names': Names,
        'rho': rho,
        'rmse': rmse,
        'mae': mae,
        'header': header,
        'output': output
    }

    return tuple((combo, Result))
Ejemplo n.º 2
0
def EvalLib(argsList):
    '''
    Function for multiprocessing of combo evaluation within library
    argsList : ( args, combo, embedding, colNames, target )
    '''
    args = argsList[0]
    combo = argsList[1]
    embedding = argsList[2]
    colNames = argsList[3]
    target = argsList[4]

    # Extract the variable combination
    # Note that we prepend the time column (0,) as Prediction() requires
    embed = np.take(embedding, (0, ) + combo, axis=1)

    # Evaluate prediction skill
    rho, rmse, mae, header, output, smap_output = Prediction(
        embed, colNames, target, args)

    return tuple((combo, round(rho, 5)))
Ejemplo n.º 3
0
def PredictFunc(argsEmbedding):
    '''
    Pool worker function called from PredictDecays() or SMapNL()
    '''

    args = argsEmbedding[0]
    embedding = argsEmbedding[1]
    colNames = argsEmbedding[2]
    target = argsEmbedding[3]
    outputType = argsEmbedding[4]

    # Prediction does not currently use colNames
    rho, rmse, mae, header, output, smap_output = Prediction(
        embedding, colNames, target, args)
    if 'Tp' in outputType:
        return tuple((args.Tp, round(rho, 3)))
    elif 'theta' in outputType:
        return tuple((args.theta, round(rho, 3)))
    else:
        raise Exception('PredictFunc() Invalid output specified.')
Ejemplo n.º 4
0
def EmbedPredict(args):
    '''
    Pool worker function called from EmbedDimensions()
    '''

    # if -e has been specified: use ReadEmbeddedData()
    # ReadEmbeddedData() sets args.E to the number of columns specified
    # if the -c (columns) and -t (target) options are used, otherwise
    # it uses args.E to read E columns.
    if args.embedded:
        # Set args.E so at least 10 dimensions are read.
        E = args.E
        args.E = 10
        embedding, colNames, target = ReadEmbeddedData(args)
        # Reset args.E for Prediction
        args.E = E

    else:
        # -e not specified, embed on each iteration
        embedding, colNames, target = EmbedData(args)

    rho, rmse, mae, header, output, smap_output = Prediction(
        embedding, colNames, target, args)
    return tuple((args.E, round(rho, 3)))
Ejemplo n.º 5
0
def Predict(args, data=None, colNames=None, target=None, source=Source.Python):
    '''
    Data input/embedding wrapper for EDM.Prediction() to compute:

      Simplex projection of observational data (Sugihara, 1990), or
      SMap    projection of observational data (Sugihara, 1994).

    There are two options for data file input, or an embedding can be
    passed in directly (data, colNames, target).

    If --embedding (-e) is specified, it is assumed that the data file
    or data input is already an embedding or multivariable data matrix.
    Otherwise, the data is embedded by EmbedData(). 

    If --embedding (-e) is specified and the data input parameter is None, 
    then the -i (inputFile) is processed by ReadEmbeddedData() which assumes
    the files consists of a .csv file formatted as:

       [ Time, Dim_1, Dim_2, ... ] 

    where Dim_1 is observed data, Dim_2 data offset by τ, Dim_3 by 2τ...
    The user can specify the desired embedding dimension E, which
    can be less than the total number of columns in the inputFile. 
    The first E + 1 columns (Time, D1, D2, ... D_E) will be returned.

    Alternatively, the data can be a .csv file with multiple simultaneous
    observations or delay embeddings (columns) where the columns to 
    embed and target to project are specified with the -c (columns)
    and -r (target) options. In all cases 'time' is required in column 0. 
 
    Embedding can be done with EDM.EmbedData() via the wrapper Embed.py. 
    Note: The embedded data .csv file will have fewer rows (observations)
    than the data input to EmbedData() by E - 1. 
    '''

    if args.embedded:
        if data is None:
            # args.inputFile is an embedding or multivariable data frame.
            # ReadEmbeddedData() sets args.E to the number of columns
            # if the -c (columns) and -t (target) options are used.
            embedding, colNames, target = ReadEmbeddedData(args)
        else:
            # Data matrix is passed in as parameter, no embedding needed
            embedding = data
            # target taken as-is from input parameters
    else:
        # args.inputFile are timeseries data to be embedded by EmbedData
        embedding, colNames, target = EmbedData(args, data, colNames)

    rho, rmse, mae, header, output, smap_output = Prediction(
        embedding, colNames, target, args)
    if source == Source.Jupyter:
        return {
            'rho': rho,
            'RMSE': rmse,
            'MAE': mae,
            'header': header,
            'prediction': output,
            'S-map': smap_output
        }
    else:
        return