J. J. Merelo-Guervós > Algorithm-Evolutionary > XML

Download:
Algorithm-Evolutionary-0.78.tar.gz

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source   Latest Release: Algorithm-Evolutionary-0.79_2

NAME ^

XML - Syntax and semantics of the XML files used in OPEAL

SYNOPSIS ^

   my $xml==<<EOC;
  <?xml version="1.0"?>
  <!DOCTYPE ea SYSTEM "EvoSpec.dtd">
  
  <ea version='0.4'>
   <initial>
    <op name='Creator' >
      <param name='number' value='20' />
      <param name='class' value='Vector' />       
      <param name='options'>
        <param name='length' value='2' />
            <param name='rangestart' value='0' />
        <param name='rangeend' value='1' />
      </param>
    </op>

    <op name='Easy'  type='unary'>
       <param name='selrate' value='0.4' />
       <param name='maxgen' value='100' />
       <code type='eval' language='perl'>
          <src><![CDATA[ my $indi = shift;
                         my ( $x, $y ) = @{$indi->{_array}};
                         my $sqrt = sqrt( $x*$x+$y*$y);
                         return sin( $sqrt )/$sqrt;
          ]]></src>
        </code>
        <op name='GaussianMutation' type='unary' rate='1'>
                <param name='avg' value='0' />
                <param name='stddev' value='0.1' />
        </op>
        <op name='VectorCrossover' type='binary' rate='1'>
                <param name='numPoints' value='1' />
        </op>
      </op>
   </initial>

  </ea>
  EOC
  use Algorithm::Evolutionary::Experiment;
  use Algorithm::Evolutionary::Op::Easy;
  my $xp = Algorithm::Evolutionary::Experiment->fromXML( $xml );
  my $popRef = $xp->go();

DESCRIPTION ^

Algorithm::Evolutionary supports XML as a language for description of the evolutionary algorithm. The language is described in the EvoSpec.dtd file, which is an DTD file, something like a dictionnary that allows to check which constructions in XML are syntactically correct and which are not. This XML dialect will be called, for lack of a better name, EvoSpec. I tried to use XML Schemas instead of DTDs, but couldn't find a good tool to process them in Perl.

This dialect will be used to describe the algorithm, and also its results, that is, the population of individuals the algorithms is going to be applied to. The first part is contained within the initial tag, while the latter goes between a couple of pop tags, and right after the initial element.

initial

The initial tag contains several sections. In principle, the number of sections is not bounded, but it is usual to have only two, one related to the individuals, and another related to the population. Imagine that section as a set of transformations to be performed in turn. If you put a pop descriptor at the beginning of the initial element, and then an operator, the operator will be applied to the population; if it is an population Creator, and then several operators, the population will be created and then each operator will be applied in turn. initial is like a pipeline that applies operators to a population, which is implied or not, in document order.

So, basically what you will find or include in this section are operator and population elements.

pop

A population element might look like this: <pop size='20' <param name='type' value='BitString' /> <param name='length' value='64' /> </pop> > . The pop element has an attribute that indicates its size, and then describes the kind of individuals that are going to be create. This section includes parameters that describe the individual type and any other thing needed to create it; the parameters are type, for the class in which the individuals are going to be instantiated, and other parameters such as length, that will be passed to the class constructor.

op

After, or instead, the declaration of the initial population, there will be declarations for one or more operators that will act on the population. If there is no population, the first operator should be a Creator, just like this:

    <op name='Creator' > 
       <param name='number' value='20' /> 
       <param name='class' value='BitString' /> 
       <param name='options'> 
          <param name='length' value='64' /> 
       </param> 
    </op> 

A Creator is a 0-ary population operator: takes a population, which could have no individuals, and adds individuals as specified by the XML fragment. In this case, 20 individuals, of class Algorithm::Evolutionary::Individual::BitString, with the length as an option that will be passed to the individual constructor.

Once the population has been created, be it via the pop tag or a Creator operator, some stuff should be done on it. In this case, we apply the Algorithm::Evolutionary::Individual::Easy operator: an easy-to-build genetic algorithm, with default mutation and crossover operator. A couple of parameters, given using the param tag, are passed to the operator: the selection rate (selrate) and the maximun number of generations (maxgen). Each operator has its own parameters, which are normally (or should be) specified in its synopsis. Wrong parameters will not hurt, but if required parameters are not set, Perl will complain (as it should).

There is another part a bit further on that is required: the fitness function, which falls within the code tag. The language and the type of function should be specified. Right now, only the Perl language is supported, as well as only the eval or fitness function, but, in principle, any code could be passed this way; it will go to an entry in the operator under the _eval name. Since this entry includes free Perl code, it must be enclosed in a CDATA tag, so it's not interpreted by the XML parser.

Although this can be in any order, following the code come the operators that are going to be included in this operator. In this case, the operators are Mutation and Crossover, and they follow the same convention as its parent. Type and rate must be specified, as well as any parameters. These parameters are interpreted in the context of the operator, so they could be applied, in principle, to the population or to individuals within it; the only requisite is that the Algorithm::Evolutionary::Op::Base class is able to interpret this and create an operator from it.

Runtime

Any Algorithm::Evolutionary program should be able to generate valid XML at any point during execution; normally, whatever is generated during runtime will go after the initial tag, and will usually consist of a population section like this one.

  <pop> <indi type='BitString' fitness='16' >  <atom>0</atom>
  <atom>1</atom> <atom>1</atom> <atom>1</atom> <atom>1</atom>
  <atom>0</atom> <atom>0</atom> <atom>1</atom> <atom>0</atom>
  <atom>0</atom> <atom>1</atom> <atom>1</atom> <atom>1</atom>
  <atom>0</atom> <atom>0</atom> <atom>1</atom> <atom>1</atom>
  <atom>1</atom> <atom>1</atom> <atom>1</atom> <atom>0</atom>
  <atom>1</atom> <atom>1</atom> <atom>1</atom> <atom>0</atom>
  <atom>0</atom> <atom>1</atom> <atom>1</atom> <atom>1</atom>
  <atom>0</atom> <atom>0</atom> <atom>0</atom> <atom>1</atom>
  <atom>1</atom> <atom>1</atom> <atom>1</atom> <atom>1</atom>
  <atom>0</atom> <atom>0</atom> <atom>0</atom> <atom>1</atom>
  <atom>1</atom> <atom>1</atom> <atom>1</atom> <atom>1</atom>
  <atom>0</atom> <atom>0</atom> <atom>1</atom> <atom>1</atom>
  <atom>0</atom> <atom>0</atom> <atom>1</atom> <atom>1</atom>
  <atom>1</atom> <atom>1</atom> <atom>1</atom> <atom>1</atom>
  <atom>0</atom> <atom>0</atom> <atom>1</atom> <atom>0</atom>
  <atom>1</atom> <atom>0</atom> <atom>0</atom> </indi> </pop>

This population will be read when reinstating an experiment by the Algorithm::Evolutionary::Experiment class, and taken as initial population to apply the rest of operators on it.

Copyright

  This file is released under the GPL. See the LICENSE file included in this distribution,
  or go to http://www.fsf.org/licenses/gpl.txt

  CVS Info: $Date: 2009/07/24 08:46:59 $ 
  $Header: /cvsroot/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/XML.pod,v 3.0 2009/07/24 08:46:59 jmerelo Exp $ 
  $Author: jmerelo $ 
  $Revision: 3.0 $
syntax highlighting: