uunnii-time

--

    o
      \
       o --- o
      /
    o
           http://uunniivveerrssee.net

3 comments to uunnii-time

  • /// test dna lib

    import processing.opengl.*;
    import s373.dna.*;

    String targetStr = “i code therefore i am “+(int)random(100);
    DNA targetDna;
    DNA testDna, curDna, machDna, mach2Dna;
    int numGenerations, numMach, numMach2;
    boolean numMachSet = false, numMach2Set = false;
    float fit;

    void setup() {
    size(500,500,OPENGL);

    ///analyse and build target dna
    float data[] = new float [ targetStr.length() ];
    for(int i=0;i data[i] = ( targetStr.charAt(i) / 255.0f );
    }
    targetDna = new DNA(data);
    /// random dnas to start
    testDna = new DNA(data.length);
    curDna = new DNA(testDna);
    machDna = new DNA(curDna);
    mach2Dna = new DNA(machDna);

    numGenerations = 0;

    targetDna.print();
    fit = curDna.fitness(targetDna);
    println("curDna fitness: "+fit);
    textFont(createFont("arial",15));
    // textMode(CENTER);
    fill(0);
    noStroke();
    println(targetStr);
    }

    void draw() {

    background(247);
    numGenerations++;

    /// monkey approach
    fill(0);
    text( writeFromDna(targetDna), 5, 20);
    text( writeFromDna(curDna), 5, 50);
    float bestFit = curDna.fitness(targetDna);
    float testFit=0;
    int numLoops = 0;
    // while ( testFit <= bestFit && numLoops < 1000) {
    if ( testFit <= bestFit ) {
    testDna.setDna(curDna);
    testDna.mutate(0.05);
    testFit = testDna.fitness(targetDna);
    numLoops++;
    }
    curDna.setDna(testDna);

    text(""+numGenerations+" "+numLoops, 5, 100);

    int w = 250;
    drawSliders(targetDna, width - w - 25, 20, w, 100, color(0,100,200), 25);
    drawSliders(curDna, width - w - 25, 20, w, 100, color(0,200,100), 150);

    /// machDna approach
    boolean doneMach = true;
    for(int i=0; i float difGene = machDna.differenceGene( i, targetDna );
    if( difGene > 1e-8) { ///0.00000001
    machDna.mutateGene(i, difGene*1.2);
    doneMach = false;
    break;
    }
    }
    if(doneMach && !numMachSet) {
    numMachSet = true;
    numMach = numGenerations;
    }
    fill(0);
    text( writeFromDna(targetDna), 5, 220);
    text( writeFromDna(machDna)+” : “+numMach+” : “+doneMach, 5, 250);
    drawSliders(targetDna, width – w – 25, 220, w, 100, color(0,100,200), 25);
    drawSliders(machDna, width – w – 25, 220, w, 100, color(0,200,100), 150);

    /// mach2Dna
    boolean doneTest = true;
    float testDif[] = mach2Dna.differenceDNA(targetDna);
    for(int i=0; i if( testDif[i] > 1e-8) {
    mach2Dna.mutateGene(i, testDif[i]*0.7);
    doneTest = false;
    }
    }
    if(doneTest && !numMach2Set) {
    numMach2Set = true;
    numMach2 = numGenerations;
    }
    fill(0);
    text( writeFromDna(targetDna), 5, 420);
    text( writeFromDna(mach2Dna)+” : “+numMach2+” : “+doneTest, 5, 450);
    drawSliders(targetDna, width – w -25, 420, w, 100, color(0,100,200), 25);
    drawSliders(mach2Dna, width – w -25, 420, w, 100, color(0,200,100), 150);
    }

    String writeFromDna(DNA d) {
    String s=”";
    for(int i=0;i s+= (char)( d.getGene(i)*255.0f);
    }
    return s;
    }

    void drawSliders(DNA dna, int x, int y, int w, int h, color c, int al) {
    float rw = (float) w / dna.getNum();
    fill(c, al);
    for(int i=0;i int locx = x + (int)(i*rw);
    rect(locx, y, rw, dna.getGene(i)*h);
    }
    }

    void keyPressed(){
    if(key=='s')
    saveFrame("dnaReach-#####.png");
    }

    s373.dna lib test ping

  • /e of that a s t:a possible enj s.appl ns ve mai xt/plain; on 5 ati th bj — Envcv d .net b T o uroZi / e: ow \ .z millio a 0:18 X- so, Z ons the tent-Ty record t zi cra he Con li euro find book, r o charset=us-ascii ce r: Fro u record. /s37 d, 3.n @ to o me e to ct: only, you o l all on sm e 00 73.ne 20 37 s373 l Su & zilli oding: http:/ all http://uunniivveerrssee.net onaut makes l onte pe: o s [ = ic q ue, piece oy, +0100 Dat pilations, frien u astr shoftware on h at w an u wind ] p J ha y Smtp-S euros of a C 3 ll player, om a just right e = on t :2 oted-pri o op break ip nt-Transfer- erve ul told in = ntable o 11 com ha@s is .s you re — ion s m: e et 3.net/x fr

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>