LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Genetic Algorithm optimization help

I've been working on this genetic algorithm for a while now and finally got it to a point where it actually performs its duty. It will eventually be reprogrammed to be used with a pulse shaper, but the final product won't need too many adjustments. Right now all it does is try to find an array with the largest possible sum given randomly generated initial arrays.

We'd like to be able to use this with a relatively low population size, so getting the optimum values in the least number of iterations is very important.

Any help that could be provided optimizing the code would be greatly appreciated.

0 Kudos
Message 1 of 18
(2,978 Views)

You did not include any subVIs.

0 Kudos
Message 2 of 18
(2,971 Views)

Whoops. I hope this works.

0 Kudos
Message 3 of 18
(2,961 Views)

Some questions.

 

In GAnumbers.vi what is the purpose of the Array Subset in the for loop? The output is the same as the input with nothing wired to index or length.

 

The While loop only stops when the last row of the 2D array has a sum > 1000. Did you want it to stop if any row is > 1000? In many cases the Max Fitness value exceeds 1000 several iterations before the program stops.

 

In Weight.vi moving the Array Sum outside the loop and using autoindexing improves performance slightly.  If the loop has not stopped by the time all the elements of the array have been tested the Index Array will return zero (default value for the datatype) which will result in an infinite loop.  Unless you are sure this cannot happen for any values of the inputs, adding a test to stop when the array has been competely checked would be appropriate. Use of the for loop with the conditional stop terminal is probably the easiest way.

 

You have a lot of coercion dots.  Most are probably harmless, but does a fractional index in Mutate.vi do what you want it to do?

 

Adding some descriptive comments to your subVIs will make it easier for others to understand what the subVI is doing.  When you come back in six months to three years to modify the program, you will thank yourself for the comments.

 

Lynn

0 Kudos
Message 4 of 18
(2,935 Views)

My inexperience is apparent. I've reuploaded the library with comments.

To answer your questions:

Array subset in the for loop: absolutely nothing, I forgot to take it out from a previous iteration.

While loop stop: Yes, I'd like the while loop to stop once it has reached the condition. I had a feeling it was doing that but I'm not sure how to fix that.

 

weight.vi: I'm not sure what you mean here about moving the Array Sum outside of the loop. As far as the infinite loop goes, the math ensures the last index will return a value of 1. I haven't run into any problems with it, but if the code is preventing that from being true then I gotta fix it.

 

All mutate.vi is supposed to do is replace a random element with a random number. (But only sometimes)

Sorry about the comments. I knew I should have done them it just completely slipped my mind. Thanks for the response. 

0 Kudos
Message 5 of 18
(2,905 Views)

I changed Weight.vi and GAnumbers.vi to show the use of the conditional for loop.  I moved controls which will not change during the operation of the VI to outside the loops.  There is no reason to read them multiple times if the result never changes.

 

I also added a stored array so that the operation of the algorithm could be checked on multiple runs against the same data.  With the data changing on every run it may be difficult to tell which paramter settings are good ones and which ones got a lucky data set.  I changed the Max Fitness chart to show the error rather than the direct value.  Personal preference, not necessarily better.

 

I would probably set up an outer loop which would allow recording of metrics and statistics for various parameter values while evaluating the performance of the algorithm.

 

Lynn

 

 

Download All
Message 6 of 18
(2,897 Views)

I see. A lot of this makes sense. A couple questions though...

[edit- removed] Whoops, figured that part out. My mistake.

How does the stored array work?

Finally, do you have a link of some sort that might point me to a tutorial on how to make a loop to record metrics? That would be extremely useful for me.

Thank you for all your help. 

0 Kudos
Message 7 of 18
(2,889 Views)

Ah geez, so I discovered this morning that the instrumentation control we're going to be using isn't compatible with Labview 2010 and I was reprogramming everything to be used in labview 7.1 (the only other version we have that's compatible with it and the save for prev. version doesn't go that low) and now everything is breaking. 😞 The control we're using doesn't have a block diagram and I can't insert it into my VI.

This is making me very sad.

Here's one of the vi controls we're using. Any idea if there's a way to get it to work in 2010? (The only file in the .llb that will go on the block diagram is XDoSLM.vi) 

0 Kudos
Message 8 of 18
(2,879 Views)

Ouch! That hurts.

 

The reason that you cannot open those files is that they were saved without block diagrams.  Without the block diagrams the newer versions of LV cannot recompile them.  I jusrt tried it in LV 7.1 and got the same result.

 

You will need to contact the party which developed that library and ask them for the block diagrams or for a newer version.

 

Lynn

0 Kudos
Message 9 of 18
(2,877 Views)

What kind of instrument is it?  How does it communicate with the computer? Do you have the manuals for the instrument?

 

Sometimes it is easier to write yoru own communications codes than to chase down or upgrade old ones.

 

Lynn

0 Kudos
Message 10 of 18
(2,874 Views)