A Single Layer Perceptron for Regression: Part 2

 

Functions Edited:

  • initialize_weights: Earlier, this function returned an numpy array of shape (1,n). It has now been edited to return the transpose, i.e., an numpy array of shape (n,1). This change was made to make matrix multiplication in the function forward_pass easy.

  • forward_pass: The main change is that now this function uses matrix multiplication to multiply all inputs with the weights. This will enable batch processing. 

  • activate: This function now activates the input sums for every row of predictor values.


    New Functions created:

    • backward_pass: Finding the change in weights required with respect to the Error. Based on the derivation, for a neuron that is on the output layer, delta w = learning_rate * eeta * input_attribute_ij wherein eeta = predicted_output_i*( 1 - predicted_output_i)(actual_output_i - predicted_output_i). 
      Parameters:  (1) input (numpy array (m,n))
                           (2) predicted_output(numpy array (m,1)) 
                           (3) actual_output(numpy array (m,1))
                           (4) learning_rate(float): the rate at which the user wants the learning to happen so                                                                  as to make the perceptron learn fast enough while not                                                                        overshooting the minima.
                           (5)error_type(string) : Type of error used so as to determine how to calculate delta                                                              w.

    • change_weights: This function is use to change the values of the current weights based on the result of the backward pass.
      Parameters:(1) delw((numpy array (n,1)): changes required in each of the weights.
                         (2) weights(numpy array of shape (n,1)): Current weights
    • epochs: This function creates epochs/iterations of forward and backward passes until the difference between the errors of 2 consecutive epochs is within a certain threshold.
      Parameters: (1)input(numpy array (m,n))
                          (2) actual_output(numpy array ()
                          (3) threshold(float)

    Functions in development:

    -  normalize
    - denormalize
    - predict


    Code

    Comments

    Popular posts from this blog

    A single layer Perceptron for Regression: Part 1

    What Data Structure Do I use?