Genetic Algorithms
Hello
I need some help with GAs. I have only just started reading about them. I need to manipulate a sin wave. There are two parameters I want to change. The amplitude and the frequency. As there are two pieces of info I am not sure how to code them into one chromosome. I have read that there are different types of GAs. Could someone poss give me some pointers and names of methods on how I can code this up.
Cheers
Richard
I presume you want to manipulate a sine wave function so that it fits some data, or a known function. Is that correct?
To work out your encoding scheme, you need to determine a reasonable discretision of the continuous parameter variables. If you have some domain information that puts limits on the parameter values, then this helps a lot. Otherwise, you''ll need some trial and error.
Once you''ve worked out how many discrete values of each parameter you have, you can determine how many bits of information it will take to encompass that information. A string of length L can encode 2L different numbers.
When you''ve got your string representation, you need to work out your storage technique. The simplest is a fixed length array, although this is somewhat slower when it comes to processing within the GA. A bit array is faster and direct operation on bit strings is usually the fastest. Each method has its pros and cons.
You might want to consider using a library like GALib rather than write your own code if this is going to be a one off affair with GAs.
If you need more help or have specific questions, just holler.
Cheers,
Timkin
To work out your encoding scheme, you need to determine a reasonable discretision of the continuous parameter variables. If you have some domain information that puts limits on the parameter values, then this helps a lot. Otherwise, you''ll need some trial and error.
Once you''ve worked out how many discrete values of each parameter you have, you can determine how many bits of information it will take to encompass that information. A string of length L can encode 2L different numbers.
When you''ve got your string representation, you need to work out your storage technique. The simplest is a fixed length array, although this is somewhat slower when it comes to processing within the GA. A bit array is faster and direct operation on bit strings is usually the fastest. Each method has its pros and cons.
You might want to consider using a library like GALib rather than write your own code if this is going to be a one off affair with GAs.
If you need more help or have specific questions, just holler.
Cheers,
Timkin
The ''Tiddlywink'' example program on my website demonstrates a GA solving for a small amount of values.
There is a link to the source at the end of the GA tutorial.
ai-junkie.com
There is a link to the source at the end of the GA tutorial.
ai-junkie.com
My Website: ai-junkie.com | My Books: 'Programming Game AI by Example' & 'AI Techniques for Game Programming'
Thanks for the repies guys.
Timkin you are right I want to manipulate the sine wave to get a given freq and amp. I want to use it to partly control rhythmic movment of a leg. I want to make sure that the legs can walk without falling over etc so I want the GA to find the parameters.
Thanks fup for the reply I will look on your web site at the tutorial
Richard :D
Timkin you are right I want to manipulate the sine wave to get a given freq and amp. I want to use it to partly control rhythmic movment of a leg. I want to make sure that the legs can walk without falling over etc so I want the GA to find the parameters.
Thanks fup for the reply I will look on your web site at the tutorial
Richard :D
Thanks for the repies guys.
Timkin you are right I want to manipulate the sine wave to get a given freq and amp. I want to use it to partly control rhythmic movment of a leg. I want to make sure that the legs can walk without falling over etc so I want the GA to find the parameters.
Thanks fup for the reply I will look on your web site at the tutorial
Richard :D
Timkin you are right I want to manipulate the sine wave to get a given freq and amp. I want to use it to partly control rhythmic movment of a leg. I want to make sure that the legs can walk without falling over etc so I want the GA to find the parameters.
Thanks fup for the reply I will look on your web site at the tutorial
Richard :D
quote: Original post by RichardJones
Timkin you are right I want to manipulate the sine wave to get a given freq and amp.
And I presume you don''t know this freq/amp before hand? How do you plan to evaluate possible solutions from the GA. That is, what is your Objective Function?
Cheers,
Timkin
Hello
I am using a CPG to control the legs of a biped walking. I have looked a lot of stuff up on CPGs and it gets very hardcore. So instead of having to learn neuroscience I have decided to use a GA to calculate the parameters of the CPG. The fitness function will look at the amp and freq and calculate whether the simulation will slip, fall over or actually walk. The objective is to make it actually walk. This function is what I am not looking forward to. I think it will be some intense mechanics!!
I hope this has made clearer what I am intending to do
Cheers
Richard
I am using a CPG to control the legs of a biped walking. I have looked a lot of stuff up on CPGs and it gets very hardcore. So instead of having to learn neuroscience I have decided to use a GA to calculate the parameters of the CPG. The fitness function will look at the amp and freq and calculate whether the simulation will slip, fall over or actually walk. The objective is to make it actually walk. This function is what I am not looking forward to. I think it will be some intense mechanics!!
I hope this has made clearer what I am intending to do
Cheers
Richard
Ah, okay. So you have a black box function that takes as inputs the amplitude and frequency and outputs a results (whether the limb is waling, falling, etc.).
As I said above, you''ll need to discretise the inputs and encode them in a binary string. You''ll also need to be able to decode an arbitrary binary string to turn it into a frequency and amplitude.
Given this encoding scheme you can apply your genetic operators: selection, crossover and mutation. If you require help in working out how these work or how to implement them, just holler.
Good luck,
Timkin
As I said above, you''ll need to discretise the inputs and encode them in a binary string. You''ll also need to be able to decode an arbitrary binary string to turn it into a frequency and amplitude.
Given this encoding scheme you can apply your genetic operators: selection, crossover and mutation. If you require help in working out how these work or how to implement them, just holler.
Good luck,
Timkin
Timkin''s suggestions are the traditional GA way of doing things, and they should be able to do what you want. However, I have some alternatives you may find useful:
1 - Evolve the phenotype rather than the genotype. If you want mutation, rather than switching ones and zeroes, then add, perhaps, a random number in the range (-k,k), where k itself may be a random number.
2 - If you find you need more complicated functions than simple sine waves, try evolving an expression tree. Alternatively, since all periodic functions can be expressed as the sum of many sine waves, try evolving a list of amplitudes and frequencies, that represents the summation.
1 - Evolve the phenotype rather than the genotype. If you want mutation, rather than switching ones and zeroes, then add, perhaps, a random number in the range (-k,k), where k itself may be a random number.
2 - If you find you need more complicated functions than simple sine waves, try evolving an expression tree. Alternatively, since all periodic functions can be expressed as the sum of many sine waves, try evolving a list of amplitudes and frequencies, that represents the summation.
Howdy.
Regarding TeranFury's comments, he's discussing (1) Evolution Strategies and (2) Genetic Programming, while Timkin is talking about Genetic Algorithms.
I agree that if you want to stick with the exact sine wave and just modulate the parameters determining frequency and amplitude, Evolution Strategies is the way to go. However, you might want a function which is much different (not so perfectly cyclic), so Genetic Programming to generate the specific function might be the answer you're looking for. If you choose this path, watch out for program bloating though - a classic problem in GP.
Any of the three approaches will likely work, it all depends upon the representation versus the ultimate goal.
-Kirk
[edited by - KirkD on November 8, 2002 1:49:40 PM]
Regarding TeranFury's comments, he's discussing (1) Evolution Strategies and (2) Genetic Programming, while Timkin is talking about Genetic Algorithms.
I agree that if you want to stick with the exact sine wave and just modulate the parameters determining frequency and amplitude, Evolution Strategies is the way to go. However, you might want a function which is much different (not so perfectly cyclic), so Genetic Programming to generate the specific function might be the answer you're looking for. If you choose this path, watch out for program bloating though - a classic problem in GP.
Any of the three approaches will likely work, it all depends upon the representation versus the ultimate goal.
-Kirk
[edited by - KirkD on November 8, 2002 1:49:40 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement