Exemplo n.º 1
0
def test():
    data = pd.read_csv("train.csv").values
    x = data[:, 1:]
    t = np.identity(10, dtype=np.uint8)[data[:, 0]]

    x = (x - x.min()) / x.max()
    x = (x - x.mean()) / x.std()

    validate = int(x.shape[0] * 0.75)

    x_train, t_train = x[:validate], t[:validate]
    x_test, t_test = x[validate:], t[validate:]

    network = NeuralNetwork(784, error="R2error", optimizer="Gradient")
    network.add(Layer(100, activation="Sigmoid"))
    network.add(Layer(50, activation="Sigmoid"))
    network.add(OutputLayer(10, activation="Softmax"))

    network.fit(x_train, t_train, epoch_time=EPOCH_TIME, batch_size=BATCH_SIZE)

    network.print_accurate(x_test, t_test)
Exemplo n.º 2
0
(x_train, y_train), (x_test, y_test) = mnist.load_data()

x_train = x_train.reshape(x_train.shape[0], 1, 28 * 28)
x_train = x_train.astype('float32')
x_train /= 255

y_train = np_utils.to_categorical(y_train)

x_test = x_test.reshape(x_test.shape[0], 1, 28 * 28)
x_test = x_test.astype('float32')
x_test /= 255
y_test = np_utils.to_categorical(y_test)

# Network
model = NeuralNetwork()
model.add(DenseLayer(28 * 28, 100))
model.add(ActivationLayer(tanh, dtanh))
model.add(DenseLayer(100, 50))
model.add(ActivationLayer(tanh, dtanh))
model.add(DenseLayer(50, 10))
model.add(ActivationLayer(tanh, dtanh))

model.use(mse, dmse)
model.fit(x_train[0:1000], y_train[0:1000], epochs=35, learning_rate=0.1)

# test on 3 samples
out = model.predict(x_test[0:3])
print("\n")
print("predicted values : ")
print(out, end="\n")
print("true values : ")
Exemplo n.º 3
0
import numpy as np

from network import NeuralNetwork
from layers import DenseLayer, ActivationLayer
from activations import tanh, dtanh
from losses import mse, dmse

x_train = np.array([[[0, 0]], [[0, 1]], [[1, 0]], [[1, 1]]])
y_train = np.array([[[0]], [[1]], [[1]], [[0]]])

model = NeuralNetwork()
model.add(DenseLayer(2, 3))
model.add(ActivationLayer(tanh, dtanh))
model.add(DenseLayer(3, 1))
model.add(ActivationLayer(tanh, dtanh))

model.use(mse, dmse)

model.fit(x_train, y_train, epochs=1000, learning_rate=0.1)

out = model.predict(x_train)
print(out)