def check_on_previous(): """ Test a hypothesis on all previous examples """ t = gl.current_hypothesis new = t['new'] specialized = t['specialized'] retained = ['retained'] x = utils.merge_all_lists([new,specialized,retained]) cwd = os.getcwd() testpath = os.path.join(os.path.dirname(cwd),'runtime','test_file.lp') testfile = open(testpath, 'w') for y in x: testfile.write(y.as_string_with_var_types) testfile.write('\n\n') testfile.write('#hide.') testfile.close() import asp allok = False for i in gl.seen_examples: utils.get_example(i) if not asp.test_hypothesis(debug=True): print('unsatisfiable at example %s')%(str(i)) allok = True if allok: print('Hypothesis consistent with all past examples') os.remove(testfile)
def check_on_previous(): """ Test a hypothesis on all previous examples """ t = gl.current_hypothesis new = t['new'] specialized = t['specialized'] retained = ['retained'] x = utils.merge_all_lists([new, specialized, retained]) cwd = os.getcwd() testpath = os.path.join(os.path.dirname(cwd), 'runtime', 'test_file.lp') testfile = open(testpath, 'w') for y in x: testfile.write(y.as_string_with_var_types) testfile.write('\n\n') testfile.write('#hide.') testfile.close() import asp allok = False for i in gl.seen_examples: utils.get_example(i) if not asp.test_hypothesis(debug=True): print('unsatisfiable at example %s') % (str(i)) allok = True if allok: print('Hypothesis consistent with all past examples') os.remove(testfile)
def learn(**kwargs): u.clear_prior() found_new_clauses = False hs,scs,cls,incsolve = False,False,False,False (step,up_to_exmpl) = utils.get_time_step(gl) time_interval = (i for i in range(0,up_to_exmpl*step+1,step) ) (newclauses,retained,specialized) = ([],[],[]) if 'heuristic_search' in kwargs and kwargs['heuristic_search'] : hs = True if 'set_cover_search' in kwargs and kwargs['set_cover_search'] : scs = True if 'clause_level_search' in kwargs and kwargs['clause_level_search'] : cls = True if 'incremental_solve' in kwargs and kwargs['incremental_solve'] : incsolve = True u.post_exmpl_constraints(heuristic_search=hs,set_cover_search=scs,clause_level_search=cls) """ for i in range(1,600): if utils.get_example(i): gl.current_example = i #if not asp.test_hypothesis(): print(i) asp.show_negs() print('here') """ #for i in time_interval: #for i in range(1,100000): for i in range(1,1000000): #for i in (110,120): #i = 250 #print(i) if i == 1672: stop = 'stop' if utils.get_example(i): gl.current_example = i if not asp.test_hypothesis(): print(i) print('revising') (newclauses,retained,specialized) = \ u.revise(is_new_example=True, debug=False, newcl=newclauses, refcl=specialized, retcl=retained,heuristic_search=hs, set_cover_search=scs, clause_level_search=cls, incremental_solve=incsolve) found_new_clauses = newclauses != [] else: print(i) print('correct') if gl.current_example_object.has_positives: u.update_support([newclauses, retained, specialized], simple_update=True) if found_new_clauses: for j in gl.seen_examples: utils.get_example(j) if not asp.test_hypothesis(): (newclauses,retained,specialized) = \ u.revise(is_new_example=False, debug=False, newcl=newclauses, refcl=specialized, retcl=retained,heuristic_search=hs, set_cover_search=scs, clause_level_search=cls, incremental_solve=incsolve) else: pass u.tideup(newclauses,retained,specialized, kernel='clear',delta='clear', usedict='clear',updatexmpl=i) found_new_clauses = False
def learn(**kwargs): u.clear_prior() found_new_clauses = False hs, scs, cls, incsolve = False, False, False, False (step, up_to_exmpl) = utils.get_time_step(gl) time_interval = (i for i in range(0, up_to_exmpl * step + 1, step)) (newclauses, retained, specialized) = ([], [], []) if 'heuristic_search' in kwargs and kwargs['heuristic_search']: hs = True if 'set_cover_search' in kwargs and kwargs['set_cover_search']: scs = True if 'clause_level_search' in kwargs and kwargs['clause_level_search']: cls = True if 'incremental_solve' in kwargs and kwargs['incremental_solve']: incsolve = True u.post_exmpl_constraints(heuristic_search=hs, set_cover_search=scs, clause_level_search=cls) """ for i in range(1,600): if utils.get_example(i): gl.current_example = i #if not asp.test_hypothesis(): print(i) asp.show_negs() print('here') """ #for i in time_interval: #for i in range(1,100000): for i in range(1, 1000000): #for i in (110,120): #i = 250 #print(i) if i == 1672: stop = 'stop' if utils.get_example(i): gl.current_example = i if not asp.test_hypothesis(): print(i) print('revising') (newclauses,retained,specialized) = \ u.revise(is_new_example=True, debug=False, newcl=newclauses, refcl=specialized, retcl=retained,heuristic_search=hs, set_cover_search=scs, clause_level_search=cls, incremental_solve=incsolve) found_new_clauses = newclauses != [] else: print(i) print('correct') if gl.current_example_object.has_positives: u.update_support([newclauses, retained, specialized], simple_update=True) if found_new_clauses: for j in gl.seen_examples: utils.get_example(j) if not asp.test_hypothesis(): (newclauses,retained,specialized) = \ u.revise(is_new_example=False, debug=False, newcl=newclauses, refcl=specialized, retcl=retained,heuristic_search=hs, set_cover_search=scs, clause_level_search=cls, incremental_solve=incsolve) else: pass u.tideup(newclauses, retained, specialized, kernel='clear', delta='clear', usedict='clear', updatexmpl=i) found_new_clauses = False