Esempio n. 1
0
def mso_separation_task():
    """ multiple_superimposed_oscillators separation into the components"""
    input_range = np.arange(3000) #np.array([range(2000)])
    timescale=10.0
    osc1 = np.sin(input_range/timescale)
    osc2 = np.sin(2.1*input_range/timescale)
    osc3 = np.sin(3.4*input_range/timescale)
    train_target = np.column_stack((osc1, osc2, osc3))
    train_input = osc1*np.cos(osc2+2.345*osc3)
    train_input = train_input[:, None] #1d->2d

    machine = ESN(1, 800, leak_rate=0.5)
    print 'Starting training...'
    start = time.time()
    trainer = LinearRegressionReadout(machine)
    trainer.train(train_input[:2000], train_target[:2000])
    print 'Training Time: ', time.time() - start, 's'
    prediction = trainer.predict(train_input[2000:])
    mse = error_metrics.mse(prediction,train_target[2000:])
    nrmse = error_metrics.nrmse(prediction,train_target[2000:])
    print 'MSE: ', mse, 'NRMSE:' , nrmse
    
    plt.subplot(3,1,1)
    plt.plot(train_input[2800:3000])
    plt.title('Input')
    plt.subplot(3,1,2)
    plt.plot(train_target[2800:3000])
    plt.title('Targets')
    plt.subplot(3,1,3)
    plt.plot(prediction[800:1000])
    plt.title('Predictions')
    plt.show()
    
    return nrmse
Esempio n. 2
0
def memory_task(N=15, delay=20):
    print "Memory Task"
    #print "create data..."
    #train_input, train_target = Oger.datasets.memtest(n_samples=1, sample_len=10000, n_delays=delay)
    #test_input, test_target = Oger.datasets.memtest(n_samples=1, sample_len=1000, n_delays=delay)
    #np.savez('data/memory_task_data', train_input, train_target, test_input, test_target)
    
    train_input, train_target, test_input, test_target = load_arrays('data/memory_task_data')
    
    best_capacity = 0
    for i in range(5):
        #print "train machine..."
        machine = ESN(1,N)
        trainer = LinearRegressionReadout(machine)
        trainer.train(train_input[0], train_target[0])
        
        #print "predict..."
        echo, prediction = trainer.predict(test_input[0])
        memory_capacity = -error_metrics.mem_capacity(prediction, test_target[0])
        mse = error_metrics.mse(prediction,test_target[0])
        printf("%d Memory Capacity: %f MSE: %f\n" , i, memory_capacity, mse)
        
        if memory_capacity > best_capacity:
            best_capacity = memory_capacity
    
    print 'Highest Capacity: ', best_capacity 
    return best_capacity