<?xml version="1.0" encoding="UTF-8" ?>
  <resource>
  <id>6440</id>
  <path>/www/nrich/html/content/id/6440/</path>
  <resourceTypeID>3</resourceTypeID>
  <last_published>0000-00-00T00:00:00</last_published>
  <indexXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;&lt;br&gt;&lt;/br&gt;
&lt;p&gt;&lt;strong&gt;This problem will introduce you to the ideas behind neural networks. The tasks become more difficult as the problem progresses!&lt;/strong&gt;&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
In standard mathematical logic, a logic gate activates, or &amp;#39;fires&amp;#39; depending on whether certain inputs are either ON of OFF. Here&amp;#39;s an example of an AND gate: (made using our &lt;a href=&quot;http://nrich.maths.org/5974&quot;&gt;Circuit Maker&lt;/a&gt; program)&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;&quot; src=&quot;andgate.png&quot; style=&quot;width: 448px; height: 208px;&quot;&gt;&lt;/mdo:image&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;In the human brain, there are around $10^{11}$ neurons. Each of these is connected to many other neurons by synapses, the junctions between cells, which allow signals to be transmitted from cell to cell electrically or chemically. Each neuron has a &lt;em&gt;resting&lt;/em&gt; potential (the value at which it remains unless stimulated) and a &lt;em&gt;threshold&lt;/em&gt; potential (the
value at which it will transmit a signal). Each input can carry potential differences; if the sum of the inputs raises the potential of the neuron to the threshold potential, the neuron fires.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Imagine neurons with three inputs x, y, z. By treating x, y and z as coordinates in three dimensions, &lt;strong&gt;describe geometrically the regions for which the neurons fire in the follow pair of examples&lt;/strong&gt;:&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;&quot; src=&quot;neuron.png&quot; style=&quot;width: 405px; height: 208px;&quot;&gt;&lt;/mdo:image&gt;&lt;mdo:image alt=&quot;&quot; src=&quot;neuron2.png&quot; style=&quot;width: 405px; height: 208px;&quot;&gt;&lt;/mdo:image&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;We can model the electrical circuits mathematically using?an &lt;em&gt;artificial neural network&lt;/em&gt;. These contain input and output neurons, and also may contain hidden neurons. Each neuron has a threshold value $T$, and also a weight factor $W$, by which its output is amplified or deamplified. Here&amp;#39;s an example of an OR gate. (The initial inputs are $0$ or $1$)&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;&quot; src=&quot;gate1.png&quot; style=&quot;width: 350px; height: 219px;&quot;&gt;&lt;/mdo:image&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;&lt;strong&gt;Verify that the output behaves as claimed&lt;/strong&gt;. (i.e. C=1 if at least one of A or B is equal to 1)&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;&lt;strong&gt;Here&amp;#39;s another network. Which logical operation does this represent?&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;&quot; src=&quot;gate2.png&quot; style=&quot;width: 180px; height: 324px;&quot;&gt;&lt;/mdo:image&gt;&lt;br&gt;&lt;/br&gt;
?&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;&lt;strong&gt;Can you create similar networks which replicate the behaviour of other logical operations?&lt;/strong&gt;&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
So far, these are all examples of feed-forward circuits, i.e. the flow is all in one direction. We can also have feedback circuits, where the output of a neuron can feed back into the network at an earlier point. These can model the biological phenemenon of positive feedback, and the circuit can get extremely complicated very quickly. In more complicated applications we can consider the neuron as
a function producing a numerical output from a vector of inputs.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Consider the following network in which the output feeds back into the input. Suppose that the output of the neuron is a function of the two input currents R and B. Suppose the the neuron system is initially charge free and then at some time a constant current of 1 is fired in A and an instantaneous pulse $P$ of current 1 is generated.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;mdo:image src=&quot;feedback1.png&quot;&gt;&lt;/mdo:image&gt;&lt;br&gt;&lt;/br&gt;
Consider the behaviour of the system in the case that $g(R,B)=\frac{1}{R+B}$ for different values of the initial pulse $P$.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Next consider the following similar system, which starts in a configuration with $A=C=1$ and $B=D=0$ and that $g(C, D)=C+D$ and $h(A,B) = 2^{-(A+B)}$ At the two junctions where the path splits into two, assume that half of the current flows down each. Where the two branches merge, the output is the sum of the two currents in the branches.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;mdo:image src=&quot;feedback2.png&quot;&gt;&lt;/mdo:image&gt;&lt;br&gt;&lt;/br&gt;
What is the output (to 6 decimal places)?&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Suppose that the current in $C$ can be varied from $0$ to a large number. What range of outputs can be produced?&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Suppose that $C$ and $A$ are initial pulses of current. Explore and explain your findings.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Explore for various functions $g$ and $h$.&lt;br&gt;&lt;/br&gt;
 &lt;/p&gt;
&lt;div class=&quot;framework&quot; style=&quot;text-align: left;&quot;&gt;Notes and Background&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
A perceptron is a model of a neural network developed by Frank Rosenblatt in 1957. The output of each neuron is determined by a formula that determines the output $f(x)$ given an input vector $x$:&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
$$f(x) = \left\{\begin{array}{c l}1 &amp;amp; w\cdot x + b &amp;amp;gt; 0\\0 &amp;amp; \mathrm{otherwise} \end{array}\right.$$&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
where $w$ represents the weight of each of the inputs and $-b$ the threshold value. It&amp;#39;s possible to teach a perceptron to give the correct outputs for various inputs, given a few initial results. There&amp;#39;s an &lt;a href=&quot;http://en.wikipedia.org/wiki/Perceptron&quot;&gt;article here&lt;/a&gt; giving more details.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
The function $f$ is called the activation function, and defines the output of a neuron given the inputs. The most simple example is a translation of the Heaviside step function:&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
$$f(v) = \left\{\begin{array}{c l}1 &amp;amp; v &amp;amp;gt; b\\0 &amp;amp; v &amp;amp;lt; b \end{array}\right.$$&lt;br&gt;&lt;/br&gt;
where $v$ is the sum of the inputs and $b$ is the threshold value. It turns out if we use this to model the neural network, we need to use a great number of neurons.&lt;br&gt;&lt;/br&gt;
A solution to this problem is to use a sigmoid function, which can realisitically model this behaviour.&lt;/div&gt;
&lt;p style=&quot;text-align: left;&quot;&gt; &lt;/p&gt;
&lt;br&gt;&lt;/br&gt;&lt;/mdoxml&gt;</indexXML>
  <solutionXML/>
  <noteXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;Perceptrons and feedback circuits&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
In standard mathematical logic, a logic gate activates, or &amp;#39;fires&amp;#39; depending on whether certain inputs are either ON of OFF&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Example of a logical AND gate.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
In an artificial neural network, this concept is extended: inputs can carry differing levels of current so that a gate (neurone) fires provided that the overall input level exceeds a certain threshold.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
For what ranges of input levels will these neurones fire?&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
SOME EXAMPLES&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
SOME PROBLEM WITH XOR&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
A feedback circuit&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
ACTIVATION FUNCTION -- SIGMOIDS&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;&lt;/mdoxml&gt;</noteXML>
  <clueXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;Treat the systems as evolving according to discrete timesteps and use a spreadsheet for the calculations.&lt;/mdoxml&gt;</clueXML>
  <canonXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;
&lt;p&gt;If the three inputs add up to at least 15mV, the neuron will fire. If two of the inputs are $x$mV and $y$mV, the third input needs to be at least $(15-x-y)$mV.&lt;/p&gt;
&lt;p&gt;We find the truth table for the OR function, as expected.&lt;/p&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; style=&quot;width: 100px;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;A\B&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Here&amp;#39;s the truth table for the second network, which turns out to be the XOR function.&lt;/p&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; style=&quot;width: 100px;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;A\B&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Here&amp;#39;s a sketch of the first graph:&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;&quot; src=&quot;tanh.png&quot; style=&quot;width: 415px; height: 175px;&quot;&gt;&lt;/mdo:image&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;We can see the limit as $x\rightarrow \infty$ is $1$ and it&amp;#39;s $-1$ as $x\rightarrow -\infty$.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Here&amp;#39;s the second function, called the logistic function:&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;&quot; src=&quot;logistic%20function.png&quot; style=&quot;width: 431px; height: 127px;&quot;&gt;&lt;/mdo:image&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;It tends to $0$ as $x\rightarrow -\infty$ and $1$ as $x\rightarrow \infty$. At $0$, the function&amp;#39;s $\frac{1}{2}$.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;These have a continous derivative, which is very useful when calculating the weights in the &amp;quot;learning&amp;quot; stage. The fact that the gradient is positive models the idea that the neuron fires more rapidly as the input increases. The asymptotic behaviour is consistent with the fact a neuron has a maximum fire rate.&lt;/p&gt;

&lt;/mdoxml&gt;</canonXML>
  <end_user_role>2</end_user_role>
  <difficulty>3</difficulty>
  <keystage1>0</keystage1>
  <keystage2>0</keystage2>
  <keystage3>0</keystage3>
  <keystage4>0</keystage4>
  <keystage4plus>1</keystage4plus>
  <title>Neural nets</title>
  <description>Find out some of the mathematics behind neural networks.</description>
  <spec_group>Decision Mathematics and Combinatorics
    <specifier>Networks/Graph Theory</specifier>
  </spec_group>
  <spec_group>Applications
    <specifier>biology</specifier>
  </spec_group>
  <spec_group>Applications
    <specifier>physics</specifier>
  </spec_group>
</resource>