26

I have a question that may be trivial but it's not described anywhere i've looked. I'm studying neural networks and everywhere i look there's some theory and some trivial example with some 0s and 1s as an input. I'm wondering: do i have to put only one value as an input value for one neuron, or can it be a vector of, let's say, 3 values (RGB colour for example)?

bias
  • 1,467
  • 3
  • 19
  • 39
agnieszka
  • 14,897
  • 30
  • 95
  • 113

6 Answers6

12

The above answers are technically correct, but don't explain the simple truth: there is never a situation where you'd need to give a vector of numbers to a single neuron.

From a practical standpoint this is because (as one of the earlier solutions has shown) you can just have a neuron for each number in a vector and then have all of those be the input to a single neuron. This should get you your desired behavior after training, as the second layer neuron can effectively make use of the entire vector.

From a mathematical standpoint, there is a fundamental theorem of coding theory that states that any vector of numbers can be represented as a single number. Thus, if you really don't want an extra layer of neurons, you could simply encode the RGB values into a single number and input that to the neuron. Though, this coding function would probably make most learning problems more difficult, so I doubt this solution would be worth it in most cases.

To summarize: artificial neural networks are used without giving a vector to an input unit, but lose no computational power because of this.

zergylord
  • 4,368
  • 5
  • 38
  • 60
8

When dealing with multi-dimensional data, I believe a two layer neural network is said to give better result.

In your case:

R[0..1] => (N1)----\
                    \
G[0..1] => (N2)-----(N4) => Result[0..1]
                    /
B[0..1] => (N3)----/

As you can see, the N4 neurone can handle 3 entries.

The [0..1] interval is a convention but a good one imo. That way, you can easily code a set of generic neuron classes that can take an arbitrary number of entries (I had template C++ classes with the number of entries as template parameter personally). So you code the logic of your neurons once, then you toy with the structure of the network and/or combinations of functions within your neurons.

Julian Aubourg
  • 11,346
  • 1
  • 29
  • 29
  • the problem is i have set of pixels of an image, i have some (3?) subsequent images of a one view that give me some (3?) different colours of a one pixel. each colour consists of 3 values. the question is - to be continued – agnieszka Mar 16 '09 at 23:57
  • 1
    the question is should i desing one input neuron for each r and g and b for every pixel for every image or can i put a colour (r,g,b value) as an input for one neuron, or maybe 3 subsequent colours? – agnieszka Mar 16 '09 at 23:58
  • The thing is you have a lot of options here. What is the problem exactly? If it's local to each pixel (ie, the solution only depends on the three consecutive colors of the same pixel) then you only need one neural network into which you'll enter you data (...) – Julian Aubourg Mar 17 '09 at 00:21
  • (...) pixel by pixel. Now, how a neural network should be configured? There's no real answer to that. Should you have 3 subnetworks like the one I have into my post than cumulate their result into another neuron? Should you have 9 entry neurons and one cumulator in the end? (...) – Julian Aubourg Mar 17 '09 at 00:22
  • no, it's about recognizing a movement so it depends on a change of colours of a one pixel and of it's realtion to his neighbours i guess – agnieszka Mar 17 '09 at 00:23
  • (...) or do you only need one neuron that will take the 9 values all at once? (which btw, wouldn't really be a "network" so to speak). It all depends on your problem and there is no all-mighty solution because every problem is different. (...) – Julian Aubourg Mar 17 '09 at 00:24
  • i just try to find out if there even is a way to put a vector such as colour as an input value for a ONE input neuron, or do i have to put one value for one neuron because i still don't get it – agnieszka Mar 17 '09 at 00:25
  • (...) what you really need is to break you problem into subproblems. It seems to me you have to determine "something" using 3 consecutive colors of the same pixel: this is network Net1. And then, maybe, you need to take into account neighbours (...) – Julian Aubourg Mar 17 '09 at 00:25
  • (...) with another network that will take the result of Net1 as its input (Net2). – Julian Aubourg Mar 17 '09 at 00:26
  • And again, a neuron can take as many entries as you want it to, like Brann said. It's all a question of what function you have into it. If it can take multiple values as input, then you have a multiple entry neuron. – Julian Aubourg Mar 17 '09 at 00:27
  • so if my neuron in the first layer takes a colour, can it produce a colour as an output for a neuron in a second layer? – agnieszka Mar 17 '09 at 00:29
  • I woudn't recommand 3 dimensional output for a neuron. I'd rather have you input neurons (Layer1) having a single output that is given to each 3 neurons of Layer2. Then you can use the 3 outputs of Layer2 as your resulting color. – Julian Aubourg Mar 17 '09 at 00:34
4

Generally, the input for a single neuron is a value between 0 and 1. That convention is not just for ease of implementation but because normalizing the input values to the same range ensures that each input carries similar weighting. (If you have some images with 8 bit color with pixel values between 0 and 7 and some images with 16 bit color with pixel values between 0 and 255 you probably wouldn't want to favor the 24 bit color images just because the numerical values are higher. Similarly, you will probably want your images to be the same dimensions.)

As far as using pixel values as inputs, it is very common to try to gather a higher level representation of the image than its pixels (more info). For example, given a 5 x 5 (normalized) gray scale image:

[1 1 1 1 1]
[0 0 1 0 0] 
[0 0 1 0 0] 
[0 0 1 0 0] 
[0 0 1 0 0]

We could use a the following feature matrices to help discover horizontal, vertical, and diagonal features of the images. See python haar face detection for more information.

[1 1]  [0 0]  [1 0]  [0 1]  [1 0], [0 1]
[0 0], [1 1], [1 0], [0 1], [0 1], [1 0]

To build the input vector, v, for this image, take the first 2x2 feature matrix and "apply" it with element-wise multiplication to the first position in the image. Applying,

[1 1] (the first feature matrix) to [1 1] (the first position in the image)
[0 0]                               [0 0] 

will result in 2 because 1*1 + 1*1 + 0*0 + 0*0 = 2. Append 2 to the back of your input vector for this image. Then move this feature matrix to the next position, one to the right, and apply it again, adding the result to the input vector. Do this repeatedly for each position of the feature matrix and for each of the feature matrices. This will build your input vector for a single image. Be sure that you build the vectors in the same order for each image.

In this case the image is black and white, but with RGB values you could extend the algorithm to do the same computation but add 3 values to the input vector for each pixel--one for each color. This should provide you with one input vector per image and a single input to each neuron. The vectors will then need to be normalized before running through the network.

tpbarron
  • 49
  • 1
  • 5
2

Use light wavelength normalized to visible spectrum as the input.

There are some approximate equations on the net. Search for RGB to wavelength conversion or use HSL color model and extract Hue component and possibly use Saturation and Lightness as well. Well...

loa_in_
  • 1,030
  • 9
  • 20
2

Normally a single neuron takes as its input multiple real numbers and outputs a real number, which typically is calculated as applying the sigmoid function to the sum of the real numbers (scaled, and then plus or minus a constant offset).

If you want to put in, say, two RGB vectors (2 x 3 reals), you need to decide how you want to combine the values. If you add all the elements together and apply the sigmoid function, it is equivalent to getting in six reals "flat". On the other hand, if you process the R elements, then the G elements, and the B elements, all individually (e.g. sum or subtract the pairs), you have in practice three independent neurons.

So in short, no, a single neuron does not take in vector values.

Antti Huima
  • 25,136
  • 3
  • 52
  • 71
  • so in a situation you described you have 3 input neurons, each one getting a value that consists of three values, for example three Rs? – agnieszka Mar 17 '09 at 00:18
  • Ah, there where actually only two R's in the example above, but yes, one way would be to dedicate one neuron per one element. – Antti Huima Mar 17 '09 at 00:22
1

It can be whatever you want, as long as you write your inner function accordingly.

The examples you mention use [0;1] as their domain, but you can use R, R², or whatever you want, as long as the function you use in your neurons is defined on this domain.

In your case, you can define your functions on R3 to allow for RGB values to be handled

A trivial example : use (x1, y1, z1),(x2,y2,z2)->(ax1+x2,by1+y2,cz1+z2) as your function to transform two colors into one, a b and c being your learning coefs, which you will determine during the learning phase.

Very detailed information (including the answer to your question) is available on Wikipedia.

Svante
  • 50,694
  • 11
  • 78
  • 122
Brann
  • 31,689
  • 32
  • 113
  • 162
  • but if one dataset stays in a relation with another dataset they should be provided to different neurons, shouldn't they? or may it be a one vector's input? – agnieszka Mar 16 '09 at 23:36
  • yes, it can be a one vector input ; R3 means a 3-members vector (well, trivially speaking) – Brann Mar 16 '09 at 23:37
  • well yeah i get that :D i mean if you have 3 colours of a one pixel in 3 subsequent images and you know that differences between these colours influence the result should you have 3 neurons for these 3 colors or one neuron for an input containing these 3 colours? or do i choose? – agnieszka Mar 16 '09 at 23:41
  • I guess I would use an array of neurons (1 per pixel), with each neurons getting three RGB vectors (one per same coordinate pixel of each image) as input values. – Brann Mar 16 '09 at 23:44
  • thanks that was helpful! the last question - does it mean that i HAVE to have a function that changes my R^n value to a R value for an input neuron? – agnieszka Mar 16 '09 at 23:46