Tuesday, July 13, 2021

Perceptron Implementation for OR gate

Perceptron implementation in Python 

(Logical OR gate Example)

The perceptron learning algorithm works as follows:
  1. Intilalize the weights for all inputs (including bias )
  2. Present the input xi to neural network
  3. Calculate the outpput for the given input. say it is zi
  4. update the weights as: w=w+a(actual-predicted output)xi
  5. Repeat from step 2 until the convergance or number of iteration reached.

Lets implement perceptron for the inputs:

     inputs              outputs
     x1  x2  b
     o   0  1            0
     0   1  1            1
     1   0  1            1
     1   1  1            1
 
import numpy as np
import random as rd
unit_step = lambda x: 0 if x < 0 else 1
train_data = [
    (np.array([0,0,1]), 0),
    (np.array([0,1,1]), 1),
    (np.array([1,0,1]), 1),
    (np.array([1,1,1]), 1),
]
w = np.random.rand(3)
out:w
//array([0.83364474, 0.84316914, 0.79095823])
errors = []
eta = 0.2
n = 100
for i in range(n):
    x, expected = rd.choice(train_data)
    result = np.dot(w, x)
    error = expected - unit_step(result)
    errors.append(error)
    w += eta * error * x

for x, _ in train_data:
    result=np.dot(x,w)
    z=unit_step(result)
    print("{}->{}".format(x[:2], z))
 
Output: 
[0 0]->0
[0 1]->1
[1 0]->1
[1 1]->1
 
import matplotlib.pyplot as plt
plt.plot(errors)
[<matplotlib.lines.Line2D at 0x2e761f72f60>]
Here the plot of error show that after the 20th iteration, it becomes zero and remains stable until 100th iterations

Sunday, May 19, 2019

LAB EXPERIMENT 1
AI AGENT [DOWNLOAD]

Monday, December 31, 2018

CSIT Internship Report Writting Guidlines

This blog post contains the link to my power-point presentation on How to prepare a Internship Report for BScCSIT final semester of Tribhuvan University. You can download the slide here.

Monday, August 27, 2018

How to Create a Test Plan and Test Cases: A Simplified View

Acknowledgement: Most of the content of this post are based on the Book " Advanced Software Project Management" by Andrew Stellman and Jennifer Greene. However Errors if any are due to me and I apolozie for them.


The goal of test planning is to establish the list of tasks which, if performed, will identify all of the requirements that have not been met in the software.
The main work product is the test plan.
     The test plan documents the overall approach to the test. In many ways, the test plan serves as a summary of the test activities that will be performed.
     It shows how the tests will be organized, and outlines all of the testers’ needs which must be met in order to properly carry out the test.
     The test plan should be inspected by members of the engineering team and senior managers.
     The bulk of the test planning effort is focused on creating the test cases.

Fig: Sample format of Test Plan


      A test case is a description of a specific interaction that a tester will have in order to test a single behavior of the software.
      Test cases are very similar to use cases, in that they are step-by-step narratives which define a specific interaction between the user and the software.
     A typical test case is laid out in a table, and includes:
      A unique name and number
      A requirement which this test case is exercising
      Preconditions which describe the state of the software before the test case (which is often a previous test case that must always be run before the current test case)
      Steps that describe the specific steps which make up the interaction
      Expected Results which describe the expected state of the software after the test case is executed
      Test cases must be repeatable.
     Good test cases are data-specific, and describe each interaction necessary to repeat the test exactly.
        The requirement specified on chapter 6-  how a search-and-replace function must deal with case sensitivity. One part of that requirement said, “If the original text was all lowercase, then the replacement  text must be inserted in all lowercase.”



Fig: Test Case Sample