is assigned to a node that is direct descendant of an-
other one, its instantiated output type and the relevant
instantiated input type of the other function must fit.
The aim is to have all the nodes fully instantiated after
the tree is generated. The result of crossover, mutation
etc. must be a valid function too.
The list of functions and terminals used together
with their types specification is presented in Table 5.
The terminal set consists of a variable X that repre-
sents the image input (its size (x, y) is known in ad-
vance), and a constant 2 that occurs very often in the
classic focus functions. Function
matrand
of null par-
ity generates random matrices of desired size in the
program generation time. If the size is unspecified,
matrand
generates a matrix of random size between
(1, 1) and (10,10). Therefore its output type gets in-
stantiated on a random basis. Some functions have
predefined type values from the definition: for ex-
ample, the function
sum
produces the sum of the el-
ements of an arbitrary matrix and therefore its output
type is fixed and its value is (1, 1). The function
hist
computes the histogram with 256 bins. The function
area
gives the multiplication of matrix sizes,
conv
is
the 2D convolution of two matrices. The meaning of
other functions is straightforward.
4.1 Generation of a New Tree
The most complicated part of the process lies in man-
aging the data flow during the instantiation. The fol-
lowing definition will be necessary:
Definition 4.1 A generic function is type-consistent
if and only if it holds that if all the input types are
fully instantiated, the output type is fully determined
as well.
An example of a function that does not fulfil this con-
dition is a unary function of which input type is (a, b)
and the output type is (c, d). The algorithm proposed
can work only on type-consistent functions.
The tree is built recursively, in a depth-first man-
ner. The data structures used by the algorithm are:
The table of functions and terminals – The table
stores information about the generic functions and
their types in terms of symbolic or predefined val-
ues, such as shown in Table 5. It is only read dur-
ing the process.
The function instances in the nodes – This data
structure is created at the same time when a node
is created. The information gets updated gradu-
ally. First, the name of the assigned elementary
function and its arity is stored here. Every time
a type component of this function instance is
instantiated, the value is stored here as well.
Investigating the node, it can be assumed what
types have already been instantiated.
The information flow concerning the types is done in
four ways (Procedure A to D). Every time a new node
is created, its output type might, but does not have to,
be fully instantiated. (The root of any program that
aims to become a focus function falls among those
that have a specified output. It is the type (1, 1) be-
cause we want to measure a focus by a scalar value.)
Based on this information, a function is randomly se-
lected only from those that comply with the output
type request. The number of the direct descendants of
this node is now known.
The table of functions and terminals (Table 5) is
read first in order to get the predefined values of type
components, if there are any.
The components of the output type of the node are
checked. If any of them is already instantiated, the
symbolic values in the table are checked. If there is a
symbolic value for this component of the output type,
it means that we have instantiated it already. The spe-
cific value gets in the node to every type component
that has the same symbolic value in the table (proce-
dure B). The process can cause (partial) instantiation
of both the input and output types of the node.
The information known at that moment is pro-
cessed further when the left-most descendant is gen-
erated.
When the left-most subtree is completed, the pro-
cess of elaborating this node continues. Because of
the type consistence property the output type of the
left descendant must be fully instantiated at that mo-
ment. If the left input type has not been instanti-
ated before, it takes the value of the left-most descen-
dant’s output (Procedure C). This information may
enrich the information about other types in the ac-
tual node, therefore procedure D is needed: it goes
through the input types and if some of their values are
newly instantiated, the symbolic values in the table
are checked similarly to procedure B. The informa-
tion goes to other components (including the output
types) according to the symbolic value in the table.
The same process continues with all other descen-
dants, including procedures C and D. At the latest
when the last branch is finished, the output type of
the actual node is fully instantiated, owing to the type
consistent property and procedure D.
4.2 Genetic Programming Experiment
Description
We used GPLAB (Silva and Almeida, 2003b), a ge-
netic programmming toolbox for MATLAB, which
ICINCO 2007 - International Conference on Informatics in Control, Automation and Robotics
444