神经网络 - 输入值

发布于 2024-07-15 02:38:22 字数 140 浏览 5 评论 0原文

我有一个可能很微不足道的问题,但在我看过的任何地方都没有描述。 我正在研究神经网络,到处都有一些理论和一些简单的例子,其中一些 0 和 1 作为输入。 我想知道:我是否必须只输入一个值作为一个神经元的输入值,或者它可以是 3 个值(例如 RGB 颜色)的向量吗?

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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

樱桃奶球 2024-07-22 02:38:22

上面的答案在技术上是正确的,但没有解释一个简单的事实:永远没有需要向单个神经元提供数字向量的情况。

从实际的角度来看,这是因为(正如早期解决方案之一所示)您可以为向量中的每个数字设置一个神经元,然后将所有这些作为单个神经元的输入。 这应该会让您在训练后获得所需的行为,因为第二层神经元可以有效地利用整个向量。

从数学的角度来看,编码理论有一个基本定理,即任何数字向量都可以表示为单个数字。 因此,如果您确实不需要额外的神经元层,您可以简单地将 RGB 值编码为单个数字并将其输入到神经元。 不过,这种编码功能可能会使大多数学习问题变得更加困难,所以我怀疑这种解决方案在大多数情况下是否值得。

总结一下:使用人工神经网络时无需向输入单元提供向量,但不会因此而损失计算能力。

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.

淑女气质 2024-07-22 02:38:22

在处理多维数据时,我相信两层神经网络据说可以给出更好的结果。

在您的情况下:

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

如您所见,N4 神经元可以处理 3 个条目。

[0..1] 间隔是一种约定,但在我看来是一个很好的约定。 这样,您就可以轻松地编写一组通用神经元类,这些神经元类可以采用任意数量的条目(我个人有模板 C++ 类,其中条目数作为模板参数)。 因此,您对神经元的逻辑进行一次编码,然后就可以尝试神经元内的网络结构和/或功能组合。

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.

温柔少女心 2024-07-22 02:38:22

一般来说,单个神经元的输入是 0 到 1 之间的值。这种约定不仅是为了便于实现,而且因为将输入值标准化到相同的范围可以确保每个输入具有相似的权重。 (如果您有一些 8 位颜色的图像,像素值在 0 到 7 之间,而一些图像有 16 位颜色,像素值在 0 到 255 之间,您可能不希望仅仅因为数值是 24 位颜色图像同样,您可能希望图像具有相同的尺寸。)

就使用像素值作为输入而言,尝试收集比其像素更高级别的图像表示是很常见的(更多信息)。 例如,给定 5 x 5(标准化)灰度图像:

[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]

我们可以使用以下特征矩阵来帮助发现图像的水平、垂直和对角线特征。 有关更多信息,请参阅 python haar 人脸检测

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

要为此图像构建输入向量 v,请采用第一个 2x2 特征矩阵,并通过逐元素乘法将其“应用”到图像中的第一个位置。 应用

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

后将得到 2,因为 1*1 + 1*1 + 0*0 + 0*0 = 2。将 2 附加到该图像的输入向量的后面。 然后将此特征矩阵移动到下一个位置,向右一个位置,并再次应用它,将结果添加到输入向量中。 对特征矩阵的每个位置和每个特征矩阵重复执行此操作。 这将为单个图像构建输入向量。 确保以相同的顺序为每个图像构建向量。

在这种情况下,图像是黑白的,但对于 RGB 值,您可以扩展算法来执行相同的计算,但为每个像素向输入向量添加 3 个值——每种颜色一个。 这应该为每个图像提供一个输入向量,并为每个神经元提供一个输入。 然后,在通过网络运行之前,需要对向量进行归一化。

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.

忆梦 2024-07-22 02:38:22

通常,单个神经元将多个实数作为输入并输出一个实数,该实数通常通过将 sigmoid 函数应用于实数之和(缩放,然后加上或减去常数偏移量)来计算。

例如,如果您想输入两个 RGB 向量(2 x 3 实数),您需要决定如何组合这些值。 如果将所有元素加在一起并应用 sigmoid 函数,则相当于获得六个“平坦”实数。 另一方面,如果您处理 R 元素,然后处理 G 元素和 B 元素,全部单独处理(例如对对进行求和或相减),那么实际上您将拥有三个独立的神经元。

简而言之,不,单个神经元不接受向量值。

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.

国粹 2024-07-22 02:38:22

它可以是任何你想要的,只要你相应地编写你的内部函数。

您提到的示例使用 [0;1] 作为其域,但您可以使用 R、R² 或任何您想要的内容,只要您在神经元中使用的函数是在该域上定义的即可。

在您的情况下,您可以在 R3 上定义函数以允许处理 RGB 值

一个简单的示例:使用 (x1, y1, z1),(x2,y2,z2)->(ax1+x2,by1+y2 ,cz1+z2) 作为将两种颜色转换为一种颜色的函数,ab 和 c 是您的学习系数,您将在学习阶段确定。

维基百科上提供了非常详细的信息(包括问题的答案)。

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.

月野兔 2024-07-22 02:38:22

使用归一化为可见光谱的光波长作为输入。

网上有一些近似方程。
搜索 RGB 到波长的转换
或者
使用 HSL 颜色模型并提取色相分量,还可能使用饱和度和亮度。 出色地...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文