def test_correct_solution_count_with_repeated_color_and_text_factors_and_constrained(design): crossing = [[color, text], [mix, text]] constraints = [ at_most_k_in_a_row(1, (repeated_color_factor, get_level_from_name(repeated_color_factor, "yes"))), at_most_k_in_a_row(1, (repeated_text_factor, get_level_from_name(repeated_text_factor, "yes"))) ] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 96
def test_that_design_is_correctly_constrained(design): crossing = [color, motion, task] k = 2 constraints = [ at_most_k_in_a_row(k, task_transition), at_most_k_in_a_row(k, response_transition) ] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 100, "Design: %s" % str( list(map(lambda f: f.factor_name, design))) for c in constraints: assert_atmostkinarow(c, experiments)
def test_correct_solution_count_with_congruence_factor_and_constrained(design): crossing = [[color, text], [text, mix]] constraints = [at_most_k_in_a_row(1, (con_factor, get_level_from_name(con_factor, "con")))] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 48
def test_correct_solution_count_when_constrained(design): crossing = [direction, congruent_factor] constraints = [at_most_k_in_a_row(1, congruent_factor)] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 500) assert len(experiments) == 128
def test_correct_solution_count_with_repeated_color_factor_and_constrained(design): crossing = [[color, text], [mix, text]] constraints = [at_most_k_in_a_row(1, (repeated_color_factor, get_level_from_name(repeated_color_factor, "yes")))] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) # With only two colors, there can never be two color repetitons anyways, # so the total should still be the same. assert len(experiments) == 96
def test_correct_solution_count_when_bookends_must_not_match_each_other( design): crossing = [color, text] # Require both bookends to be incongruent with each other. constraints = [at_most_k_in_a_row(1, congruent_bookend)] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 16
def test_correct_solution_count_when_transition_in_crossing_and_constrained( design): crossing = [direction, repeated_color_factor] constraints = [ at_most_k_in_a_row(1, (color, get_level_from_name(color, "red"))) ] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 32
def test_correct_solution_count_with_congruence_factor_and_constrained_cnf(design=[color, text, mix, con_factor]): crossing = [[color, text], [text, mix]] constraints = [at_most_k_in_a_row(1, (con_factor, get_level_from_name(con_factor, "con")))] block = multiple_cross_block(design, crossing, constraints) cnf = build_cnf(block) # with open(path_to_cnf_files+'/test_correct_solution_count_with_congruence_factor_and_constrained.cnf', 'w') as f: # f.write(cnf.as_unigen_string()) with open(path_to_cnf_files+'/test_correct_solution_count_with_congruence_factor_and_constrained.cnf', 'r') as f: old_cnf = f.read() assert old_cnf == cnf.as_unigen_string()
def test_correct_solution_count_when_bookends_must_not_match_each_other_cnf( design=[color, text, congruent_bookend]): crossing = [color, text] # Require both bookends to be incongruent with each other. constraints = [at_most_k_in_a_row(1, congruent_bookend)] block = fully_cross_block(design, crossing, constraints) cnf = build_cnf(block) # with open(path_to_cnf_files+'/test_correct_solution_count_when_bookends_must_not_match_each_other.cnf', 'w') as f: # f.write(cnf.as_unigen_string()) with open( path_to_cnf_files + '/test_correct_solution_count_when_bookends_must_not_match_each_other.cnf', 'r') as f: old_cnf = f.read() assert old_cnf == cnf.as_unigen_string()
def test_correct_solution_count_when_transition_in_crossing_and_constrained_cnf( design=[direction, color, repeated_color_factor]): crossing = [direction, repeated_color_factor] constraints = [ at_most_k_in_a_row(1, (color, get_level_from_name(color, "red"))) ] block = fully_cross_block(design, crossing, constraints) cnf = build_cnf(block) # with open(path_to_cnf_files+'/test_correct_solution_count_when_transition_in_crossing_and_constrained.cnf', 'w') as f: # f.write(cnf.as_unigen_string()) with open( path_to_cnf_files + '/test_correct_solution_count_when_transition_in_crossing_and_constrained.cnf', 'r') as f: old_cnf = f.read() assert old_cnf == cnf.as_unigen_string()
response transition (repetition, switch). dependent factor of correct response: if left-left then task transition = repetition if right-right then task transition = repetition . if left-right then task transition = switch if right-left then task transition = switch """ def response_repeat(responses): return responses[0] == responses[1] def response_switch(responses): return not response_repeat(responses) resp_transition = factor("resp_transition", [ derived_level("repeat", transition(response_repeat, [response])), derived_level("switch", transition(response_switch, [response])) ]) k = 7 constraints = [at_most_k_in_a_row(k, task_transition), at_most_k_in_a_row(k, resp_transition)] design = [color, motion, task, congruency, response, task_transition, resp_transition] crossing = [color, motion, task] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 5) print_experiments(block, experiments)
def response_repeat(responses): return responses[0] == responses[1] def response_switch(responses): return not response_repeat(responses) resp_transition = Factor("resp_transition", [ derived_level("repeat", Transition(response_repeat, [response])), derived_level("switch", Transition(response_switch, [response])) ]) k = 7 constraints = [ at_most_k_in_a_row(k, task_transition), at_most_k_in_a_row(k, resp_transition) ] design = [ color, motion, task, congruency, response, task_transition, resp_transition ] crossing = [color, motion, task] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 5) print_experiments(block, experiments)
def congruent(color, motion): return ((color == "red") and (motion == "up")) or ((color == "blue") and (motion == "down")) def some_func(color0, text0, color1, text1, color2): return None derived_level("con", within_trial(op.eq, [color, text])) derived_level("con", transition(congruent, [color, motion])) #derived_level("con", window(some_func, [[color, text], [color, text], [color]], 2, stride=2)) k = 1 #TODO this value should change to the intended value from the writing of the original code at_most_k_in_a_row(k, conLevel) Balance(congruentFactor) # congruent : 3 (red, red) (g, g) (b,b) # incongruent : 6 # # 2 of each congruent --> 6 congruent # matches the 6 incongruent # without rep should be a keyword # balance which figures out the 2-to-1 ratio weighting = Ratio([WithoutRep(2, conLevel), WithoutRep(1, incLevel)]) # text = Factor "text" [Level "red", Level "blue", Level "green"] # color = Factor "color" [Level "red", Level "blue", Level "green"]