2019-05-01 03:31:50 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Created on Tue Apr 30 19:57:27 2019
|
|
|
|
|
|
|
|
@author: francois
|
|
|
|
"""
|
|
|
|
import numpy as np
|
|
|
|
import NeuralNetUtils as nnu
|
|
|
|
|
|
|
|
class NeuralNode:
|
|
|
|
def __init__(self, input_size, input_weights=None, **kwargs):
|
|
|
|
self.input_size = input_size+1
|
2019-05-03 04:11:36 +00:00
|
|
|
if (input_weights is None):
|
2019-05-01 03:31:50 +00:00
|
|
|
self.input_weights = np.random.uniform(-1,1,self.input_size)
|
|
|
|
else:
|
2019-05-03 04:11:36 +00:00
|
|
|
self.input_weights = np.repeat(input_weights,self.input_size)
|
2019-05-01 03:31:50 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.input_weights)
|
|
|
|
|
|
|
|
def input_function(self,input_values):
|
|
|
|
return np.dot(input_values,self.input_weights)
|
|
|
|
|
|
|
|
def activation(self,input_values):
|
|
|
|
input_values_with_bias = np.hstack((1,input_values))
|
|
|
|
return round(nnu.sigmoid(self.input_function(input_values_with_bias)))
|
|
|
|
|
|
|
|
def activation_derivative(self,input_values):
|
|
|
|
input_values_with_bias = np.hstack((1,input_values))
|
|
|
|
return nnu.sigmoid_derivative(self.input_function(input_values_with_bias))
|
|
|
|
|
|
|
|
def update_weights(self,input_values,alpha,delta):
|
|
|
|
input_values_with_bias = np.hstack((1,input_values))
|
|
|
|
self.input_weights = self.input_weights+(alpha*input_values_with_bias*delta)
|