📄 article771.asp.htm
字号:
<BLOCKQUOTE>
<FONT COLOR=RED>
<P><I>v</I><SUB>0</SUB> = (0,0,0), <I>v</I><SUB>1</SUB>
= (0,0,1)
</FONT>
</BLOCKQUOTE>
<P>have a hamming distance of 1 while the vectors,
<BLOCKQUOTE>
<FONT COLOR=RED>
<P><I>v</I><SUB>2</SUB> = (0,1,0), <I>v</I><SUB>4</SUB>
= (1,0,0)
</FONT>
</BLOCKQUOTE>
<P>have a hamming distance of 2.
<P>We can use hamming distance as the measure of orthogonality in binary bit vector systems. And this can help us determine if our input vectors are going to have a lot of overlap. Determining orthogonality with general vector inputs is harder, but the concept is the same. That's all the time we have for concepts and terminology, so let's jump right in and see some actual neural nets that do something and hopefully by the end of the article you will be able to use them in your game's AI. We are going to cover neural nets used to perform logic functions, classify inputs, and associate inputs with outputs.
<BLOCKQUOTE>
<SPAN CLASS="maintext-2"><FONT COLOR="#000088"><I>Figure 5.0 - The McCulloch-Pitts Neurode.</I></FONT></SPAN>
<P ALIGN=CENTER><IMG SRC="xneuralnet/Image18.jpg" tppabs="http://www.gamedev.net/reference/articles/xneuralnet/Image18.jpg" width="427" height="217">
</BLOCKQUOTE>
<H1>Pure Logic Mr. Spock</H1>
<P>The first artificial neural networks were created in 1943 by <I>McCulloch</I> and <I>Pitts</I>. The neural networks were composed of a number of neurodes and were typically used to compute simple logic functions such as <I>AND</I>, <I>OR</I>, <I>XOR,</I> and combinations of them. Figure 5.0 is a representation of a basic McCulloch-Pitts neurode with 2 inputs. If you are an electrical engineer then you will immediately see a close resemblance between McCulloch-Pitts neurodes and transistors or <I>MOSFETs</I>. In any case, McCulloch-Pitts neurodes do <I>not</I> have biases and have the simple activation function <I>f</I><SUB>mp</SUB><I>(x)</I> equal to:
<BLOCKQUOTE>
<SPAN CLASS="maintext-2"><FONT COLOR="#000088"><I>Eq. 5.0</I></FONT></SPAN>
<FONT COLOR=RED>
<P><I>f</I><SUB>mp</SUB><I>(x) = </I>1, if <I>x</I><font face="Symbol">'</font><font face="Symbol">q</font><br>
0,
if <I>x</I> < <font face="Symbol">q</font>
</FONT>
</BLOCKQUOTE>
<P>The <I>MP</I> (McCulloch-Pitts) neurode functions by summing the product of the inputs <I>X</I><SUB>i</SUB> and weights <I>w</I><SUB>i</SUB> and applying the result <I>Y</I><SUB>a</SUB> to the activation function <I>f</I><SUB>mp</SUB><I>(x).</I> The early research of McCulloch-Pitts focused on creating complex logical circuitry with the neurode models. In addition, one of the rules of the neurode model is that is takes one time step for a signal to travel from neurode to neurode. This helps model the biological nature of neurons more closely. Let's take a look at some examples of MP neural nets that implement basic logic functions. The logical <I>AND</I> function has the following truth table:
<BLOCKQUOTE>
<SPAN CLASS="maintext-2"><FONT COLOR="#000088"><I>Table 1.0 - Truth Table for Logical AND.</I></FONT></SPAN>
<P><table border="1" cellpadding="2">
<tr>
<td><I>X1</I></td>
<td><I>X2</I></td>
<td><I>Output</I></td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</table>
<P><SPAN CLASS="maintext-2"><FONT COLOR="#000088"><I>Figure 6.0 - Basic Logic Functions Implemented with McCulloch-Pitts Nets.</I></FONT></SPAN>
<P ALIGN=CENTER><IMG SRC="xneuralnet/Image19.jpg" tppabs="http://www.gamedev.net/reference/articles/xneuralnet/Image19.jpg" width="609" height="493">
</BLOCKQUOTE>
<P>We can model this with a two input MP neural net with weights <I>w</I><SUB>1</SUB>=1, <I>w</I><SUB>2</SUB>=1, and <font face="Symbol">q</font> = 2. This neural net is shown in Figure 6.0a. As you can see, all input combinations work correctly. For example, if we try inputs <I>X</I><SUB>1</SUB>=0, <I>Y</I><SUB>1</SUB>=1, then the activation will be:
<BLOCKQUOTE>
<FONT COLOR=RED>
<I>X</I><SUB>1</SUB>*<I>w</I><SUB>1</SUB> + <I>X</I><SUB>2</SUB>*<I>w</I><SUB>2</SUB>
= (1)*(1) + (0)*(1) = 1.0
</FONT>
</BLOCKQUOTE>
<P>If we apply 1.0 to the activation function <I>f</I><SUB>mp</SUB><I>(x)</I> then the result is 0 which is correct. As another example, if we try inputs <I>X</I><SUB>1</SUB>=1, <I>X</I><SUB>2</SUB>=1, then the activation will be:
<BLOCKQUOTE>
<FONT COLOR=RED>
<I>X</I><SUB>1</SUB>*<I>w</I><SUB>1</SUB> + <I>X</I><SUB>2</SUB>*<I>w</I><SUB>2</SUB>
= (1)*(1) + (1)*(1) = 2.0
</FONT>
</BLOCKQUOTE>
<P>If we input 2.0 to the activation function <I>f</I><SUB>mp</SUB><I>(x)</I>, then the result is 1.0 which is correct. The other cases will work also. The function of the <I>OR</I> is similar, but the threshold <font face="Symbol">q</font> of is changed to 1.0 instead 2.0 as it is in the <I>AND</I>. You can try running through the truth table yourself to see the results.
<P>The <I>XOR</I> network is a little different because it really has 2 layers in a sense because the results of the pre-processing are further processed in the output neuron. This is a good example of why a neural net needs more than one layer to solve certain problems. The <I>XOR</I> is a common problem in neural nets that is used to test a neural net's performance. In any case, <I>XOR</I> is not linearly separable in a single layer, it must be broken down into smaller problems and then the results added together. Let's take a look at <I>XOR</I> as the final example of MP neural networks. The truth table for <I>XOR</I> is as follows:
<BLOCKQUOTE>
<SPAN CLASS="maintext-2"><FONT COLOR="#000088"><I>Table 2.0 - Truth Table for Logical XOR.</I></FONT></SPAN>
<P><table border="1" cellpadding="2">
<tr>
<td><I>X1 </I></td>
<td><I>X2</I></td>
<td><I>Output</I></td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
</table>
<P><SPAN CLASS="maintext-2"><FONT COLOR="#000088"><I>Figure 7.0 - Using the XOR Function to Illustrate Linear Separability.</I></FONT></SPAN>
<P ALIGN=CENTER><IMG SRC="xneuralnet/Image20.jpg" tppabs="http://www.gamedev.net/reference/articles/xneuralnet/Image20.jpg" width="619" height="470">
</BLOCKQUOTE>
<P><I>XOR</I> is only true when the inputs are different, this is a problem since both inputs map to the same output. <I>XOR</I> is not linearly separable, this is shown in Figure 7.0. As you can see, there is no way to separate the proper responses with a straight line. The point is that we can separate the proper responses with 2 lines and this is just what 2 layers do. The first layer pre-processes or solves part of the problem and the remaining layer finishes up. Referring to Figure 6.0c, we see that the weights are <I>w</I><SUB>1</SUB>=1, <I>w</I><SUB>2</SUB>=-1, <I>w</I><SUB>3</SUB>=1, <I>w</I><SUB>4</SUB>=-1, <I>w</I><SUB>5</SUB>=1, <I>w</I><SUB>6</SUB>=1. The network works as follows: layer one computes if <I>X</I><SUB>1</SUB> and <I>X</I><SUB>2</SUB> are opposites in parallel, the results of either case (0,1) or (1,0) are feed to layer two which sums these up and fires if either is true. In essence we have created the logic function:
<BLOCKQUOTE>
<FONT COLOR=RED>
<I>z = ((X1 AND NOT X2) OR (NOT X1 AND X2))</I>
</FONT>
</BLOCKQUOTE>
<P>If you would like to experiment with the basic
McCulloch Pitts neurode Listing 1.0 is a complete 2 input, single
neurode simulator that you can experiment with.
<BLOCKQUOTE>
<SPAN CLASS="maintext-2"><FONT COLOR="#000088"><I>Listing 1.0 - A McCulloch-Pitts Logic Neurode Simulator</I></font></SPAN>
<PRE><DIV CLASS="code">
// MCULLOCCH PITTS SIMULATOR
/////////////////////////////////////////////////////
// INCLUDES
/////////////////////////////////////////////////////
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <fcntl.h>
// MAIN
/////////////////////////////////////////////////////
void main(void)
{
float threshold, // this is the theta term used to threshold the summation
w1,w2, // these hold the weights
x1,x2, // inputs to the neurode
y_in, // summed input activation
y_out; // final output of neurode
printf("\nMcCulloch-Pitts Single Neurode Simulator.\n");
printf("\nPlease Enter Threshold?");
scanf("%f",&threshold);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -