#!/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 if (input_weights is None): self.input_weights = np.random.uniform(-1,1,self.input_size) else: self.input_weights = np.repeat(input_weights,self.input_size) 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)