Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/14/2011 in all areas

  1. Name: Waptia - genetic optimization algorithm Submitter: vugie Submitted: 10 Sep 2009 File Updated: 23 Jan 2011 Category: General LabVIEW Version: 8.2 License Type: BSD (Most common) Waptia - genetic optimization algorithm Copyright © 2009, Wojciech Golebiowski All rights reserved. Author: Wojciech Golebiowski (w_golebiowski (at) tlen.pl) Name: Waptia - genetic optimization algorithm Type: library LabVIEW version: 8.2 Distribution: This code was downloaded from: http://www.lavag.org Description: Waptia is general genetic optimization algorithm - it tries to maximize user supplied function of N variables (so called "Fitness Function"). Function is given as strictly typed VI reference. So the optimization goal may be described as: find such set of N numbers for which Fitness Function value is highest. Waptia is LabVIEW implementation of quite well known genetic optimization algorithm Pikaia by Paul Charbonneau & Barry Knapp developed in Fortran-77. For more information on Pikaia and some background informatio on genetic algorithms visit: http://www.hao.ucar....kaia/pikaia.php Pikaia name comes from lancelet-like creature which lived ages ago in Cambrian sea and waptia was another Cambrian being. Original Pikaia was developed for educational purposes, but it grew up and became widely used routine. Waptia is almost 1:1 conversion of Pikaia code (which is public domain) to LabVIEW - parts of original Fortran code are placed in related VIs - with some cosmetic modifications and improvements. Although Waptia already does real job I treat this code as starting point for further development to create sophisticated, but still easy to use genetic algorithm. Here are Waptia's core features: - decimal genotype encoding - two-point crossover operator - optional dynamically adjustable mutation rate - optional "creep" (smoothly changing) mutation mode - three possible reproduction plans - elitism - optionally stops optimization when fitness criterion is satisfied - optimization progress may be traced on-line with notifiers Usage is very simple - just put Waptia.vi on block diagram and provide number of independent variables and fitness function VI reference (which may be created using included template). There is of course a lot of parameters to tune, but default set usually does good job. Installation Preferably install VIP package with VI Package Manager Alternatively extract ZIP to User.lib. There are no external dependencies. Documentation Documentation is provided in "Waptia docs.rtf" file. It's just a description of all controls of Waptia.vi with some background information. Same information may be found in context help. Information on how to write your own fitness function is provided as comments in "Fitness Function Template.vit" If you want to understand how Waptia works, whole code is extensively commented. Examples There is one quite complex example (but I hope that still understandable) located in _examples folder - "multimodal optimise.vi" If you want any support on general or specifically genetic optimization problems, just contact me. License (BSD): Copyright © 2009 Wojciech Golebiowski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Click here to download this file
    1 point
  2. Short explanation first - this is continuation of ours private discussion, so I repeat some things already said. Thanks for asking it - PID optimization is a very good use case for genetic algorithm. But you have to remember that it is only good for off-line optimization as it base on huge number of trials. So you have to have prepared a numerical model of your object of control - a program (VI in case of LabVIEW) which respond on control signal exactly the same way as real object would respond. To prepare it you have to know what phenomena drives your object, what are their equations and you have to implement them with proper coefficients (measured i.e.). To be more specific I have to know what exactly do you want to control with PID. Once you have the model you have to insert it into simulated PID loop, so you have a model of whole control system with Kp, Kd and Ki coefficients as parameters (gains of proportional, differentiating and integrating blocks respectively). Than you have to determine what will be the measure of quality of regulation. Typically parameters of response on step-like excitation are used for this purpose: You have to decide which of these parameters are more important, which are less important, which are not important at all and combine them into one number which is the higher, the better regulation is. It may be for example weighted sum: a*(1/rise_time)+b*(1/overshoot)+c*(1/settling_time), where a,b,c are the weights. In genetic algorithm such a number is called a fitness function and PID optimization process may be now described as: find such Kp, Kd, Ki which maximizes previously defined fitness function. You have to implement a fitness function as a VI which takes certain Kp, Kd and Ki parameters, makes a simulation of control system's response on step-like excitation, calculates quality parameters out of the response and combines them into final quality measure. In Waptia you have to implement fitness function as a strictly typed VI. There is a special template in main Waptia directory (Fitness Function Template.vit): Phenotype input (1D array of doubles) in terms of genetic algorithm is a set of parameters describing the system, which are the subject of optimization. In our case size of this array will be always 3 and Kp, Kd and Ki will be coded in it. Coded, because optimizer requires all parameters to be scaled to 0..1 range. So you have to know the expected ranges for optimized gains (you could determine them using i.e. Ziegler–Nichols method and some manual checking). Your fitness function VI could look like this: Data and Init? inputs are not required in simplest approach, but they may not be deleted as VI must be strictly typed. You could use these inputs to control other parameters of the models which are not to be optimized (i.e. coefficients of equations of the model). Code for actual optimization of PID gains is now as simple as: Values from final solution have to be scaled, because optimizer works on 0..1 range and it doesn't know anything about scaling you use. Most significant parameters for optimizer are population size , number of generations (both affect computation time) and number of significant digits. All parameters are described in documentation, but if you need more detailed explanation, don't hesitate to ask. It was quite general introduction for PID optimization using genetic algorithm. To help in anything more specific, I have to know more details on what do you want to control. But if you already have a model as you said, you are very close to make an optimization of PID gains.
    1 point
  3. I just got the results, I passed my CLAD!!! with 77.5% good answers, which was my practice score.Hope I can pass CLD after I graduate (Master degree) I used LabVIEW for everyone, so thanks to Jim Kring and Jeffrey Travis, this book is worth a read!
    1 point
  4. Hi Steve Firstly, this is just my opinion. Secondly, if it works - it works (so good job ) - but I always like to ask myself can it be done better? So on that note, comparing your two posts, it feels that you have just used LVOOP for the sake of it. As a result you have coupled your UI to the logic of your code. I discussed this on the darkside here with respect to the CLD so I won't regurgitate it again, only to say that you mention that... ...yet you have used logic (nodes) on the top level BD which are not encapsulated. Additionally, you have used typedefs that are not part of a Class, but which form an interface to your Class (i.e. public clusters) (private clusters is another topic for discussion when persisting data to disk not relevant to this one). This is not always a bad thing, I do this for: UI Classes where the role of the Class is to essentially take data and format it for display (but note there is always that distinction) - I do this as opposed to breaking out an X-Control when I don't need to. Very Top Level Class which is just wrapping up all the Classes e.g. so method calls do not sit on the BD of a process\loop etc... - this is what I think you have done however, underneath it is still coupled. Therefore, I think there is the opportunity to encapsulate more. However, given the size of the application it may be overkill, but would definitely be a good exercise. I don't think LVOOP makes it more exciting, perhaps using LabVIEW 8.6 instead of 2010 was a better idea this time to cover more reviewers? Although I prefer LVOOP when programming day-to-day, I ended up using a more traditional approach for the CLD given the nature of the question\solution, time available etc... Cheers -JG
    1 point
  5. As suggested earlier, post your code and we can be more helpful. Perhaps even a VI Snippet. tushar gave you good advice regarding timing when the trigger occurs. To further elaborate, if you are simply wanting the time from execution to the first threshold, you can place a tick count vi before your while loop. Place another inside the while loop inside a case structure that has the selector wired to the same boolean as what turns the LED on. In the false case you can put the put the tick count from the beginning. Then subtract the two and conditionally wire the result into a numeric indicator. When true you'll see the time between start and threshold, when false you should see 0. I have a feeling you may need a little bit more sophisticated approach, but this should get you started for now.
    1 point
  6. I uploaded the VIPM package (thanks Jim for resolving the building issue).
    1 point
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.