Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Better yet, how about having it try to create a perl script and periodically eval'ing the result? *grin* "It's not obfuscated, it's written by my monkey!

They actually use a technique a bit similar to the monkeys system to breed programs. It's called genetic programming.

It can be used to breed program that are good at a certain task. Say for instance sorting a file or solving some math problem, or writing shakespeare :)

Applied to perl it would go something like this:

You have a population of 1000 individuals. Each individual is a program of say 100 lines of perl code. These lines are chosen randomly at the begin.

Each population goes through a number of generations. During each generation the fitness of each individual (perl program) is tested.

It is tested by running the program and evaluating how well it perform the target task. In the case of sorting it is tested of the file was sorted correctly and how fast the program sorted. Or how well it writes literature in case of the Shakespeare problem.

The 500 best programs are allowed to mate and produce two childern. For this a pair of programs is chosen at random. A random line number is chosen. Say n. Child 1 is created out of the first n lines of parent 1 and the remaining 100-n lines of parent 2. Child two is made out of the first n lines of parent 2 and the remaining 100-n lines of parent 1. Sometimes a line of code is also mutated, (changed a bit), this introduces more diversity.

Now all the parents die. What remains is a population of 1000 childern, a new generation. Which are hopefully better addapted to solving the given problem. The process is repeated.

With each generation the individuals will become better and better (on average) at solving the given problem. It works much like evolution works, survival of the fittest, with a bit of mutation.

The only thing you have to do solve a problem is specifiy is a function that defines how good a program is at solving the given problem.

Which is easy in most cases, though in case of the Shakespeare problem finding such a function is probably more difficult, cause how do you define good literature :)

Have Fun

GalaxyNG


In reply to RE: RE: Be a monkey! by gumpu
in thread Be a monkey! by KM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found