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


Messages In This Thread
A Learning Neural Network (?) - by CoderMan - Oct-09-2018, 04:39 PM
Updated Simplified Code - by CoderMan - Oct-10-2018, 12:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Query about arrays in a neural network juan_o_o 0 1,848 May-21-2020, 05:21 PM
Last Post: juan_o_o
  how to create useful neural network program? hsunteik 1 3,672 Feb-04-2017, 11:32 AM
Last Post: ichabod801
  Help on Hopfield Neural Network gabrielw6 1 5,404 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