Python Forum
A Learning Neural Network (?)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Learning Neural Network (?)
#1
I've recently got interested in Neural Networks, and I wanted to try and create one using Python. I am not very advanced with Python, I just know the basic stuff. I also don't think I have totally understood all about Neural Networks.

What i created is what I understood about the topic from online sources, especially this one: https://becominghuman.ai/making-a-simple...a1de81ec20

I've read about the NN learning with trials in the above article, and wanted to try and recreate it.

The structure I chose is super simple: 2 "input neurons" (one of them has the value of 1 and the other has the value of 0), 2 neurons in one hidden layer, and one output.

Simple representation:

input neuron1 --- layer neuron1 - - output1

input neuron2 --- layer neuron2 - - output1

My only question is: is this considered a learning Neural Network or is it just a 'simulation' of it?

In the code the values of the input neurons is chosen pseudorandomly.
The way it learns is that each time that it sees which input neuron is active, the weight that neuron has is increased by 0.2, and the next neuron has a threshold of 1 (so when the weight reaches 1, the next neuron activates and then generates the output).
It's simpler to understand if you read a part of the article I linked.

Here is the code:

import random
randX = random.randint(0,1)
if randX == 0:
    randY = 1
elif randX == 1:
    randY = 0

class inpNeur:
    def __init__(self,value):
        self.val = value
        self.w = self.val*0

class layNeur:
    def __init__(self,w):
        global thresh
        thresh = 1
        self.val = w
        self.w = self.val

class output:
    def __init__(self,w):
        self.val = w


in1 = inpNeur(randX)
in2 = inpNeur(randY)

n1 = layNeur(in1.w)
n2 = layNeur(in2.w)

out = output(n1.val+n2.val)


inpL = [in1,in2]

def trial():
    for x in inpL:
        x.w += .2*x.val
        global n1
        global n2
        n1 = layNeur(in1.w)
        n2 = layNeur(in2.w)
    if n1.val+n2.val < thresh:
        pass
    else:
        global out
        out = output(n1.val+n2.val)
    if out.val > 0:
        print(f'OUTPUT = {out.val}')
Does anybody know if I actually created a simple learning Neural Network?

Thank you!
Reply
#2
Here is a simplified version of the code:

import random

num1 = random.randint(0,1)

if num1 == 0:
    num2 = 1
elif num1 == 1:
    num2 = 0


class neuron:
    def __init__(self,value,inW):
        self.v = value
        self.inW = inW

inp1 = num1
inp2 = num2

in1 = neuron(int(inp1),int(inp1))
in2 = neuron(int(inp2),int(inp1))

n1A = neuron(in1.v*0,in1.v)
n1B = neuron(in2.v*0,in2.v)



l1 = [n1A,n1B]

def r():
    for x in l1:
        x.v += .25*x.inW
        nOUT = neuron(n1A.v+n1B.v,n1A.v+n1B.v)

    if nOUT.v >= 1:
        print(nOUT.v)
I know it might take time to understand what I mean. Thanks for helping!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Query about arrays in a neural network juan_o_o 0 1,299 May-21-2020, 05:21 PM
Last Post: juan_o_o
  how to create useful neural network program? hsunteik 1 3,056 Feb-04-2017, 11:32 AM
Last Post: ichabod801
  Help on Hopfield Neural Network gabrielw6 1 4,505 Jan-08-2017, 10:54 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020