def T12():
    '''
    Tests saving a model to file
    '''
    A = np.random.rand(32, 4)
    Y = (A.sum(axis=1)**2).reshape(-1, 1)
    m1 = MLPR([4, 4, 1], maxIter=16, name='t12ann1')
    m1.fit(A, Y)
    m1.SaveModel('./t12ann1')
    return True
def T1():
    '''
    Tests basic functionality of MLPR
    '''
    A = np.random.rand(32, 4)
    Y = np.random.rand(32, 1)
    a = MLPR([4, 4, 1], maxIter=16, name='mlpr1')
    a.fit(A, Y)
    a.score(A, Y)
    a.predict(A)
    return True
def T9():
    '''
    Tests if multiple MLPRs can be created without affecting each other
    '''
    A = np.random.rand(32, 4)
    Y = (A.sum(axis=1)**2).reshape(-1, 1)
    m1 = MLPR([4, 4, 1], maxIter=16)
    m1.fit(A, Y)
    s1 = m1.score(A, Y)
    m2 = MLPR([4, 4, 1], maxIter=16)
    m2.fit(A, Y)
    s2 = m1.score(A, Y)
    if s1 != s2:
        return False
    return True
def T8():
    '''
    Tests if multiple MLPRs can be created without affecting each other
    '''
    A = np.random.rand(32, 4)
    Y = (A.sum(axis=1)**2).reshape(-1, 1)
    m1 = MLPR([4, 4, 1], maxIter=16)
    m1.fit(A, Y)
    R1 = m1.GetWeightMatrix(0)
    m2 = MLPR([4, 4, 1], maxIter=16)
    m2.fit(A, Y)
    R2 = m1.GetWeightMatrix(0)
    if (R1 != R2).any():
        return False
    return True
def T14():
    '''
    Tests saving and restore a model
    '''
    A = np.random.rand(32, 4)
    Y = (A.sum(axis=1)**2).reshape(-1, 1)
    m1 = MLPR([4, 4, 1], maxIter=16, name='t12ann1')
    m1.fit(A, Y)
    m1.SaveModel('./t12ann1')
    R1 = m1.GetWeightMatrix(0)
    ANN.Reset()
    m1 = MLPR([4, 4, 1], maxIter=16, name='t12ann2')
    m1.RestoreModel('./', 't12ann1')
    R2 = m1.GetWeightMatrix(0)
    if (R1 != R2).any():
        return False
    return True
Пример #6
0
print(stockData2)

print(scale(stockDataASC))

# to get only specific columns of data from a array use :
# data[:, [1, 9]] where data is array and you want columns 1, 9 (index start from 0)

# scale the stock data, volume to ease the calculations and fit within the data range

# Number of neurons in the input layer
# 4 neurons to indicate the candle stick doji patterns
# 4 neurons to indicate the previous most tested highs which are greater than previous day closing prices
# 4 neurons to indicate the previous most tested lows which are less than previous day closing prices
# 5 neurons to indicate the previous day open, close, high and low prices, and volume
i = 17
# Number of neurons in the output layer
# 5 neurons to indicate the current day open, close, high and low prices and volume
o = 5
#Number of neurons in the hidden layers
h = 17
#The list of layer sizes
layers = [i, h, h, h, h, h, h, h, h, h, o]
mlpr = MLPR(layers, maxIter=1000, tol=0.40, reg=0.001, verbose=True)
mlpr.fit()

#Begin prediction
yHat = mlpr.predict(A)
#Plot the results
mpl.plot(A, Y, c='#b0403f')
mpl.plot(A, yHat, c='#5aa9ab')
mpl.show()
Пример #7
0
#Number of neurons in the input layer
i = 4
#Number of neurons in the output layer
o = 4
#Number of neurons in the hidden layers
h = 4
#The list of layer sizes
layers = [i, h, o]
mlpr = MLPR(layers, maxIter = 10000, tol = 0.0010, reg = 0.001, verbose = True)

#Length of the hold-out period
n = len(A)
nDays = int(round(n*.3))
#Learn the data
mlpr.fit(A[0: (n - nDays)], Y[1:(n - nDays + 1)])

#Begin prediction
yHat = mlpr.predict(A[0: (n - 1)])
#Plot the results

# mPlotLib.plot(list(range(nDays - 1)), Y[(n-nDays + 1):, (0)].reshape(-1, 1), c='#b04fff')
# mPlotLib.plot(list(range(nDays - 1)), yHat[:, (0)].reshape(-1, 1), c='#000000')
# # # mPlotLib.plot(A[(n-nDays): (n-1)], yHat, c='#5aa9ab')
# mPlotLib.show()


# plot with various axes scales
mPlotLib.figure(1)
nDays = n
# linear