1 / 20

Fitness Discussion

Fitness Discussion. March 19 th , 2014 Erik Fredericks. Overview. Value backend progress Code translation progress Fitness function discussion. Value Backend. Factory pattern not applicable to context Type must change at run time Factory instantiates different types

dwayne
Download Presentation

Fitness Discussion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fitness Discussion March 19th, 2014 Erik Fredericks

  2. Overview • Value backend progress • Code translation progress • Fitness function discussion

  3. Value Backend • Factory pattern not applicable to context • Type must change at run time • Factory instantiates different types • Currently working on an interface-based approach • Experiencing run-time errors (attempting to coerce type change via interfaces)

  4. Code Translation • Intend to focus on code generation/translation this upcoming week • Located point within EpochX that full abstract syntax tree is held in memory • Intention is to traverse tree in some fashion to generate code • Cannot use standard code translation tools with EpochX output, as it is not a “correct” s-expression • Extra parentheses required, less commas • Modifying internal representation within EpochX breaks framework

  5. Fitness Functions • For each will present: • Prose description • Mathematical function (if necessary) • Code • Reminder: • Best fitness is closest to 0.0 • My implementation penalizes by subtracting fitness and encourages by adding fitness • if fitness > 0.0, it is inverted as 1.0/fitness • Otherwise, the absolute value is taken to penalize it • Farther away from 0.0 than inverted values • Each node has a validity flag, which is true if everything is ok • A FALSE validity flag is penalized at the top level

  6. Fitness Flowchart • In code representation, returning a value is passed up to the next level Top Level (SAGE.java) Composition Level (Composition.java) Lower Level

  7. Fitness Flowchart (Lower Level) Lower Level Wrapper fitness (NWrapper.java) Fn. Pointer fitness (FunctionPointer.java) Module fitness (Module.java) Transform/Operation fitness (TypeConversion.java, Flatten.java, Expand.java, )

  8. Fitness – Transform and Operations • Only concerned with validity • Is transform valid (FLOAT2INT only valid if starting type is FLOAT) • Is operation valid (EXPAND only valid if starting array is 1-D) • Validity flag ignored here, as we penalize it early on in the process to remove invalid transforms If TRANSFORM.isValid() return this; // return as is else this.fitness -= 1000.0; // severely penalize return this;

  9. Fitness – Module • A MODULE can be passed up to a WRAPPER, FUNCTION POINTER, or directly out (in case of CODE INJECTION) • A module contains a target method, and then any number of parameters • Fitness is calculated as: • Sum of all prior fitness values (children of module parameters) • Validity check on the number of correct parameters (target preconditions+targetpostconditions) • Non-duplicates • Correct terminal variables placed in correct order

  10. Fitness – Module if len(children) == (len(target_preconditions) +len(target_postconditions)) : each child is unique : each child in either a source_precondition or target_postcondition

  11. Fitness – Module // check that rest of results match up with target preconditions intnum_res = this.getArity(); SageProgram[] res = new SageProgram[num_res]; //res0 is guaranteed to be TGT_METHOD by the grammar definition res[0] = ((SageProgram)getChild(0).evaluate()); for (inti = 1; i < num_res; ++i) { res[i] = ((SageProgram)getChild(i).evaluate()); res[0].updateValidXform(res[i].getValidXform()); } // ensure we have the correct number of terminals filling this if (num_res != (this.sage_program.target_preconditions.size() +this.sage_program.target_postconditions.size())) res[0].setValidity(false);

  12. Fitness – Module // ensure we don't have duplicates booleanunique = true; for (inti = 0; i < num_res; ++i) { for (int j = 0; j < num_res; ++j) { if (i == j) continue; if (res[i].getName() == res[j].getName()) { unique = false; break; }}} if (!unique) res[0].setValidity(false); // now make sure that we're using variables from the source preconditions // starting at 1 as the target method is guaranteed by the grammar for (inti = 1; i < num_res; ++i) { if (!this.sage_program.source_prelabels.contains(res[i].getName()) && !this.sage_program.target_postlabels.contains(res[i].getName())) { res[0].setValidity(false); break; }} // return the sub-fitness value of target method return res[0];

  13. Wrapper Fitness • Input and output transforms must be handled within wrapper • Target module must also be called within wrapper • Only a single target module may be passed • Consume previous fitness • Ensure source and target preconditions match • Ensure source and target postconditions match

  14. Wrapper Fitness : number of target modules == 1 else (20.0 * number of matched target preconditions) + (20.0 * number of matched source postconditions) + (-1.0 * number of mismatched target preconditions) + (-1.0 * number of mismatched source postconditions)

  15. Wrapper Fitness // evaluate all nodes before deciding fitness (easier to set breakpoints) for (inti = 0; i < num_res; ++i) { res[i] = ((SageProgram)getChild(i).evaluate()); if (res[i].getRole() == SageProgram.Role.TARGET_METHOD) { num_mod++; mod_indx= i; // track where the module is to give appearance of order } // ensure that all sub-nodes are valid if (!res[i].checkIfValid()) res[0].updateValidXform(-1000.0); else res[0].updateValidXform(res[i].getValidXform()); } if (num_mod > 1) { // there should only be a single target method res[0].updateValidXform(-1000.0); return res[0]; } else if (num_mod == 1) res[0].incrementValidXform(); // if module index is somehow incorrect, bail out if (mod_indx >= num_res) return res[0];

  16. Wrapper Fitness // check that source preconditions match target preconditions for (inti = 0; i < mod_indx; ++i) { // find a transform for each target precondition for (int j = 0; j < this.sage_program.target_preconditions.size(); ++j) { if ((res[i].getRole() == this.sage_program.target_preconditions.get(j).getRole()) && // role match (this.sage_program.source_prelabels.contains(res[i].getName())) && // terminal is in the correct list (!res[i].isSatisfied())) // not already satisfied { res[0].updateValidXform(20.0); res[i].updateSatisfaction(true); } else res[0].updateValidXform(-1.0); } } }

  17. Wrapper Fitness for (inti = mod_indx+1; i < num_res; ++i) { // find a transform for each source postcondition for (int j = 0; j < this.sage_program.source_postconditions.size(); ++j) { if ((res[i].getRole() == this.sage_program.source_postconditions.get(j).getRole()) && // role match (this.sage_program.target_postlabels.contains(res[i].getName())) && // terminal is in the correct list (!res[i].isSatisfied())) // not already satisfied { res[0].updateValidXform(20.0); res[i].updateSatisfaction(true); } else res[0].updateValidXform(-1.0); } } return res[0];

  18. Function Pointer Fitness • This one is more straightforward • Only a single child node allowed, and it must be a MODULE • TARGET_METHOD constrained to MODULE node • Transforms in and out are handled by MODULE if (this.getRole() != TARGET_METHOD) this.validity = FALSE; return this;

  19. Fitness – Composition Level • Consume previous fitness • Code and mathematical formulae are the same except: • If a WRAPPER, then return • pre/postcondition matching should already be satisfied • If calculated fitness is 0.0, return -1.0 (as 0.0 is the initialized value)

  20. Fitness – Top Level • Total sum of calculated sub-fitnesses • fitness cannot equal 0.0 if (fitness < 0.0) or (tree is invalid) fitness = Math.fabs(fitness) else fitness = 1.0 / fitness

More Related