Beispiel #1
0
def evaluate_ind(individual):
    """
    Fitness function.
    Trains a randomly initiated ESN using the parameters in 'individual' and
    the config file.

    Returns touple with error metric (touple required by DEAP)
    """

    parameters = paramhelper.get_parameters(individual)

    # Run a few times to get the average error over several networks.
    n_eval = optconfig['n_eval']
    errors = np.empty((n_eval, ), dtype=float)

    for i in range(n_eval):
        _, errors[i] = esnet.run_from_config(Xtr, Ytr, Xval, Yval, parameters)

    error = np.mean(errors)

    # Do we have dimensionality reduction?
    if parameters['n_dim'] is None:
        return error,
    else:
        return error, float(
            parameters['n_dim']) / parameters['n_internal_units']
Beispiel #2
0
def single_run(dummy):
    """
    This function will be run by the workers.
    """
    _,error = esnet.run_from_config(Xtr, Ytr, Xte, Yte, config)

    return error
Beispiel #3
0
def single_run(dummy):
    """
    This function will be run by the workers.
    """
    Y_pred, error = esnet.run_from_config(Xtr, Ytr, Xte, Yte, config)
    np.savetxt('Y_pred_prep', Y_pred)

    return error
def single_run(dummy):
    """
    This function will be run by the workers.
    """
    predictions, error = esnet.run_from_config(Xtr, Ytr, Xte, Yte, config,
                                               Yscaler)

    predictions = Yscaler.inverse_transform(predictions)
    allPredictions.append(predictions)

    return error
Beispiel #5
0
def main():
    averages = []
    predictions_error = []
    predictions = []
    reals = []
    startPoint = args.count

    #For the first few predictions, use the last error as prediction
    dataPath = '/home/minh/PycharmProjects/Ensemble/PythonESN/data/edgar_historical'
    count = 0
    """with open(dataPath,'r') as f:
        for line in f:
            if count>0:
                data = line.split(',')
                total = 0
                for i in range(5):
                    total += float(data[i])
                averages.append(total/5)
                reals.append(float(data[6]))
            count+=1"""
    """count = 0
    with open(dataPath,'r') as f:
        for line in f:
            if count>0:
                if count>(startPoint+2):
                    break
                else:
                    data = line.split(',')
                    total = 0
                    for i in range(5):
                        total += float(data[i])
                    predictions.append(float(data[6])-total/5)
            count+=1
    print('predictions:',predictions)"""

    # Run in parallel and store result in a numpy array
    X, Y = esnet.load_from_text(args.data)
    Xtr, Ytr, _, _, Xte, Yte, Yscaler = esnet.generate_datasets(X[:startPoint], Y[:startPoint])
    Yhat, error = esnet.run_from_config(Xtr, Ytr, Xte, Yte, config, Yscaler)
    Yhat = np.ceil(Yscaler.inverse_transform(Yhat))
    predictions_error.append(Yhat[len(Yhat) - 1][0])

    """for i in range(startPoint,len(X)):
        Xtr, Ytr, _, _, Xte, Yte, Yscaler = esnet.generate_datasets(X[:i], Y[:i])
        if i<800:
            config['n_drop'] = int(i/8)
        else:
            config['n_drop'] = 100
        Yhat, error = esnet.run_from_config(Xtr, Ytr, Xte, Yte, config)
        Yhat = np.ceil(Yscaler.inverse_transform(Yhat))
        #print('predictions:',Yhat)
        #print('error:',error)
        predictions_error.append(Yhat[len(Yhat)-1][0])
        count+=1
        if count%100==0:
            print('predictions made:',count)"""

    curPath = os.getcwd().split('/')
    writePath = ''
    for i in range(len(curPath)):
        writePath += curPath[i] + '/'
    configs = args.esnconfig.split('/')
    writePath += 'predictions/predictions_' + configs[-1] + '_' + str(args.times)

    """with open(writePath, 'a') as f:
        f.write(str(np.ceil(Yhat[len(Yhat) - 1][0]))+'\n')"""
    with open (writePath, 'w') as f:
        for i in range(len(Yhat)):
            f.writelines(str(np.ceil(Yhat[i][0])) + '\n')