Some simple questions

140 views
Skip to first unread message

Daniel Kramer

unread,
Sep 23, 2009, 10:22:11 AM9/23/09
to pyevolve

Hello, I just started using pyevolve for the first time and
integrating it into a 3D animation package, mostly to play. I have a
very simple problem (of which I don't really need GA for, but just to
get the system talking to my 3D package).. I want to evolve the
translates and rotates of one object to match another object.. get one
object to follow the other one around each frame of the animation. So
each genome (hope I'm getting the terms right) has 6 genes tx ty tz rx
ry rz

-Since I know something about my genes and my environment I'd like a
different min/max per gene. I see how to set that for all params, but
not a diff val for each. I suppose I can set the min max to 0-1 and
then have my own min/max per gene and fit the 0-1 to whatever I need.
Just didn't know if there was a better way

-I'd also like to define an initial condition. I see how to make a
population of n size and I'd want just one of those members to be hand
defined. I'm not clear how to do that. Essentially define a best
individual so the answer I get back is at least as good as that.. if
nothing is found that's better I just get that same one back. when
stepping though my animation I'd use the best answer from the previous
frame as the starting point for the next.

-Lastly since I know that the first 3 genes are translates and the
last 3 are rotates I'd like to give each gene a mutation variance
amount.. for example I may say that the most a translate gene can
mutate is 10 units where the most a rotate can mutate is 5 degrees.
This may go against the basic premises of GA, don't really know as
this is my first time using it! I guess I'm trying to give it some
extra info to guide the result.

Thanks for the great module, so far it's been very easy to integrate
as my 3D package has a python scripting lang.

Daniel

Christian S. Perone

unread,
Sep 25, 2009, 3:36:19 PM9/25/09
to pyev...@googlegroups.com
For some reason, the default gmail behaviour in the iGoogle is to not reply to list, so I'm sending here the emails between me and Daniel just to become public in the list, sorry for the mistake.

- Christian S. Perone

christian.p...@gmail.com <christian.p...@gmail.com> Thu, Sep 24, 2009 at 11:12 AM
To: Daniel Kramer <daniel...@gmail.com>
Hello Daniel, follow the answers of your questions.


On Sep 23, 2009 11:22am, Daniel Kramer <daniel...@gmail.com> wrote:
>
>
>
>
> Hello, I just started using pyevolve for the first time and
>
> integrating it into a 3D animation package, mostly to play.  I have a
>
> very simple problem (of which I don't really need GA for, but just to
>
> get the system talking to my 3D package).. I want to evolve the
>
> translates and rotates of one object to match another object.. get one
>
> object to follow the other one around each frame of the animation.  So
>
> each genome (hope I'm getting the terms right) has 6 genes tx ty tz rx
>
> ry rz
>
>

First, let's call your parameters of P set [tx,ty,tz,rx,ry,rz]; the question is: the data type of each parameters are the same ? They are real or integers ? Anyway, you can put heterogeneous data into the G1DList chromosome, so I think it is the best representation for your problem.


>
> -Since I know something about my genes and my environment I'd like a
>
> different min/max per gene.  I see how to set that for all params, but
>
> not a diff val for each.  I suppose I can set the min max to 0-1 and
>
> then have my own min/max per gene and fit the 0-1 to whatever I need.
>
> Just didn't know if there was a better way
>

See the http://pyevolve.sourceforge.net/module_allele.html#GAllele.GAlleles documentation, you must use the GAlleles and insert into it the GAlleleRange, so you can define ranges for each parameter.



>
> -I'd also like to define an initial condition.  I see how to make a
>
> population of n size and I'd want just one of those members to be hand
>
> defined.  I'm not clear how to do that.  Essentially define a best
>
> individual so the answer I get back is at least as good as that.. if
>
> nothing is found that's better I just get that same one back.  when
>
> stepping though my animation I'd use the best answer from the previous
>
> frame as the starting point for the next.

You must define your own initialization function, so you can control the initial population, see the Initializators.py module for examples.


>
>
> -Lastly since I know that the first 3 genes are translates and the
>
> last 3 are rotates I'd like to give each gene a mutation variance
>
> amount.. for example I may say that the most a translate gene can
>
> mutate is 10 units where the most a rotate can mutate is 5 degrees.
>
> This may go against the basic premises of GA, don't really know as
>
> this is my first time using it!   I guess I'm trying to give it some
>
> extra info to guide the result.
>

You must define your own mutation function too, see the Mutators.py for an example of how you can create one. You need to take care of the range of parameters too, so you need to check a mutator for alleles to use as base for your own mutation function.
[Quoted text hidden]

Daniel Kramer <daniel...@gmail.com> Thu, Sep 24, 2009 at 1:34 PM


On Thu, Sep 24, 2009 at 7:12 AM, <christian.p...@gmail.com> wrote:
Hello Daniel, follow the answers of your questions.


On Sep 23, 2009 11:22am, Daniel Kramer <daniel...@gmail.com> wrote:
>
>
>
>
> Hello, I just started using pyevolve for the first time and
>
> integrating it into a 3D animation package, mostly to play.  I have a
>
> very simple problem (of which I don't really need GA for, but just to
>
> get the system talking to my 3D package).. I want to evolve the
>
> translates and rotates of one object to match another object.. get one
>
> object to follow the other one around each frame of the animation.  So
>
> each genome (hope I'm getting the terms right) has 6 genes tx ty tz rx
>
> ry rz
>
>

First, let's call your parameters of P set [tx,ty,tz,rx,ry,rz]; the question is: the data type of each parameters are the same ? They are real or integers ? Anyway, you can put heterogeneous data into the G1DList chromosome, so I think it is the best representation for your problem.


Yes, I'm using the G1DList, they are all real numbers.
 

>
> -Since I know something about my genes and my environment I'd like a
>
> different min/max per gene.  I see how to set that for all params, but
>
> not a diff val for each.  I suppose I can set the min max to 0-1 and
>
> then have my own min/max per gene and fit the 0-1 to whatever I need.
>
> Just didn't know if there was a better way
>

See the http://pyevolve.sourceforge.net/module_allele.html#GAllele.GAlleles documentation, you must use the GAlleles and insert into it the GAlleleRange, so you can define ranges for each parameter.



I wondered about the Alleles, ok I'll try and figure that out.  I do have something already working in a diff way.  Associated with each gene (or transformation channel) I have a "mutate variance".. say that's 10.  .  Within a custom ConvergenceCriteria() at each new generation the min/max is redefined as a variance off the best individual.   So if tx is 50.1 then min is 40.1 and max is 60.1, I do that for each gene.  I think this is working, but I'm still playing.  I'll look at the Alleles.   BTW, the min max I actually get back from pyevolve is always 0-1 and I fit that to my own min/max per gene.
 

>
> -I'd also like to define an initial condition.  I see how to make a
>
> population of n size and I'd want just one of those members to be hand
>
> defined.  I'm not clear how to do that.  Essentially define a best
>
> individual so the answer I get back is at least as good as that.. if
>
> nothing is found that's better I just get that same one back.  when
>
> stepping though my animation I'd use the best answer from the previous
>
> frame as the starting point for the next.

You must define your own initialization function, so you can control the initial population, see the Initializators.py module for examples.


Ok.  I tried doing a ga.initalize() then getting the population and modifying the first member to match my initial condiion.  Then do my own for loop with ga.step().  I don't think that's working though, I get back answers that aren't as fit as my initial condition.  I'll look at the init function, didn't see that before.


>
>
> -Lastly since I know that the first 3 genes are translates and the
>
> last 3 are rotates I'd like to give each gene a mutation variance
>
> amount.. for example I may say that the most a translate gene can
>
> mutate is 10 units where the most a rotate can mutate is 5 degrees.
>
> This may go against the basic premises of GA, don't really know as
>
> this is my first time using it!   I guess I'm trying to give it some
>
> extra info to guide the result.
>

You must define your own mutation function too, see the Mutators.py for an example of how you can create one. You need to take care of the range of parameters too, so you need to check a mutator for alleles to use as base for your own mutation function.


My current workaround of setting a variance and custom min/max may do what I want.. though probably not as clean.  I'll will look at all your suggestions, thanks for taking the time to help out

D

 

>
> Thanks for the great module, so far it's been very easy to integrate
>
> as my 3D package has a python scripting lang.
>
>
>
> Daniel



--
--------------------
Daniel Kramer

daniel...@gmail.com <daniel...@gmail.com> Thu, Sep 24, 2009 at 4:23 PM
Hello Christian,

I've implemented much of what you've suggested which (if it's working correctly) was pretty easy. I'm not doing anything with Alleles and I don't think I need to, if I understand it correctly.

My new initializer takes two new parmas, both lists. One is the init gene and the other is a variance value per gene. So my genes can only deviate so far from the init. maybe the Gaussian would have been just fine, not sure. I just wanted to avoid a min/max at all and keep it relative

def G1DListInitializatorRealDank(genome, **args):

genome.clearList()

genomeInit = genome.getParam("genomeInit", xrange(genome.listSize))
genomeVariance = genome.getParam("genomeVariance", xrange(genome.listSize))

for i in xrange(genome.listSize):
randomReal = rand_uniform(genomeInit[i] - genomeVariance[i], genomeInit[i] + genomeVariance[i])
genome.append(randomReal)


New Mutator, simply mutates the incoming gene only as much as the variance allows. Similar to the init one.

def G1DListMutatorRealRangeDank(genome, **args):

if args["pmut"] <= 0.0: return 0
listSize = len(genome)
mutations = args["pmut"] * (listSize)
genomeVariance = genome.getParam("genomeVariance", xrange(genome.listSize))

if mutations < 1.0:
mutations = 0
for it in xrange(listSize):
if Util.randomFlipCoin(args["pmut"]):
genome[it] = rand_uniform(genome[it] - genomeVariance[it], genome[it] + genomeVariance[it])
mutations += 1

else:
for it in xrange(int(round(mutations))):
which_gene = rand_randint(0, listSize-1)
genome[which_gene] = rand_uniform(genome[which_gene] - genomeVariance[which_gene], genome[which_gene] + genomeVariance[which_gene])
return mutations


I think all of this is working and it's much simpler (and probably faster) then what I was doing before. The one part that's not working is having my initial starting point genome as part of the population. The initializer acts on a genome at a time and I'd want at least one genome in the population to equal my initial starting point genome. I'm not clear how I add that to my population before I run the evolve() method.
[Quoted text hidden]

Christian S. Perone <christian.p...@gmail.com> Thu, Sep 24, 2009 at 8:49 PM
Hello Daniel, the code seems right, you can add your initial starting point genome using the "stepCallback":

      def your_func(ga_engine):
         # Here you get the pop from ga_engine and add your genome
         return False

      ga_engine.stepCallback.set(your_func)

The "your_func" will be called in this step:

Initialize
Evaluate
Call stepCallback function
(...)

Every generation it will be called, so you must check in "your_func", if is the first generation, you can use ga_engine.getCurrentGeneration() to verify this, try putting a print inside to see. So, you'll check if it's the first generation and then simple replace an individual with your initial starting point individual, it should be easy too.
[Quoted text hidden]
--
Christian S. Perone
http://pyevolve.sourceforge.net/wordpress
"Forgive, O Lord, my little jokes on Thee, and I'll forgive Thy great big joke on me."

Daniel Kramer <daniel...@gmail.com> Fri, Sep 25, 2009 at 3:09 AM
To: "Christian S. Perone" <christian.p...@gmail.com>
Thanks Christian, sounds good.  I did get it working and in addition to adding in my init values I had to also set the score.  I basically compare the score of my init values against the pop[0] after the 1st generation, if it's more fit then I replace pop[0].  Seems to work just fine.

Thanks for all the help, I've got a working example of a very generic pyevolve node in my 3D package working.  A few years back at my last company we wrote a 3d camera tracker using GA so I know there are many applications that this can help with

d
[Quoted text hidden]
--
--------------------
Daniel Kramer

christian.p...@gmail.com <christian.p...@gmail.com> Fri, Sep 25, 2009 at 8:53 AM
To: Daniel Kramer <daniel...@gmail.com>
Your package sounds cool, Python as scripting for 3D is very productive, good work man !

Yours,
- Christian S. Perone
[Quoted text hidden]
> if args["pmut"] listSize = len(genome)
> mutations = args["pmut"] * (listSize)
> genomeVariance = genome.getParam("genomeVariance", xrange(genome.listSize))
>
>
>
>
> if mutations mutations = 0
[Quoted text hidden]

--
Christian S. Perone
http://pyevolve.sourceforge.net/wordpress
"Forgive, O Lord, my little jokes on Thee, and I'll forgive Thy great big joke on me."
Reply all
Reply to author
Forward
0 new messages