LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Genetic Algorithm optimization help

I can open the intrumentation control in 7.1 through "Select a .vi" button and place it on my block diagram. I think my best choice here is to find some way to get my program working again in 7.1.

The instrument is a pulse shaper, and its documentation is lousy.

So basically I'm stuck without all the nice newer features. I'm sure there's a way to get this thing to work in 7.1... Just no idea what's going wrong... When I chose a population size larger than 1 the vi just stops.

Here's the copy I did in version 7... Maybe I missed something simple? 

0 Kudos
Message 11 of 18
(1,083 Views)

I found two bugs so far.

1. In Weight.vi the DBL input to the case structure should be the output of the sum node, not one of the inputs.  The value on the shift register stays zero as wired.

2. In GAnumbers the comparison inside the for loop with the Wait(ms) function is < and should be >.

 

If you are new to LV, learn to use break points and Highlight Execution as debgging tools.  With htese I found your bugs in just a few minutes.

 

After those changes it seems to run OK.

 

If you can run the instrument control VIs in LV 7.1 maybe you can figure out what they are doing and rewrite them in a newer version.  How does the instrument communicate with the computer?  Where does the GA fit in with the instrument control?

 

Lynn

Message 12 of 18
(1,072 Views)

Okay after a couple of design changes that were necessary for the actual application of the GA a couple of things came up...

The biggest redesign was that the two parent arrays had to swap their elements at the same index. This effectively broke the GA's ability to maximize the array sum through reproduction only and relied almost solely on mutation. (not helpful)

If my wording isn't clear, it needed to do something like this:

[1 2 3 4 5] and [6 7 8 9 0] and swap the elements 3 and 4 into the other array starting at index 2. So swapping 3 and 4 to 8 and 9. This is a must for the experiment.

By doing this, we actually illuminated a problem with the GA: It was actually drastically reducing genetic diversity. There's something wrong with the way the algorithm works. My opinion is that it is in the select parent function.

We'd like to try out a different GA scheme, but I'm running into a problem with the design.

Basically, say I have an array with values [2 4 9 3 7 4] (note the repeated 4) and I want to sort this array from highest value to lowest value and output an array that shows the INDEX from highest value to lowest value... Using my example it would be an array of [2 4 1 5 3 0].

My current version will not recognize identical values in an array. I've attached an example. Also my GA with the couple of design alterations.

A final note, remember this all has to be in 7.1, at least unless I can figure out how to get the instrumentation control to work in 2010.

Thanks! 

Download All
0 Kudos
Message 13 of 18
(1,041 Views)

I have not thought much about your algorithm, although I had the vague suspicion that somehting about it was not right.

 

This is one way to do your sort.  Create an array of clusters of Numeric (data element) and I32 (index).  When you sort an array of clusters the sort is done on the first elemetn of the cluster.  Then pull out the index elements from the clusters into the array of indexes.

 

Lynn

 

Array sorter.png

Message 14 of 18
(1,035 Views)

hi, I am a chinese student.

And now I do some research about machine vision in that I also use the genetic algorithm to calculate some values

Today before, I use C++ and DLL to achieve the genetic algorithm

and now I think it will a good idea that achieve GA by labview

I'm vert interested in what you're working 

If you want to talk with me,

Here is my msn:      s.w.liu@hotmail.com 

 

 

lowry 

0 Kudos
Message 15 of 18
(1,027 Views)

Ah, see I had no idea that clusters worked in that way. That solves that little problem handily, thanks.

Guevara- Sorry but I doubt you'd find me very interesting to talk to. I'm just a physics student fumbling around with labview to get a program to work the way we want. 

Message 16 of 18
(1,014 Views)

We're trying to compile a lot of data to figure out what values to use in the program during the experiment. What's the best tool for this?

Say for population size, we want to see if changing the size from 5 to 30 has any effect. That would go on the x-axis of a graph, and on the y-axis we would have the average number of iterations it took for it to complete.

Then we'd probably do that for a number of other variables.

Something that we could let run on its own would be ideal!

Thanks for all the help. 

0 Kudos
Message 17 of 18
(995 Views)

I would probably write a VI with some test loops.

 

First I would decide which things will be allowed to change and which are determined by your final goal.  Then I would consider how fast things run and how many possible variations you really need to cover.  It is pretty easy to write a program which will take the rest of the year to complete execution. And then you find that it did not decord the data your really needed!  Decide how to present or analyze your data.  Graphs are very useful because the eye and brain can identify patterns or trends which would be hard to detect programmatically.  Is it worth saving paramters to a file for later analysis?

 

Modify the GAnumbers VI so that the array generation is not part of the VI.  That should be in the test loops program.  If you need to test it with various sizes of arrays, then you may need a loop to vary the arrays as well.  This it the kind of variations which can quickly increase the running time of the test progam.  Remove the chart.  No need to take time to plot that data for thousands of possible combinations. Remove the Wait(ms).  In test mode you will want that loop to run quickly.  After you narrow down the parameters to values which appear to work well, you can always run them in the original program.

 

You may want to modify the Select.vi to have a control for Weight rather than a random value. Or you may want to bring the Weight value out to an indicator so that you can tell what values worked.  Similarly, think about whether there is any value in knowing which elements were mutated.

 

Lynn

 

 

0 Kudos
Message 18 of 18
(983 Views)