Linux version of GPdotNET v2.0 now on code.google.com


GPdotNET tree based genetic programming tool

GPdotNET LOGO

For Linux version of  GPdotNET v2.0 I have decided to publish on code.google.com. In the future GPdotNET will be developed separately for this two OSs. The second reason for publishing Linux version is that people don’t know for Linux version of GpdotNET.

So these two reason is enough to start separate hosting . When the final version of GPdotNET v2.0 will come, it would be the same as previously announced. After version 2, probably development of Linux and Windows version will be separated because of my preferred platform and some future plans and implementation with specific features for Windows 8.

Project home page for code.google.com is http://code.google.com/p/gpdotnet

Advertisement

With .NET 4.5, 10 years memory limit of 2 GB is over


There are numerous new features coming with .NET 4.5 and here, on this blog, you can find several posts about it. But the feature we are goint to talk about today is very exciting, because we were waiting for it more than 10 years. Since .NET 1.0 the memory limit of .NET object is 2GB. This means you cannot for example create array which contains elements with more than 2GB in total. If try to create such array, you will get the OutOfMemoryException.
Let’s see an example how to produce OutOfMemoryException.

Before that Open Visual Studio 2012, and create C# Console Application, like picture below.

First lets create simple struct with two double members like example below:

public struct ComplexNumber
{
    public double Re;
    public double Im;

    public ComplexNumber(double re,double im)
    {
        Re=re;
        Im=im;
    }

}

As we know this structure consumes about 16 bytes of memory.  So if we want to create array of this type which consume more than 2GB we need to create array at least with 134217728 instances. So this sample program below creates 130000000 (about 1,97 GB) of array.

int maxCount = 130000000;
ComplexNumber[] arr=null;
try
{
    arr = new ComplexNumber[maxCount];

}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

So if we run this sample program the output will be like picture below:

Let’s try to create 140000000 instances. This is about 2.08 GB. The output produces exception:

The new feature of .NET 4.5 allows to create object beyond this magical number. To enable creation of object more than 2 GB, you only need to set proper variable in configuration file. The new gcAllowVeryLargeObjects
Element enables creation of array that are greater than 2 gigabytes (GB) in total size on 64 bit platform.  So the following configuration file allows us to create more that 140000000 instances of our sample.

Now,If we run our sample the output is:

Ok how about to create more than 3GB of instances. For that propose, we need to create at least 201326592 instances. If we include this number in our sample the output is:

Be careful with this feature, because it will suck all your computer memory.

This feature works only with 64bit OS, it will not work with 32 bit.

Before you use this feature please see official description, because it contains some limitation which you must know before you use.

Complete source code for this blog post can be downloaded from here.

Happy coding with .NET4.5

GPdotNET v2.0 Tutorial: Working with optimization module


1. Optmization of analitycaly defined function

As it was announced GPdotNET v2.0 has new optimization modul based on Genetic Algorithm. In fact you can perform two kind of optimization in GPdotNET.

1. Optimization of analytic defined function

2. Optimization of GPModel

In tihis tutorial it will be presented how you can optimize classic mathematic function. For example we need to optimize the following function:

f(x)= x^{3}-6x^{2}+4x+12, on interval [-1; 5]

First lets see how this function looks like, and what is the optimum (maximum) of the function in defined interval. For this propose we are going to use WolframAlpha, great online mathematical tool. All you need to do in order to calculate optimum of our functionis just click the following link: http://www.wolframalpha.com/input/?i=maximize+x%5E3+-+6x%5E2+%2B+4x+%2B+12+inteval+-1%2C5

After we click on the link above internet explorer show the picture similar with below.clip_image002

As we can see maximum value is depicted with red point, and corespond with Max(0.367; 12.7). If you dont belive just calculate x=2-2*\sqrt{(\frac{2}{3})} and put in to function to get f(x).

Now our problem is how to do that with GPdotNET v2.0.

Working with Analytic Function edito in GPdotNET

1. Open GPdotNET v2.0 and press “New” Button.

2. The following dialog box appears:

clip_image004

3. Every time you want to create a new Model you got this dialog to choose what kind of model you want to create. As you previously know you can create 4 diferent models, and the last one is going to be show now.

4. Choose Optimization of analytic function (the last one), and the following windows appears:

clip_image006

On this picture we have 3 different. 1: Area for drawing three structures, 2: command for manipulation of analytic function and 3: register of constants and variables. The combo box Function contain all available function in GPdotNET, so if you want to add one just choose from the combo box and press Add Fun button.

To define our function we need to analyze it and start inserting operation by operation. If we look the function we have 3 addition, 1 substract, 2 multiplication, cube and quadrat. So first we are going to insert 1 addition.

5. From Function Combo box choose +, and press Add Funbutton, the following picture is appear.

clip_image008

After we inser + function, GPdotNET is automatically added to child, because addition operation has two argument.

6. Now click on Left child node, and Add “-” function similar like picture below:

clip_image010

7. Also on the left leaf node Add X^3 as picture show.

clip_image012

8. Select left node and add “*” function like picture below.

clip_image014

9. Now we are going to add X1- independent variable. Press Left mouse button on leaf node below X^3 function. In Param Name enter “X1” and press Add Param button. Notice that X1 is inserted in to right ListView control as register of variables.

Rule for Entering variable: You can only add variables in the form of : X1, X2, x3 ,….. The following picture shows the result of adding variable.

clip_image016

10. Now select left empty node “o” and insert constant 6. It is the same procedure as inserting variable. Type 6 in parame name and oress Add Param button. The rest of the job is similar so the final result mus be similar like picure below:

clip_image018

11. When we finish with defining the function press Finish button, and registered variables and constants are transferred to Terminals need to make program.

Running optimization module in GPdotNET

12. After you press Finish button, select Optimize Model tab, and we are ready to star finding optimum value for our function. Before we press RUN button on the toolbar we need to define maximum and minimum values for variable X1. To do this:

13. Select X1 in listView located in Optimize Model panel, enter minimum and maximum value and then press updatebutton.Now Optimum panel is rey for running simulaton.

clip_image020

14- Now that we have all needed information to run program, press Optimize toolbar button. In few millisecond program is started and simulation begins. After some evolution best solution (optimum) ius found so you can stop the program if you want to by pressing STOP toolbar button.

The solution of our optimization shows below picture.It is very closed to previous one calculated by WolframAlpha.

clip_image022

15. Press Save toolbar button and save your work.

2. Optimization of GPModel v2.0

Optimization of GPModel begins after you find solution to yout model.

1. When you create new model, choose second option instead of first for Modelling and optimization.

2. How to perform modelling in GPdotNEt you can see in previous post.

3. After you finish modeling refer to ste 12. the procedure is the same. Definie maximum and minumu value of vaiables and press Optimize button.

GPdotNET v2.0 first look


GPdotNET is artificial intelligence tool for applying Genetic Programming and Genetic Algorithm in modeling and optimization of various engineering problems. It is .NET (Mono) application written in C# programming language which can run on both Windows and Linux OS. This tool started in 2006 within postgraduate project for modeling and optimization with evolutionary algorithms. As open source project, GPdotNET is first published on November 5 2009 on codeplex.com. If you want to use GPdotNET you need to have at least basic knowledge about Genetic Programming and Genetic Algorithm. Since version 2, GPdotNET became cross-platfrom and cross-OS application.

GPdotNET v2.0 supports the following types of modeling and optimizations:

  1. Modeling of discrete data by using SymbolicRegression modeling with GP
  2. Modeling of discrete data by using SymbolicRegression with GP and optimization GPModel by using GA
  3. Time Series modeling data by using SymbolicRegression with GP
  4. Optimization of analytical defined function by using GA

GPdotNET v2.0 as Cross-Platform and Cross-OS application

GPdotNET v2 is developed against .NET 4.0 and Mono 2.8. Both frameworks share 100% of all code. Except of exporting model to Excel, all source code are the same. The pictures below show look of GPdotNET on Windows 7 (first one) and Fedora 17 (second one). GPdotNET v2.0 is tested only on Fedora OS.

image_thumb11
Picture above shows GPdotNET and its GP simulation panel in Windows 7.

image_thumb10
Picture above shows GPdotNET and its GP simulation panel in Fedora 17.

Optimization main new feature in GPdotNET

The main new feature among several other is Optimization based on Genetic Algorithm. You can either optimize GPModel calculated in previously thought GP modeling, and also optimize analytically defined function defined with analytic function editor. The picture below shows sample of defining f(x)=x^3 – 6x^2 + 4x + 12 in the analytic function editor. During construction of the function, right table is filled automatically with variables and constants. End of process of defining analytic function is finished when the Finish button is pressed to transfer variables and constants in to Optimization panel.

image_thumb15
Analytic function editor in GPdotNET

After the Finish button is pressed, switch to Optimize model tab and define maximum and minimum values for input variables. More information how to work with function editor can be found at this blog post.

image_thumb27

The picture above, show optimization panel, with defined min,max values (-1, 5) and also finished optimization proces founded result of f(0.36713)=12.7093. The process of optimization is similar with GP showing standard properties during of running program.

“*.gpa” – new file format for persisting GP and GA models

GPdotNET v2.0 introduce new textual file format for persisting GP and GA models and information during the program run. The file format is simple and easy, so sometimes you can edit in order to correct some minor changes. For example if you create GPModel without optimization, but later on you need to optimize this mode, you can easily change the type of model to enable optimization. The picture below shows sample GPdotNET “gpa” file format opened in Notepad++ with syntax highlighting.

image_thumb31

Before every line there is a comment with description.