<!--

  thr_networks.xml            thelma package documentation          Victor Bovdi
																	Vasyl Laver

  Copyright (C) 2018  Victor Bovdi, Vasyl Laver, Department of Mathematical Sciences,
  UAEU, Al Ain, United Arab Emirates
  This file is free software, see license information at the end.

  This chapter contains the operations with threshold networks.

-->

<Chapter Label="thr_networks">
<Heading>Networks of Threshold Elements</Heading>

Not all Boolean functions can be realized by a single threshold element. However, all of them can be realized by a multi-layered network of threshold elements, with a number of threshold elements on a first layer and conjunction or a disjunction on the second layer. In this chapter we will decribe some functions regarding such networks.

<Section Label="thr_net_basic">
<Heading>Basic Operations</Heading>
In this section we describe some operations, similar to the ones described in Section
<Ref Chap="thr_basic"/>.

<ManSection>
<Func Name="NeuralNetwork" Arg="InnerLayer, OuterLayer"/>
<Description>
<!-- The names chosen for the arguments describe their meaning.-->
For the list of threshold elements <C>InnerLayer</C>  and the Boolean variable <C>OuterLayer</C>, which
can be either <C>true</C> (for disjunction), <C>false</C> (for conjunction), or <C>fail</C> (if there is only
one layer) the function <C>NeuralNetwork</C> returns a neural network built from this inputs.


<Example>
<![CDATA[
gap> te1:=ThresholdElement([1,1],1);
< threshold element with weight vector [ 1, 1 ] and threshold 1 >
gap> te2:=ThresholdElement([-1,-2],-2);
< threshold element with weight vector [ -1, -2 ] and threshold -2 >
gap> inner:=[te1,te2];
[ < threshold element with weight vector [ 1, 1 ] and threshold 1 >,
  < threshold element with weight vector [ -1, -2 ] and threshold -2 > ]
gap> nn:=NeuralNetwork(inner,false);
< neural network with
2 threshold elements on inner layer and conjunction on outer level >
gap> Display(last);
Inner Layer:
[ [[ 1, 1 ], 1], [[ -1, -2 ], -2] ]
Outer Layer: conjunction
Neural Network realizes the function f :
Boolean function of 2 variables.
[ 0, 0 ] || 0
[ 0, 1 ] || 1
[ 1, 0 ] || 1
[ 1, 1 ] || 0
Sum of Products:[ 1, 2 ]
]]>
</Example>
</Description> </ManSection>

<ManSection>
<Func Name="IsNeuralNetwork" Arg="Obj"/>
<Description>
<!-- The names chosen for the arguments describe their meaning.-->
For the object <C>Obj</C> the function <C>IsNeuralNetwork</C> returns <C>true</C> if
<C>Obj</C> is a neural network (see <Ref Func="NeuralNetwork" />), and <C>false</C> otherwise.

<Example>
<![CDATA[
gap> ## Consider the neural network <C>nn</C> from the previous example.
gap> IsNeuralNetwork(nn);
true
]]>
</Example>
</Description> </ManSection>

<ManSection>
<Func Name="OutputOfNeuralNetwork" Arg="NNetwork"/>
<Description>
<!-- The names chosen for the arguments describe their meaning.-->
For the neural network <C>NNetwork</C> the function <C>OutputOfNeuralNetwork</C> returns the Boolean function, realized by <C>NNetwork</C>.

<Example>
<![CDATA[
gap> f:=OutputOfNeuralNetwork(nn);
< Boolean function of 2 variables >
gap> Display(last);
Boolean function of 2 variables.
[ 0, 0 ] || 0
[ 0, 1 ] || 1
[ 1, 0 ] || 1
[ 1, 1 ] || 0
]]>
</Example>
</Description> </ManSection>

</Section>

<Section Label="thr_net_net">
<Heading>Networks of Threshold Elements</Heading>
In this section we consider the networks of threshold elements.

<ManSection>
<Func Name="BooleanFunctionByNeuralNetwork" Arg="Func"/>
<Description>
<!-- The names chosen for the arguments describe their meaning.-->
For the Boolean function <C>Func</C> the function <C>BooleanFunctionByNeuralNetwork</C> returns a two-layered neural network,
which realizes <C>Func</C> (see <Ref Func="NeuralNetwork" />).
The realization of this function is based on the algorithm proposed in <Cite Key="GecheRobotyshyn83"/>.

<Example>
<![CDATA[
gap> x:=Indeterminate(GF(2),"x");;
gap> y:=Indeterminate(GF(2),"y");;
gap> z:=Indeterminate(GF(2),"z");;
gap> f:=PolynomialToBooleanFunction(x*y+z,3);
< Boolean function of 3 variables >
gap> nn:=BooleanFunctionByNeuralNetwork(f);
< neural network with
2 threshold elements on inner layer and disjunction on outer level >
gap> Display(last);
Inner Layer:
[ [[ -1, -2, 4 ], 2], [[ 1, 2, -3 ], 3] ]
Outer Layer: disjunction
Neural Network realizes the function f :
Boolean function of 3 variables.
[ 0, 0, 0 ] || 0
[ 0, 0, 1 ] || 1
[ 0, 1, 0 ] || 0
[ 0, 1, 1 ] || 1
[ 1, 0, 0 ] || 0
[ 1, 0, 1 ] || 1
[ 1, 1, 0 ] || 1
[ 1, 1, 1 ] || 0
Sum of Products:[ 1, 3, 5, 6 ]
]]>
</Example>
</Description> </ManSection>


<ManSection>
<Func Name="BooleanFunctionByNeuralNetworkDASG" Arg="Func"/>
<Description>
<!-- The names chosen for the arguments describe their meaning.-->
For the Boolean function <C>Func</C> the function <C>BooleanFunctionByNeuralNetworkDASG</C>
returns a two-layered neural network which realizes <C>Func</C> (see <Ref Func="NeuralNetwork" />).

The realization of this function is based on decomposition of <C>Func</C> by the non-unate
variables with the biggest influence. The DASG algorithm (DASG - Decomposition Algorithm
for Synthesis and Generalization) was proposed in <Cite Key="Subirats2008"/>,
however we use a slightly modified version of this algorithm.

<Example>
<![CDATA[
gap> f:=LogicFunction(3,2,[0,0,0,0,0,1,1,0]);
< Boolean function of 3 variables >
gap> nn:=BooleanFunctionByNeuralNetworkDASG(f);
< neural network with 2 threshold elements on inner layer and conjunction on outer level >
gap> Display(last);
Inner Layer:
[ [[ 1, 4, 2 ], 3], [[ 1, -4, -2 ], -3] ]
Outer Layer: conjunction
Neural Network realizes the function f :
Boolean function of 3 variables.
[ 0, 0, 0 ] || 0
[ 0, 0, 1 ] || 0
[ 0, 1, 0 ] || 0
[ 0, 1, 1 ] || 0
[ 1, 0, 0 ] || 0
[ 1, 0, 1 ] || 1
[ 1, 1, 0 ] || 1
[ 1, 1, 1 ] || 0
Sum of Products:[ 5, 6 ]
]]>
</Example>
</Description> </ManSection>
</Section>


<!-- ############################################################ -->

</Chapter>

<!--
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->
