130 likes | 253 Vues
This document outlines recent updates to grammar and fitness functions within modular programming, addressing previous glitches and limitations. Key improvements include better management of low-level variables, enabling outputs to meet specified conditions, and expanding capabilities for handling multi-dimensional arrays. Detailed examples illustrate the setup of variables, preconditions, and postconditions, demonstrating the effect of code injection on processing arrays. The next steps involve strengthening the wrapper fitness function and implementing a factory pattern for live variables.
E N D
Example Output February 5th, 2014 Erik Fredericks
Overview • Grammar / fitness update • Examples • Next steps
Grammar/Fitness Update • Fixed glitch with grammar and fitness sub-function, as presented last week • MODULE production was not able to reach low-level variables properly, resulting in bad output • Fitness was limiting mid-level output to a single child • Rewarding trees that produced a COMPOSITION with a number of children that matched the amount of source postconditions • In this case, 1
Examples / Setup • Live variables (terminals) • bubble_sort : target_method • num_cols : int • incoming_array : array_int_2d • convert-me-to-int : double
Examples / Setup // - source preconditions: what variables are available to us convert-me-to-int : DOUBLE num_cols : INT bubble_sort: TARGET_METHOD incoming_array : ARRAY_INT_2D // - source postconditions: what we expect the variables to be in the end sorted_numbers_2D_array: ARRAY_INT_2D // - target preconditions: target module parameters bubble_sort: TARGET_METHOD values_to_sort : ARRAY_INT_2D low_index : INT // (these will be updated to be low/high index high_index : INT // following addition of values and slight grammar // change) // - target postconditions: output from module sorted_values: INT_ARRAY
Examples / Setup Terminals // - source preconditions: what variables are available to us convert-me-to-int : DOUBLE num_cols : INT bubble_sort: TARGET_METHOD incoming_array : ARRAY_INT_2D // - source postconditions: what we expect the variables to be in the end sorted_numbers_2D_array : ARRAY_INT_2D // - target preconditions: target module parameters bubble_sort: TARGET_METHOD values_to_sort : ARRAY_INT_2D low_index : INT // (these will be updated to be low/high index high_index : INT // following addition of values and slight grammar // change) // - target postconditions: output from module sorted_values : INT_ARRAY Composition fitness sub-function Module fitness sub-function
Examples • Example 1.1: Code injection • Grammar specifies module only COMPOSITION( MODULE(bubble_sort, DOUBLE2INT(convert-me-to-int), incoming_array) )
Example • Example 1.2: Code Injection • Grammar allows all available statements COMPOSITION( EXPAND(FLATTEN(incoming_array)), MODULE(bubble_sort, DOUBLE2INT(convert-me-to-int), incoming_array ) ) ////////////////////////////////////////////// COMPOSITION( EXPAND(FLATTEN(incoming_array)), MODULE(bubble_sort, DOUBLE2INT(convert-me-to-int), EXPAND(FLATTEN(incoming_array)) ) )
Example Source post-condition: - 2D INT ARRAY • Example 1.2: Code Injection COMPOSITION( EXPAND(FLATTEN(incoming_array)), MODULE(bubble_sort, DOUBLE2INT(convert-me-to-int), incoming_array ) ) ////////////////////////////////////////////// COMPOSITION( EXPAND(FLATTEN(incoming_array)), MODULE(bubble_sort, DOUBLE2INT(convert-me-to-int), EXPAND(FLATTEN(incoming_array)) ) ) Target pre-conditions: - TARGET_METHOD - 2D INT ARRAY - INT - INT
Example Discussion • Things I am noticing with this example: • Output tends to converge to single subset of solutions with little variation • Either: • Pre- and post-conditions too constrained • Grammar too constrained • FLATTEN rule seems to take precedence when 2D array is encountered • Tree must then EXPAND back to 2D to satisfy conditions
WRAPPER Example • Work in progress • NWRAPPER (accepts n-children) COMPOSITION( <wrapper> ) <wrapper> ::= NWRAPPER( <statement_list>, <module_invocation>, <statement_list> )
WRAPPER Example COMPOSITION( NWRAPPER( EXPAND(FLATTEN(incoming_array)), MODULE(bubble_sort,convert-me-to-int), DOUBLE2INT(convert-me-to-int) ) ) ////////////////////////// COMPOSITION( NWRAPPER( EXPAND(FLATTEN(incoming_array)), MODULE(bubble_sort,num_cols), DOUBLE2INT(convert-me-to-int) ) )
Next Steps • Strengthen Wrapper fitness function • Implementing factory pattern to facilitate live variables • Abstract data type so that role transforms may be seamlessly applied to underlying value • Generic type required to pass values between nodes in GP tree • For example: • var = 5; | var = factory.create(5,Int); • var = (int)var; | var = factory.xform(var,Int); • var = (float)var; | var = factory.xform(var,Float); • var = var.toString(); | var = factory.xform(var,String);