0

I originally asked this on AI StackExchange here, but since it's an algorithm question it might be more suitable here.

I have a shape on a 2D plane, and I want to draw a neural network to detect if a point (x,y) is within the shape, or outside the shape.

As a test, let's say I have a rectangle, who's four points are bound by:

(1,3), (2,3), (1,1) and (2,1).

The equations for the lines of this shape are:

x=2
x=1
y=1
y=3

My ultimate question is how do I convert this into a set of weights and thresholds in a neural network. For the algorithm, I was thinking my neural network will have 2 input neurons (one for each x co-ordinate and one for y), and then a hidden layer with two neurons, and then an output layer with one neuron descibing 'is in the rectangle, or not'. So it's a fully connected network?

I was thinking I want the values that will be within the shape to be:

1 ≤ x ≤ 2 (I want x to be between 1 and 2) AND
1 ≤ y ≤ 3 (I want y to be between 1 and 3)

But I don't understand how to actually convert this into weights and thresholds? I have come across the equation

y = -(Wx/Wx)x - (Wb/Wy) 

...but without y values in this case, I'm not sure how this applies? I would like to solve this example, but using a method that would be applicable to other shapes (e.g. a cube or a triangle).

Update 1: Similar to the way you can draw a perceptron for an AND/NOT etc gate manually, I want to translate a 2D shape to a NN manually so I can understand the process.

So at the minute I have a NN with three input nodes (X, Y and B), and four hidden nodes in one layer (one for each line of rectangle). But given a rectangle, I don't know how to solve for equation of line for say the line (3,3) (3,6), because the slope is undefined (6-3/3-3), so then I don't know how that slots into y=-Wx/Wy(x) - Wb/Wy to work out weights and bias.

Slowat_Kela
  • 1,377
  • 2
  • 22
  • 60
  • Basically, you're asking [how to train a neural network](https://www.neuraldesigner.com/blog/5_algorithms_to_train_a_neural_network). You might want to look at [this Stock Overflow question](https://stackoverflow.com/questions/8792607/getting-started-with-neural-networks-ann) and [this tutorial on artificial intelligence](http://www.ai-junkie.com/ann/evolved/nnt1.html). – Bob Jarvis - Слава Україні Dec 26 '20 at 00:32
  • Thanks, yes I want to understand an example manually. Similar to the way you can draw a perceptron for an AND/NOT etc gate manually, I want to translate a 2D shape to a NN manually so I can understand the process (and this is my problem, does the neural network have an input layer with two values, an X and Y? and then two hidden layers? I'm not sure that is right) – Slowat_Kela Dec 27 '20 at 12:10
  • I added 'Update 1' to the question, I'm not sure if that makes it clearer. – Slowat_Kela Dec 27 '20 at 12:42

1 Answers1

0

For a single layer perceptron you will need four neurons. Assuming you use the Heaviside function as your activation function you want,

y1=numpy.heaviside(x1-1,1)
y2=numpy.heaviside(2-x1,1)
y2=numpy.heaviside(x2-1,1)
y3=numpy.heaviside(3-x2,1)
y=y1+y2+y3+y4
z=numpy.heaviside(y-4,1) 

x1 and x2 are the inputs; z is the output which is 1 if a point is inside the square and zero otherwise.

Ted Black
  • 125
  • 1
  • 3