Skip to content

Commit

Permalink
AGAIN 17
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Apr 20, 2023
1 parent a43b8bd commit 9c48946
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 510 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
uast,!,
setup_call_cleanup(open('arc-dsl/constants.py',read,In1,[]),read_python(In1),close(In1)),
!.
%read_michod_test:- read_sols,read_dsl.
read_michod_test:- read_sols,read_dsl.

uast:- uast_test.
uast_test:-setup_call_cleanup(open('arc-dsl/dsl.py.uast',read,In3,[]),read_uast_python(In3),close(In3)).
Expand Down
183 changes: 42 additions & 141 deletions packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc.unused
Original file line number Diff line number Diff line change
Expand Up @@ -483,147 +483,48 @@ all_ogs(IO,In,Out,Set):- %member(R,[strict,loose]),
*/
%maybe_ogs(R,In,Out):- find_ogs(X,Y,In,Out)*->R=strict;(ogs_11(X,Y,In,Out),R=loose).

:- arc_history(test_what_unique).
test_what_unique:- get_current_test(TestID), what_unique(TestID,n=0,n>10).


:- arc_history((get_current_test(TestID),what_unique(TestID,n=0,n>10))).
get_new_uniq_dict(Dict):-
ArgDict = _{sharedWith:_SharedWith,object:_Obj,trait:_Trait,groupSizeMask:_GroupSizeMask,
actualGroupSize:_ActualGroupSize,countMask:_CountMask,
actualCount:_ActualCount,otherL:_OtherL,slistL:_ListL,
setL:_SetL,others:_TraitCountSets,how:_How,group:_Group},
(var(Dict)->Dict=ArgDict ; Dict >:< ArgDict).

is_fti_step(most_unique).
most_unique(symmetry_type,VM):-
List = VM.objs,
last(List,Obj),
set(VM.solution)= Obj.




what_unique:- get_current_test(TestID),what_unique(TestID).

what_unique(TestID):-
get_vm(VM),
((VM.id \= (TestID > _ * _)), ndividuator),
get_vm(VM2), explain_uniqueness(VM2.objs).

what_unique(TestID,Dict):- is_vm_map(Dict),!,what_unique_dict(TestID,Dict).
what_unique(TestID,Obj):- get_current_test(TestID),select_group(TestID,Group,_How), member(Obj,Group), must_det_ll(what_unique(TestID,Obj,Group)).
what_unique(TestID,Obj,Group):- (is_group(Group);is_object(Obj)),!,what_unique_obj(TestID,Obj,Group).
what_unique(TestID,CountMask,GroupSizeMask):-
get_new_uniq_dict(Dict),
Dict.groupSizeMask = GroupSizeMask,
Dict.countMask = CountMask,!,
what_unique_dict(TestID,Dict),
report_unique(Dict).

what_unique_obj:- get_current_test(TestID),what_unique_obj(TestID,_,_).
what_unique_obj(TestID,Obj,Group):-
get_new_uniq_dict(Dict),
Dict.group = Group,
Dict.object = Obj,
what_unique_dict(TestID,Dict),
report_unique(Dict).

/*what_unique(TestID,CountMask,GroupSizeMask):-
what_unique(TestID,SharedWith,Obj,Trait,GroupSizeMask,ActualGroupSize,CountMask,ActualCount,OtherL,ListL,SetL,TraitCounts,How),
report_unique(SharedWith,Obj,Trait,GroupSizeMask,ActualGroupSize,CountMask,ActualCount,OtherL,ListL,SetL,TraitCounts,How).
*/
report_unique(Dict):- var(Dict),get_new_uniq_dict(Dict),!,report_unique(Dict).
report_unique(Dict):- var(Dict.actualCount),!,get_current_test(TestID), what_unique_dict(TestID,Dict),report_unique(Dict).
report_unique(Dict):-
must_det_ll((
ArgDict = _{sharedWith:SharedWith,object:Obj,trait:Trait,groupSizeMask:GroupSizeMask,
actualGroupSize:ActualGroupSize,countMask:CountMask,
actualCount:ActualCount,otherL:OtherL,listL:ListL,
setL:SetL,others:TraitCountSets,how:How,group:Group},
(var(Dict)->Dict=ArgDict ; Dict >:< ArgDict),
maplist_e(tersify,TraitCountSets,HTraitSetO),
maplist_e(tersify,SharedWith,SharedWithO),
maplist_e(tersify,Group,GroupO),
maplist_e(tersify,Obj,ObjO),
%(Obj\==[] -> ignore(print_grid(Obj)) ; true),
format('~N'), pp(what_unique(ObjO=[ActualCount/ActualGroupSize-Trait],sharedWith=SharedWithO,
setL/listL=SetL/ListL,others=HTraitSetO,how=How,
groupSizeMask=GroupSizeMask,group:GroupO,countMask=CountMask,otherL=OtherL)))).

maplist_e(P2,A,B):- is_list(A),!,mapgroup(P2,A,B).
maplist_e(P2,A,B):- call(P2,A,B).

:- style_check(-singleton).
%:- arc_history(what_unique(TestID,SharedWith,Obj,Trait,GroupSizeMask,ActualGroupSize,CountMask,ActualCount,OtherL,ListL,SetL,Others,_How)).
:- style_check(+singleton).


obj_exclude(Obj,Group,Others):- var(Obj),!,select(Obj,Group,Others).
obj_exclude(Obj,Group,Others):- select(O,Group,Others),(O==Obj *-> true; Group=Others).


what_unique_dict(TestID,Dict):-
ArgDict = _{sharedWith:SharedWith,object:Obj,trait:Trait,groupSizeMask:GroupSizeMask,
actualGroupSize:ActualGroupSize,countMask:CountMask,
actualCount:ActualCount,otherL:OtherL,listL:ListL,
setL:SetL,others:TraitCountSets,how:How,group:Group},
(var(Dict)->Dict=ArgDict ; Dict >:< ArgDict),
(var(Group)->(select_group(TestID,Group,How));true),
obj_exclude(Obj,Group,Others),
length_criteria(Group,GroupSizeMask),
length(Group,ActualGroupSize),
mapgroup(each_trait,[Obj|Others],[_-ObjT|TraitList]),
member(Trait,ObjT),
\+ too_non_unique(Trait),
\+ too_unique(Trait),
found_in_o(Trait,TraitList,SharedWith),
length_criteria(SharedWith,CountMask),
length(SharedWith,ActualCount),
freeze(B,\+ \+ (member(E,SharedWith), E==B)),
my_partition(=(B-_),TraitList,_Mine,NotMine),
length(NotMine,OtherL),
%dif(WTrait,Trait),
functor(Trait,F,A),functor(WTrait,F,A),
found_in_w(WTrait,NotMine,HTraitList),length(HTraitList,ListL),
sort_safe(HTraitList,HTraitSet),length(HTraitSet,SetL),
findall(C-HTrait,(member(HTrait,HTraitSet),found_in_w(HTrait,NotMine,LS),length(LS,C)),TraitCounts),
sort_safe(TraitCounts,TraitCountSets),
\+ filter_what_unique(TestID,SharedWith,Obj,Trait,GroupSizeMask,ActualGroupSize,CountMask,ActualCount,OtherL,ListL,SetL,How).


explain_uniqueness(GroupWhole):-
object_printables(GroupWhole,Group,GroupPP),
get_current_test(TestID),!,
forall(member(Obj,Group),
(dash_chars,
object_glyph(Obj,G), object_color_glyph_short(Obj,GC), object_grid(Obj,OG),
locally(nb_setval(color_index,[Obj|GroupPP]),print_side_by_side(GC,GroupPP,'explain_uniqueness',_,OG,G)),
dmsg(uobj=Obj),!,
forall(what_unique_obj(TestID,Obj,Group),true))),
dash_chars.


% touching vs each dir
% size2D



:- style_check(-singleton).
filter_what_unique(TestID,SharedWith,Obj,Trait,GroupSizeMask,ActualGroupSize,CountMask,ActualCount,OtherL,ListL,SetL,How):-
OtherL=<1.

filter_what_unique(TestID,SharedWith,Obj,Trait,GroupSizeMask,ActualGroupSize,CountMask,ActualCount,OtherL,ListL,SetL,How):-
ListL=SetL, SetL>1.


/*

With each type of example we can have...

values_all_same|values_all_dif
values_where_1_stand_otherwise
values_where_2_stand_otherwise

*/
accompany_change2(TestID,ExampleNum,[X1=P1O,X2=P2O,common=Intersect]):-
changing_props(TestID,X1,X2),
accompany_change(TestID,ExampleNum,X1,Props1,_NotProps1),
accompany_change(TestID,ExampleNum,X2,Props2,_NotProps2),
once((
intersection(Props1,Props2,Intersect,P1,P2),
include(has_other_val(Props2),P1,P1O),
include(has_other_val(Props1),P2,P2O))).

has_other_val(Props1,X2):- member(X1,Props1),other_val(X1,X2),!.

accompany_change(TestID,ExampleNum,P,Props,NotProps):-
var(TestID),!,ensure_test(TestID),
accompany_change(TestID,ExampleNum,P,Props,NotProps).
accompany_change(TestID,ExampleNum,P,Props,NotProps):-
var(ExampleNum),!,current_example_nums(TestID,ExampleNum),
accompany_change(TestID,ExampleNum,P,Props,NotProps).
accompany_change(TestID,ExampleNum,P,Props,NotProps):-
var(P),!,props_change(TestID,IO,P),
accompany_change(TestID,ExampleNum,P,Props,NotProps).

accompany_change(TestID,ExampleNum,P,Props,NotProps):-
once((counts_change(TestID,ExampleNum,_I_or_O,P,N1,N2), N1<N2)),!,
%no_repeats_var(Out),
once(( obj_group_gg(TestID,ExampleNum,_In,Out),
once((my_partition(has_prop(P),Out,HasPropsO,NotHasPropsO),
common_props(HasPropsO,Common), common_props(NotHasPropsO,NotCommon),
intersection(Common,NotCommon,_,Props1,NotProps))),
include(\=@=(P),Props1,Props),
Props\==[])).

accompany_change(TestID,ExampleNum,P,Props,NotProps):- fail,
counts_change(TestID,ExampleNum,_I_or_O,P,N1,N2), N1>N2,
once((
%obj_group_io(TestID,ExampleNum,in,In), my_partition(has_prop(P),In,HasPropsI,NotHasPropsI),
%obj_group_io(TestID,ExampleNum,out,Out),
objs_other_than_example(TestID,ExampleNum,out,Out),
my_partition(not_has_prop(P),Out,HasPropsO,NotHasPropsO),
%my_partition(not_has_prop(P),Others,HasPropsOthers,NotHasPropsOthers),
common_props(HasPropsO,Common),
common_props(NotHasPropsO,NotCommon),
intersection(Common,NotCommon,_,Props,NotProps),Props\==[])).

20 changes: 12 additions & 8 deletions packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc_boards.pl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@
clsbake:- nop(clsmake).

compile_and_save_test:- update_and_fail,fail.
compile_and_save_test:- get_pair_mode(entire_suite),!,clsbake, forall_count(all_arc_test_name(TestID),time(compile_and_save_test(TestID))).
compile_and_save_test:- get_pair_mode(entire_suite),!,clsbake,
forall_count(all_arc_test_name(TestID),time(compile_and_save_test(TestID))).
compile_and_save_test:- get_current_test(TestID),time(compile_and_save_test(TestID)),!,
detect_all_training_hints,!.

gen_gids:- u_dmsg(start(gen_gids)),forall(all_arc_test_name(TestID),gen_gids(TestID)),u_dmsg(end(gen_gids)).
gen_gids:- u_dmsg(start(gen_gids)),
forall(all_arc_test_name(TestID),gen_gids(TestID)),
u_dmsg(end(gen_gids)).
gen_gids(Mask):-
testid_name_num_io(Mask,TestID,Example,Num,IO),
ExampleNum = Example+Num,!,
Expand Down Expand Up @@ -303,17 +306,17 @@

training_only_examples(ExampleNum):- ignore(ExampleNum=(trn+_)).

detect_test_hints1:- clsbake, get_current_test(TestID),detect_test_hints1(TestID).
detect_test_hints1(TestID):-
some_current_example_num(ExampleNum), training_only_examples(ExampleNum),
forall(kaggle_arc(TestID,ExampleNum,In,Out),detect_pair_hints(TestID,ExampleNum,In,Out)).


color_subst([],[],[]):-!.
color_subst([O|OSC],[I|ISC],[O-I|O2I]):-
color_subst(OSC,ISC,O2I).
color_subst(_OSC,_ISC,[]):-!.

detect_pair_hints:- clsbake, get_current_test(TestID),detect_pair_hints(TestID).
detect_pair_hints(TestID):-
some_current_example_num(ExampleNum), training_only_examples(ExampleNum),
forall(kaggle_arc(TestID,ExampleNum,In,Out),detect_pair_hints(TestID,ExampleNum,In,Out)).
detect_pair_hints(TestID,ExampleNum,In,Out):-
ensure_test(TestID),
must_det_ll((
Expand Down Expand Up @@ -1109,15 +1112,16 @@

save_the_alt_grids(TestID):-
forall(ensure_test(TestID),
forall(kaggle_arc(TestID,ExampleNum,I,O),
once(save_the_alt_grids(TestID,ExampleNum,[],I,O)))),!.
forall(kaggle_arc(TestID,ExampleNum,_,_),
once(save_the_alt_grids(TestID,ExampleNum)))).

save_the_alt_grids(TestID,ExampleNum):-
arc_test_property(TestID,ExampleNum,has_blank_alt_grid,_),!.
save_the_alt_grids(TestID,ExampleNum):-
forall(kaggle_arc(TestID,ExampleNum,I,O),
once(save_the_alt_grids(TestID,ExampleNum,[],I,O))),!.

save_the_alt_grids(TestID,ExampleNum,_,_,_):-arc_test_property(TestID,ExampleNum,ori(_),_),!.
save_the_alt_grids(TestID,ExampleNum,_,_,_):- arc_test_property(TestID,ExampleNum,iro(_),_),!.
save_the_alt_grids(TestID,ExampleNum,XForms,In,Out):- %same_sizes(In,Out),
!,
Expand Down
41 changes: 29 additions & 12 deletions packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc_grid_size.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,43 @@
:- dynamic(muarc_tmp:grid_size_prediction/4).


test_grid_size_prediction:- forall_count(all_arc_test_name(TestID), test_grid_sizes(TestID)).
store_grid_size_predictions:- forall_count(all_arc_test_name(TestID), test_grid_sizes(TestID)).
test_grid_size_prediction:- forall_count(all_arc_test_name(TestID), predict_grid_size(TestID)).
store_grid_size_predictions:- forall_count(all_arc_test_name(TestID), predict_grid_size(TestID)).

test_grid_sizes(TestID):-
predict_grid_size(TestID):-
must_det_ll((
ensure_test(TestID),
retractall(muarc_tmp:learned_grid_size(TestID,_)),
retractall(muarc_tmp:grid_size_prediction(TestID,_,_,_)),
findall(R,(kaggle_arc(TestID,(trn+_),In,Out),learn_grid_size(In,Out,R),nop((writeq(R),write('.\n')))),L),
asserta_if_new(muarc_tmp:learned_grid_size(TestID,L)),
forall(kaggle_arc(TestID,tst+_,In,Out),predict_grid_size(TestID,In,Out)).
forall(kaggle_arc(TestID,tst+_,In,Out),
ignore((predict_grid_size(TestID,In,Out)))))).

learn_grid_size(In,Out,R):-
grid_size(In,IH,IV),grid_size(Out,OH,OV),
locally(nb_setval(allow_unused_proportion,t),
proportional(size2D(IH,IV),size2D(OH,OV),R)).
%proportional_size2D(IH,IV,OH,OV,R).
predict_grid_size(TestID,In,Out):-
grid_size(In,IH,IV),grid_size(Out,OH,OV),

predict_grid_size_now(TestID,In,PH,PV):-
grid_size(In,IH,IV),
muarc_tmp:learned_grid_size(TestID,List),
% predsort_on(better_grid_size_prop,List,SList),
predict_grid_size(List,IH,IV,PH,PV).

predict_grid_size(TestID,In,Out):-
predict_grid_size_now(TestID,In,PH,PV),
(var(Out)->make_grid(PH,PV,Out);true),!.

test_predict_grid_size(TestID,In,Out):-
(nonvar(In)->grid_size(In,IH,IV);true),
(nonvar(Out)->grid_size(Out,OH,OV);true),
wots(SS,((
dash_chars, dash_chars, write(test_grid_sizes(TestID)), write('\n'),
predict_grid_size(List,IH,IV,PH,PV),
dash_chars, dash_chars, write(test_predict_grid_size(TestID)), write('\n'),
predict_grid_size_now(TestID,In,PH,PV),
((PH=OH,PV=OV) -> C = green ; C = red),
color_print(C,predict_grid_size(TestID,in(size2D(IH,IV)),predicted(size2D(PH,PV)),actual(size2D(OH,OV))))))),!,
color_print(C,test_predict_grid_size(TestID,in(size2D(IH,IV)),predicted(size2D(PH,PV)),actual(size2D(OH,OV))))))),!,
(C==green
-> asserta(muarc_tmp:grid_size_prediction(TestID,In,PH,PV))
;(nop(print_test(TestID)), write(SS),assert_test_suite(failed_predict_grid_size,TestID),!,fail)).
Expand All @@ -53,8 +65,13 @@
%my_maplist(ppnl,List),dash_chars,
my_maplist(ppnl,ListA),dash_chars,
my_maplist(ppnl,NewInfo),dash_chars,
predict_grid_size1(ListA,NewInfo,IH,IV,PH,PV).
predict_grid_size(_List,IH,IV,IH,IV).
predict_grid_size_now(ListA,NewInfo,IH,IV,PH,PV),!.

predict_grid_size_now(ListA,NewInfo,IH,IV,PH,PV):-
predict_grid_size1(ListA,NewInfo,IH,IV,PH,PV),
pp(predict_grid_size(IH,IV,PH,PV)),!.
predict_grid_size_now(_,_,IH,IV,PH,PV):- PH=IH,PV=IV,
pp(predict_grid_size(IH,IV)).

better_grid_size_prop(_,1).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:- discontiguous individuals_from_pair/9.


i_pair(WasROptions,GridIn,GridOut):- WasROptions==complete,
i_pair(WasROptions,GridIn,GridOut):- fail, WasROptions==complete, % TODO unfail this
catch((must_det_ll((
check_for_refreshness,
((var(GridIn);var(GridOut))-> current_pair_io(GridIn,GridOut) ; true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1310,13 +1310,13 @@
sub_term(E,Obj),shall_count_as_same(Pre,E),ignore(Pre=E),do_rule(VM,Pre,Post,Obj,NewObj),!.
maybe_rule(_,_,_,Obj,Obj).

do_rule(_VM,Pre,Post,Obj,NewObj):-
do_rule(VM,Pre,Post,Obj,NewObj):-
object_grid(Obj,GPs),
obj_call(Post,GPs,GPsO),!,
globalpoints_include_bg(GPsO,LPoints),
loc2D(Obj,OX,OY),
offset_points(OX,OY,LPoints,NewGPoints),
must_det_ll(rebuild_from_globalpoints(Obj,NewGPoints,NewObj)),
must_det_ll(rebuild_from_globalpoints(VM,Obj,NewGPoints,NewObj)),
print_side_by_side(rule(Pre,Post),[Obj],[NewObj]),!,
Obj\=@=NewObj,!.
do_rule(_VM,Pre,Post,Obj,NewObj):-
Expand Down Expand Up @@ -2661,11 +2661,11 @@
mono_shaped( FG,_BG,Cell,NewCell):- is_fg_color(Cell),!,nop(decl_many_fg_colors(_NewCell)),NewCell=FG.
mono_shaped(_,_,Cell,Cell).

recolor_object(Recolors,Old,New):-
recolor_object(VM,Recolors,Old,New):-
%globalpoints_include_bg(Grid,Recolors),
globalpoints_include_bg(Old,GPoints),
my_maplist(recolor_point(Recolors),GPoints,NewGPoints),
must_det_ll(rebuild_from_globalpoints(Old,NewGPoints,New)),!.
must_det_ll(rebuild_from_globalpoints(VM,Old,NewGPoints,New)),!.

recolor_point(Recolors,_-Point,C-Point):-
must_det_l((hv_point(H,V,Point), hv_c_value(Recolors,C,H,V))).
Expand Down Expand Up @@ -2726,7 +2726,7 @@
with_other_grid(Other,individuate2(_,Shape,GOID,NewGrid,FoundObjs)),
set_vm(VMS),
globalpoints_include_bg(VM.start_grid,Recolors),
my_maplist(recolor_object(Recolors),FoundObjs,ReColored),
my_maplist(recolor_object(VM,Recolors),FoundObjs,ReColored),
learn_hybrid_shape(ReColored),
remLOPoints(VM,ReColored),
addObjects(VM,ReColored))),!.
Expand Down Expand Up @@ -3386,7 +3386,7 @@
individuate(Subtraction,NewGrid,FoundObjs),
set_vm(VMS),
ReColored = FoundObjs,
%globalpoints_include_bg(VM.start_grid,Recolors), my_maplist(recolor_object(Recolors),FoundObjs,ReColored),
%globalpoints_include_bg(VM.start_grid,Recolors), my_maplist(recolor_object(VM,Recolors),FoundObjs,ReColored),
print_grid(fg_abtractions(GOID),NewGrid),
print_ss(ReColored),
remLOPoints(VM,ReColored),
Expand Down
Loading

0 comments on commit 9c48946

Please sign in to comment.