Beispiel #1
0
 def test_hessian_assign_step_exception(self):
     with self.assertRaises(ValueError):
         # Don't have step parameter
         algorithms.Hessian(
             layers.Input(2) > layers.Sigmoid(3) > layers.Sigmoid(1),
             step=0.01,
         )
Beispiel #2
0
	def select_algorithm(self, algorithm, options=None):
		try:
			self.network = algorithms.LevenbergMarquardt(self.layers)
			opt = options
			print(opt[1])
			print("Wybrano optymalizator: " + str(algorithm))
		except RecursionError:
			print("Problem rekursji")
			return None

		if algorithm == 'GradientDescent':
			self.network = algorithms.GradientDescent(self.layers)
		if algorithm == 'LevenbergMarquardt':
			self.network = algorithms.LevenbergMarquardt(connection=self.layers, mu=opt[0], mu_update_factor=opt[1])
		if algorithm == 'Adam':
			self.network = algorithms.Adam(self.layers)
		if algorithm == 'QuasiNewton':
			self.network = algorithms.QuasiNewton(self.layers)
		if algorithm == 'Quickprop':
			self.network = algorithms.Quickprop(self.layers)
		if algorithm == 'MinibatchGradientDescent':
			self.network = algorithms.MinibatchGradientDescent(self.layers)
		if algorithm == 'ConjugateGradient':
			self.network = algorithms.ConjugateGradient(self.layers)
		if algorithm == 'Hessian':
			self.network = algorithms.Hessian(self.layers)
		if algorithm == 'HessianDiagonal':
			self.network = algorithms.HessianDiagonal(self.layers)
		if algorithm == 'Momentum':
			self.network = algorithms.Momentum(self.layers)
		if algorithm == 'RPROP':
			self.network = algorithms.RPROP(self.layers)
		if algorithm == 'IRPROPPlus':
			self.network = algorithms.IRPROPPlus(self.layers)
		if algorithm == 'Adadelta':
			self.network = algorithms.Adadelta(self.layers)
		if algorithm == 'Adagrad':
			self.network = algorithms.Adagrad(self.layers)
		if algorithm == 'RMSProp':
			self.network = algorithms.RMSProp(self.layers)
		if algorithm == 'Adamax':
			self.network = algorithms.Adamax(self.layers)
Beispiel #3
0
data = dataset.data
target = dataset.target.reshape((-1, 1))

data_scaler = preprocessing.MinMaxScaler((-3, 3))
target_scaler = preprocessing.MinMaxScaler()

data = data_scaler.fit_transform(data)
target = target_scaler.fit_transform(target)

x_train, x_test, y_train, y_test = train_test_split(data,
                                                    target,
                                                    train_size=0.85)

cgnet = algorithms.Hessian(
    connection=[
        layers.Sigmoid(13),
        layers.Sigmoid(50),
        layers.Sigmoid(10),
        layers.Output(1),
    ],
    verbose=True,
)

cgnet.train(x_train, y_train, x_test, y_test, epochs=3)
y_predict = cgnet.predict(x_test)

y_test = target_scaler.inverse_transform(y_test.reshape((-1, 1)))
y_predict = target_scaler.inverse_transform(y_predict).T.round(1)
error = estimators.rmsle(y_predict, y_test)
print("RMSLE = {}".format(error))
    target = dataset.target.reshape((-1, 1))

    data_scaler = preprocessing.MinMaxScaler((-3, 3))
    target_scaler = preprocessing.MinMaxScaler()

    data = data_scaler.fit_transform(data)
    target = target_scaler.fit_transform(target)

    return target_scaler, train_test_split(data, target, test_size=0.15)


if __name__ == '__main__':
    optimizer = algorithms.Hessian(
        network=[
            layers.Input(13),
            layers.Sigmoid(50),
            layers.Sigmoid(10),
            layers.Sigmoid(1),
        ],
        verbose=True,
    )

    target_scaler, (x_train, x_test, y_train, y_test) = load_data()
    optimizer.train(x_train, y_train, x_test, y_test, epochs=10)
    y_predict = optimizer.predict(x_test)

    y_test = target_scaler.inverse_transform(y_test.reshape((-1, 1)))
    y_predict = target_scaler.inverse_transform(y_predict).T.round(1)
    error = rmsle(y_predict, y_test)
    print("RMSLE = {}".format(error))
Beispiel #5
0
 def test_hessian_assign_step_exception(self):
     with self.assertRaises(ValueError):
         # Don't have step parameter
         algorithms.Hessian((2, 3, 1), step=0.01)
target = mnist.target.reshape((-1, 1))
target = target_scaler.fit_transform(target).todense()

data = mnist.data / 255.
data = data - data.mean(axis=0)

x_train, x_test, y_train, y_test = model_selection.train_test_split(
    data.astype(np.float32), target.astype(np.float32), train_size=(6 / 7.))

network = layers.join(layers.Input(784), layers.Relu(25), layers.Softmax(10))
'''
network.architecture()
network.train(x_train, y_train, x_test, y_test, epochs=2)
'''
gd = algorithms.Momentum(network)
gd.batchsize = 128
l = []
for i in range(10):
    gd.train(x_train, y_train, epochs=10)
    y_predicted = gd.predict(x_test).argmax(axis=1)
    y_testt = np.asarray(y_test.argmax(axis=1)).reshape(len(y_test))
    print(metrics.classification_report(y_testt, y_predicted))
    score = metrics.accuracy_score(y_testt, y_predicted)
    print("Validation accuracy: {:.2%}".format(score))
    l.append(round(score, 4))
    print(l)

hess = algorithms.Hessian(network)
hess.iter = ('momentum')
hess.train(x_train, y_train, epochs=1)