<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>CIlib</title>
 <link href="http://cilib.net/atom.xml" rel="self"/>
 <link href="http://cilib.net"/>
 <updated>2012-04-18T02:23:00-04:00</updated>
 <id>http://cilib.net</id>
 <author>
   <name>CIRG</name>
   <email>cirg@cs.up.ac.za</email>
 </author>

 
 <entry>
   <title>Simplified domain string grammar</title>
   <link href="http://cilib.net/updates/2012/04/17/simplified-domain-string-grammar"/>
   <updated>2012-04-17T00:00:00-04:00</updated>
   <id>http://cilib.net/updates/2012/04/17/simplified-domain-string-grammar</id>
   <content type="html">&lt;h2 id='the_need_to_change_domain_string_grammar'&gt;The need to change domain string grammar&lt;/h2&gt;

&lt;p&gt;Defining a domain for use within a simulation is allowed within CIlib as a simple string, such as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;R(-10.0,3.0)^7,Z(0,1),B^2,R(0.0,5.0)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The notation is simple enough, but it is unfortunately difficult to work with because the &amp;#8217;,&amp;#8217; token is overloaded to be both a separator for individual dimensions within the domain definitions as well as being the separator for lower and upper bound definitions within the dimension as well.&lt;/p&gt;

&lt;p&gt;In order to parse the above, a fair amount of state needs to be maintained to know the current &amp;#8220;scope&amp;#8221;. This mutable state results is utter havoc with concurrent usage of the domain parser. Two possible fixes could be applied to resolve this issue:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Re-create the parser each time, ensuring that each thread has its own instance.&lt;/li&gt;

&lt;li&gt;Make the parser stateless.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Option (1) seems reasonable but has a massive amount of effort for very little gain, whereas option (2) means that the parser can not only be reused, but that the concurrency issues should just disappear because no state is mangled.&lt;/p&gt;

&lt;p&gt;As a result, we have reimplemented the parser to be as stateless as possible. There is still some state within the parboiled parser library code that we have made peace with.&lt;/p&gt;

&lt;h2 id='what_has_changed'&gt;What has changed&lt;/h2&gt;

&lt;p&gt;The new parser now has two phases: (1) expansion and (2) transformation. The expansion process is responsible to convert &amp;#8220;exponent&amp;#8221; strings into simpler forms. As an example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;R^7 =&amp;gt; R,R,R,R,R,R,R&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The transformation phase then converts the declared types into actual instances that may be used within the algorithm. In order to differentiate the bounds and dimension elements, the upper and lower bounds separator has been changed from a &amp;#8217;,&amp;#8217; (comma) to a &amp;#8217;:&amp;#8217; (colon).&lt;/p&gt;

&lt;p&gt;The new domain string is then:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;R(-10.0:3.0)^7,Z(0:1),B^2,R(0.0:5.0)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is a minor change to the domain string representation, but the benefits we have gained through this little modification are far too large to pass up. To allow for the user to update the XML simulation specifications, clearer error messages have been created with the simulation refusing to execute without an updated domain string.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Recent changes in master</title>
   <link href="http://cilib.net/updates/2012/04/12/recent-changes-in-master"/>
   <updated>2012-04-12T00:00:00-04:00</updated>
   <id>http://cilib.net/updates/2012/04/12/recent-changes-in-master</id>
   <content type="html">&lt;p&gt;A couple of patches recently made their way into the master branch of CIlib which affect the way CIlib is used. The changes were made to the stopping conditions, topologies and control parameters.&lt;/p&gt;

&lt;h3 id='stopping_conditions'&gt;Stopping Conditions&lt;/h3&gt;

&lt;p&gt;In a bid to increase genericity (is that a word?) and remove duplicate code the stopping conditions package was revamped. The new stopping condition classes are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;MeasuredStoppingCondition which takes in a measurment an Objective and a target The measurement is taken from the measurement package, objective can be either Maximum or Minimum and target is the value the measurement must exceed (above for Maximum, below for Minimum) for the algorithm to terminate.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;MaintatinedStoppingCondition whcih takes in another StoppingCondition and the number of consecutive iterations for which the condition must hold before the algorithm can terminate.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are a few examples showing the differences from the before and after the changes.&lt;/p&gt;

&lt;h4 id='before'&gt;Before&lt;/h4&gt;

&lt;p&gt;Java:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;StoppingCondition sc = new MaximumIterations(2000);

StoppingCondition sc = new MinimumDiversity();
sc.setMinimumDiversity(ConstantControlParameter.of(0.01));
sc.setConsecutiveIterations(ConstantControlParameter.of(20));&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;XML:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;addStoppingCondition class=&amp;quot;stoppingcondition.MaximumIterations&amp;quot; maximumIterations=&amp;quot;2000&amp;quot;/&amp;gt;

&amp;lt;addStoppingCondition class=&amp;quot;stoppingcondition.MinimumDiversity&amp;quot;&amp;gt;
    &amp;lt;minimumDiversity class=&amp;quot;controlparameter.ConstantControlParameter&amp;quot; parameter=&amp;quot;0.01&amp;quot;/&amp;gt;
    &amp;lt;consecutiveIterations class=&amp;quot;controlparameter.ConstantControlParameter&amp;quot; parameter=&amp;quot;20&amp;quot;/&amp;gt;
&amp;lt;/addStoppingCondition&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id='after'&gt;After&lt;/h4&gt;

&lt;p&gt;Java:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;StoppingCondition sc = new MeasuredStoppingCondition(new Iterations(), new Maximum(), 2000);

StoppingCondition sc = new MaintainedStoppingCondition(new MeasuredStoppingCondition(new Diversity(), new Minimum(), 0.01), 20);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;XML:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;addStoppingCondition class=&amp;quot;stoppingcondition.MeasuredStoppingCondition&amp;quot; target=&amp;quot;2000&amp;quot;&amp;gt;
    &amp;lt;measurement class=&amp;quot;measurement.generic.Iterations&amp;quot;/&amp;gt;
    &amp;lt;objective class=&amp;quot;stoppingcondition.Maximum/&amp;gt;&amp;quot;
&amp;lt;/addStoppingCondition&amp;gt;

&amp;lt;addStoppingCondition class=&amp;quot;stoppingcondition.MaintainedStoppingCondition&amp;quot; consecutiveIterations=&amp;quot;20&amp;quot;&amp;gt;
    &amp;lt;condition class=&amp;quot;stoppingcondition.MeasuredStoppingCondition&amp;quot; target=&amp;quot;0.01&amp;quot;&amp;gt;
        &amp;lt;measurement class=&amp;quot;measurement.single.diversity.Diversity&amp;quot;/&amp;gt;
        &amp;lt;objective class=&amp;quot;stoppingcondition.Minimum/&amp;gt;&amp;quot;
    &amp;lt;/condition&amp;gt;
&amp;lt;/addStoppingCondition&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='topologies'&gt;Topologies&lt;/h3&gt;

&lt;p&gt;The main difference regarding topologies is how to get the best entity/entities. The getBestEntity method has been removed from the Topology classes and has been placed in the Topologies class as a static method along with a number of other methods. This was done to prevent overcrowding the topology interface and to separate concerns since a topology is only suppose to impose a structure on a population of entities.&lt;/p&gt;

&lt;h4 id='before'&gt;Before&lt;/h4&gt;

&lt;pre&gt;&lt;code&gt;Particle currentBest = topology.getBestEntity();
Particle gBest = topology.getBestEntity(new SocialBestFitnessComparator());

Particle nBest = particle.getNeighbourhoodBest();
// Although to the nBest could have changed so a more accurate way would be
// to iterate through the neighbourhood of the particle and compare each one&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id='after'&gt;After&lt;/h4&gt;

&lt;pre&gt;&lt;code&gt;Particle currentBest = Topologies.getBestEntity(topology);
Particle gBest = Topologies.getBestEntity(topology, new SocialBestFitnessComparator());

Particle currentNBest = Topologies.getNeighbourhoodBest(topology, particle);
Particle nBest = Topologies.getNeighbourhoodBest(topology, particle, new SocialBestFitnessComparator());&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='control_parameters'&gt;Control Parameters&lt;/h3&gt;

&lt;p&gt;Before, using control parameters that could change (e.g. linear increasing/decreasing parameters) meant that the user had to update the parameters every iteration. This became a hassle if a control parameter was introduced into code that already had a big inheritance structure since a mechanism for updating the control parameters would have to be introduced into each of those classes.&lt;/p&gt;

&lt;p&gt;The changes made allow a control parameter to automatically update its value when the getParameter method is called. One implication of this is that parameters cant be updated only once per iteration. This is a problem for algorithms that use multiple stopping conditions or whose stopping conditions dont include maximum iterations (ControlParameters updateon percentage completion of an algorith which is determined by the stopping conditions). This problem is dealt with by introducing a new ControlParameter: UpdateOnIterationControlParameter which takes in a delegate control parameter and updates it at the end of each iteration.&lt;/p&gt;

&lt;p&gt;Additionally, some parameters were merged to avoid duplicating code and control parameters are only bounded if used with BoundedControlParameter (which is a class now, not an interface).&lt;/p&gt;

&lt;h4 id='before'&gt;Before&lt;/h4&gt;

&lt;p&gt;Java:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// Only updated at the end of an iteration or when updateParameter was called
LinearIncreasingControlParameter cp = new LinearIncreasingControlParameter();
cp.setUpperBound(0.9);
cp.setLowerBound(0.4);
cp.setParameter(0.4);

LinearDecreasingControlParameter cp = new LinearDecreasingControlParameter();
cp.setUpperBound(0.9);
cp.setLowerBound(0.4);
cp.setParameter(0.9);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;XML:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;inertiaWeight class=&amp;quot;controlparameter.LinearIncreasingControlParameter&amp;quot;&amp;gt;
    &amp;lt;upperBound value=&amp;quot;0.9&amp;quot;/&amp;gt;
    &amp;lt;lowerBound value=&amp;quot;0.4&amp;quot;/&amp;gt;
    &amp;lt;parameter value=&amp;quot;0.4&amp;quot;/&amp;gt;
&amp;lt;/inertiaWeight&amp;gt;

&amp;lt;inertiaWeight class=&amp;quot;controlparameter.LinearDecreasingControlParameter&amp;quot;&amp;gt;
    &amp;lt;upperBound value=&amp;quot;0.9&amp;quot;/&amp;gt;
    &amp;lt;lowerBound value=&amp;quot;0.4&amp;quot;/&amp;gt;
    &amp;lt;parameter value=&amp;quot;0.9&amp;quot;/&amp;gt;
&amp;lt;/inertiaWeight&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id='after'&gt;After&lt;/h4&gt;

&lt;p&gt;Java:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// Updates whenever it is called
LinearlyVaryingControlParameter cp = new LinearlyVaryingControlParameter();
cp.setInitialValue(0.4);
cp.setFinalValue(0.9);

LinearlyVaryingControlParameter cp = new LinearlyVaryingControlParameter();
cp.setInitialValue(0.9);
cp.setFinalValue(0.4);

// Will update otherCP at the end of an iteration
UpdateOnIterationControlParameter cp = new UpdateOnIterationControlParameter();
cp.setDelegate(otherCP);

// Will always keep otherCP within bounds
BoundedControlParameter cp = new BoundedControlParameter();
cp.setBounds(new Bounds(-1, 1));
cp.setDelegate(otherCP);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;XML:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;inertiaWeight class=&amp;quot;controlparameter.LinearlyVaryingControlParameter&amp;quot; initialValue=&amp;quot;0.4&amp;quot; finalValue=&amp;quot;0.9&amp;quot;/&amp;gt;

&amp;lt;inertiaWeight class=&amp;quot;controlparameter.LinearlyVaryingControlParameter&amp;quot; initialValue=&amp;quot;0.9&amp;quot; finalValue=&amp;quot;0.4&amp;quot;/&amp;gt;

&amp;lt;inertiaWeight class=&amp;quot;controlparameter.UpdateOnIterationControlParameter&amp;quot;&amp;gt;
    &amp;lt;delegate class=&amp;quot;controlparameter.LinearlyVaryingControlParameter&amp;quot; initialValue=&amp;quot;0.9&amp;quot; finalValue=&amp;quot;0.4&amp;quot;/&amp;gt;
&amp;lt;/inertiaWeight&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If there are any questions join us on &lt;a href='http://webchat.freenode.net/?channels=cilib'&gt;irc chat&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 
</feed>
