Anda di halaman 1dari 9

CSC 514 Project

Documentation
Group 7

Agho Adrian
Odunuga Kemi

080805015
080805065

Olubumni Morgan

080805058

Onuigbo Elizabeth

090805046

Documentation of the implementations of the Sentence Verifier algorithm,


Simple GA algorithm, and using Real-coded GA to train FFNNs.

Sentence Verifier
Project Description
The verify sentence algorithm is a recursive algorithm that takes in an expression
and determines whether it is really a valid sentence or not. The algorithm is as
follows:
function verify_sentence(expression);
begin
case
expression is an atomic sentence: return SUCCESS;
expression is of the form Q X s, where Q is either or , X is a
variable,
if verify_sentence(s) returns SUCCESS
then return SUCCESS
else return FAIL;
expression is of the form s:
if verify_sentence(s) returns SUCCESS
then return SUCCESS
else return FAIL;
expression is of the form s1 op s2, where op is a binary logical
operator:
if verify_sentence(s1) returns SUCCESS and
verify_sentence(s2) returns SUCCESS
then return SUCCESS
else return FAIL;
otherwise: return FAIL
end
end.

Conceptual Design
The program takes in a string to represent the expression as input. In order to
simplify the selection of the process, symbols are first identified and extracted
out from the string (a process similar to token generation in lexical analysis). This
is achieved by passing the string through finite state automata as illustrated
bellow:
Connectives and Quantifiers: ^ (Represents Conjunction), * (Represents
Disjunction), ! (Represents Negation), ~ (represents Implication), =
(represents Equivalence), $ (represents Universal Quantifier), % (represents
Existential Quantifier).

Start

Return Conjunction
Symbol

Return Disjunction
Symbol

Return Negation
Symbol

Return Implication
Symbol

Return Equivalence
Symbol

Return Universal Quantifier


Symbol

Return Existential Quantifier


Symbol

%
Delimiter

Uppercase
Letter
Lowercase
Letter

10
12

15

Return Predicate
End

Delimiters: , ,.
8

Othe
r

Othe
r

11

Go back to
state 0

Delimit
er
Variable: Jam, Var_10_x, etc.

10

Uppercase
letter/
Lowercase
letter/ Digit/

Return Variable
Symbol

Constant: jam, var_10_x, etc.

12

Uppercase
letter/
Lowercase
letter/ Digit/

Othe
r
(

13

Return Constant
Symbol

14

Return Predicate
Begin

The finite state automaton identifies symbols from the list, which are then
passed into the algorithm as a list.

Program Description
The program consists of 7 classes:
1. Symbol Class: this class represents a symbol type as used in predicate
calculus. It specifies its type (e.g. Connective), instance (e.g. Conjunction)
and its actual value (e.g. ^).
2. SymbolAnalyser Class: this class implements the finite state automata
described above. Its main method getSymbol() takes in a string, and
passes each character into a switch-case. This switch-case successfully
models the above automata.
3. SentenceVerifier Class: the sentence verifier class implements the main
verify_sentence algorithm. Its main method verifySentence() takes in a
list of symbols and recursively calls itself to verify if the sequence of
symbols in the list conform to the structure of a valid statement.
4. RunVerifier Class: this is the main class where the components of all
other classes are used. The input string is read from a text file. A
SymbolAnalyser instance is created and the string is passed into its
getSymbol method, the result of which is stored in a symbol list. A
SentenceVerifier instance is created to assess the components of the
string list. The result of the analysis is sent into an output text file.
5. ReadTextFile Class: this class implements the procedure for getting the
input string from the input text file.
6. CreateTextFile Class: this class implements the procedure for writing
the output to a text file.
7. FailException Class: a custom exception class.

Simple Genetic Algorithm


Project Description
The next project is the implementation of the Simple GA. The evolutionary
algorithm has the following features:
1.
2.
3.
4.

The genes of a chromosome are represented as binary strings.


Proportional selection is used to select parents for recombination.
Recombination/Crossover method adopted is the one-point crossover.
Mutation operator used is the uniform/random mutation.

The algorithm for the simple GA is as follows:


Algorithm SGA
Let t = 0 be the generation counter;

n x -dimensional population,

Create and initialize an

ns individuals;
while stopping condition(s) not true do

f ( x i ( t ) ) , of each individual,

xi ( t ) ;

Evaluate the fitness,

o
o

Select individuals to form the mating pool based on their fitness;


Perform reproduction/crossover to create offspring for new
population

C( 0) , to consist of

o
o
End

C( t+1) ;

Mutate each offspring;


Advance to the new generation, i.e. t = t + 1;

Also, the SGA should be used to solve the following problems:

Ackley problem,
Griewank problem,
Rastrigin problem,
Rosenbrock problem, and
Spherical problem.

Conceptual Design

Genetic Individual: the genetic would form the basic element upon
which the GA operators would act upon. It would represent the genes of a
chromosome, and its fitness according to the fitness function used.
Environment: this would represent the world in which the genetic
individual exist and interact. Here the GA operations (i.e. selection,

crossover, mutation) are carried out on the genetic individuals that exist in
that environment.

Program Description
The program is a windows form application that consists of 1 form, 1 interface
and 8 classes:

1. IFunction Interface: interface for the function classes.


2. Ackley, Griewank, Rastrigin, Rosenbrock and Spherical Classes:
Model their respective functions.
3. GeneticIndividual Class: models the chromosome. It holds an integer
array to represent the bit string (i.e. the genes) and another variable for
its fitness value.
4. Environment Class: models the environment of the chromosomes. It is
initialized with the necessary parameters (i.e. mutation probability,
generation number, population number, etc.) and implements the
methods for selection, crossover, and mutation.
5. Form 1: a user interface for the input of initialization data, and to show
the output results.

Using Real-Coded Genetic


Algorithm to Train Feedforward
Neural Networks
Project Description
The final project uses a real-coded GA to train a feedforward neural network. The
features of the project differ from the SGA:
1. The genes of a chromosome are represented by real numbers.
2. Proportional selection is used to select parents for recombination.
3. Recombination/Crossover method adopted is the SBX crossover (Simulated
Binary Crossover).
4. Mutation operator used is the non-uniform mutation.

Conceptual Design
The algorithm used is similar to the SGAs, the major difference to be noted is
the fitness function used:

Bias 1

Weight 1 = Gene 1

1
x1

2
Chromosome i

x2

Bias 3

D9
D2
D3

D7

D4
D5

D8

D6

D 11
Out 1

D 10
Bias 2

Each chromosome is a representation of a complete feedforward neural network,


where the chromosomes genes represent the weights of the network. The
fitness function is therefore a single feedforward pass of the network, using the
chromosomes genes as the weights of that network.

Program Description
The program is a windows form application that consists of the following
elements:

1. GeneticIndividual Class: models the chromosome. It holds a floating


number array to represent the genes and another variable for its fitness
value.
2. Environment Class: models the environment of the chromosomes. It is
initialized with the necessary parameters (i.e. mutation probability,
generation number, population number, etc.) and implements the
methods for selection, crossover, and mutation.
3. ICrossover Interface: interface for the SBX class.
4. SBX: models the SBX crossover procedure.
5. IMutate Interface: interface for the UniformMutation class (discarded
in final implementation).
6. UniformMutation Class: models the uniform mutation procedure.
7. NeuralNetwork Class: models a feedforward neural network.

8. Form 1: a user interface for the input of initialization data, and to show
the output results.

Anda mungkin juga menyukai