Re: Neural networks

new topic     » goto parent     » topic index » view thread      » older message » newer message

Here is my first version of the genetics library. It is very simple, actually.
There are some bugs in it though, so if you could help figure them out, that
would be really great.

Also, I'll probably post my science fair research on my website sometime soon,
but I'm not sure when (I'm going to the state competition and I don't know
whether I should post my research until then... I'll ask my teachers when I get
back to school). Basically, I wrote a program to simulate natural selection in
Peppered Moths (there
was a famous study done in England about these, but I won't explain it all here.
You should be able to find it by searching the Internet).

-- Genetics library by Jeffrey Fielding (JJProg at cyberbury.net)
-- version 0.1 alpha
-- Allows programs to use genetic algorithms to adapt
-- Please send me your questions, comments, and suggestions
global constant GENES = 1, INVERSE_FITNESS = 2
global function evolve(sequence lifeforms, integer mutate, integer
inverseFitness, integer n)
    object k
    for i = 1 to length(lifeforms) do
lifeforms[i][INVERSE_FITNESS] =
         call_func(inverseFitness,{lifeforms[i]})
    end for
    for i = 1 to n do
         k = {}
         for j = 1 to length(lifeforms) do
             k = k & repeat(j,lifeforms[j][INVERSE_FITNESS])
         end for
         k = k[rand(length(k))]
lifeforms[k][GENES] =
         call_func(mutate,{lifeforms[rand(length(lifeforms))]})
lifeforms[k][INVERSE_FITNESS] =
         call_func(inverseFitness,{lifeforms[k]})
    end for
    return lifeforms
end function
-- All the rest of this code is a test. It creates a group of 1-gened things
with the gene ranging from 0 to 9.
-- They should adapt to 5.
sequence l
l = repeat(0,80)
for i = 1 to 80 do
    l[i] = {rand(10)-1,0}
end for
function m(sequence l)
    l[1] += rand(3)-2
    return l
end function
function inv(sequence l)
    if l[1] < 5 then
         return 5-l[1]
    else
         return l[1]-5
    end if
end function
while get_key() = -1 do
    l = evolve(l,routine_id("m"),routine_id("inv"),1)
    position(1,1)
    for i = 1 to 80 do
         printf(1,"%d",l[i][1])
    end for
end while

--
Jeffrey Fielding
JJProg at cyberbury.net
http://members.tripod.com/~JJProg/

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu