Skip to content

Commit

Permalink
% TODO Directional shooter
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed May 2, 2023
1 parent c44756c commit 0791758
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -871,12 +871,12 @@

obj_group_pair(TestID,ExampleNum,InC,OutC):-
current_example_nums(TestID,ExampleNum),
no_repeats_var(OutC), % set_example_num(ExampleNum),
obj_group5(TestID,ExampleNum,in,HowIn,InC), InC\==[], length(InC,L),
%no_repeats_var(OutC), % set_example_num(ExampleNum),
once((obj_group5(TestID,ExampleNum,in,HowIn,InC), InC\==[], length(InC,L),

(((obj_group5(TestID,ExampleNum,out,HowOut,OOut),length(OOut,L),save_how_io(TestID,HowIn,HowOut)))
;obj_group5(TestID,ExampleNum,out,_,OOut)),
OutC = OOut.
OutC = OOut)).

objs_other_than_example(TestID,ExampleNum,InOut,Others):-
findall(O,(current_example_nums(TestID,OExampleNum),
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@
remove_background_only_object(InCB,InC),remove_background_only_object(OutCB,OutC),
%pp(InC),
print_side_by_side(green,InC,after_rm_bg(ROptions,ID1),_,OutC,objs(ID2)),
nop(show_individuated_pair_cont(PairName,ROptions,GridIn,GridOut,InC,OutC))))))).
show_individuated_pair_cont(PairName,ROptions,GridIn,GridOut,InC,OutC)))))).

show_individuated_pair_cont(PairName,ROptions,GridIn,GridOut,InC,OutC):-
must_det_ll((
show_indivs_side_by_side(inputs,InC),
show_indivs_side_by_side(outputs,OutC),!,
nop(show_individuated_pair_cont2(PairName,ROptions,GridIn,GridOut,InC,OutC)),!.
show_individuated_pair_cont2(PairName,ROptions,GridIn,GridOut,InC,OutC))),!.

show_individuated_pair_cont2(PairName,ROptions,_GridIn,GridOut,InC,OutC):-
must_det_ll((
Expand All @@ -114,7 +115,7 @@
%when_in_html(if_wants_output_for(sort_some_relations,sort_some_relations(InC,OutC))),

% (sub_var(trn,ID1)->show_object_dependancy(TestID,ExampleNum,InC,OutC);show_object_dependancy(TestID)),
if_t( fail,((
if_t( true,((


w_section(learn_group_mapping, if_t(sub_var(trn,ID1), learn_group_mapping(InCR,OutCR))),
Expand Down
131 changes: 131 additions & 0 deletions packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc_howdiff.pl
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,134 @@

distance(A,B,R):- loc2D(A,X1,Y1),loc2D(B,X2,Y2), R is sqrt(abs(X1-X2)*abs(Y1-Y2)).

sort_by_closeness(In,Objs,List):- sorted_by_closeness(In,_Sorted,Objs,List).
:- dynamic(saved_sorted_by_closeness/4).
sorted_by_closeness(In,Sorted,Objs,List):- once(var(In);var(Objs)),!,enum_in_objs(In,Objs), sorted_by_closeness(In,Sorted,Objs,List),List\==[].
sorted_by_closeness(In,Sorted,Objs,List):- var(Sorted), my_maplist(obj_to_oid,Objs,OIDS), sort_safe(OIDS,Sorted),!,sorted_by_closeness(In,Sorted,Objs,List).
sorted_by_closeness(In,Sorted,Objs,List):- saved_sorted_by_closeness(In,Sorted,Objs,List),!.
sorted_by_closeness(In,Sorted,Objs,List):-
sort_by_jaccard(In,_,Objs,List),
asserta(saved_sorted_by_closeness(In,Sorted,Objs,List)),!.



%find_prox_mappings(A,Candidates,Objs):- sort_by_jaccard(A,Candidates,Objs).
sort_by_jaccard(A,Candidates,Objs):- bonus_sort_by_jaccard([],A,sort_by_jaccard,Candidates,Objs).

find_prox_mappings(A,GroupID,Candidates,Objs):- sort_by_jaccard(A,GroupID,Candidates,Objs).
sort_by_jaccard(A,GroupID,Candidates,Objs):- bonus_sort_by_jaccard([],A,GroupID,Candidates,Objs).

bonus_sort_by_jaccard(Bonus,A,Candidates,Objs):-
bonus_sort_by_jaccard(Bonus,A,sort_by_jaccard,Candidates,Objs).

find_prox_mappings(Bonus,A,GroupID,Candidates,Objs):- bonus_sort_by_jaccard(Bonus,A,GroupID,Candidates,Objs).

points_by_distance_to_center(I,GGP):- center2D(I,X,Y), globalpoints(I,GP), sort_on(dist_to(X,Y),GP,GGP).

dist_to(X1,Y1,HVP,Dist):- center2D(HVP,X2,Y2),dist(X1,Y1,X2,Y2,Dist).
dist_to(P1,P2,Dist):- center2D(P1,X1,Y1), center2D(P2,X2,Y2),dist(X1,Y1,X2,Y2,Dist).


sort_by_distance(Bonus,A,GroupID,Candidates,Objs):-
center2D(A,X1,Y1),
globalpoints(A,AP),
maplist(distance(A,AP,X1,Y1),Candidates,Results),
sort(Results,SortedR),sort(SortedR,Sorted),
tie_break_sbd(Bonus,A,GroupID,Sorted,Objs).

tie_break_sbd(Bonus,A,GroupID,[W1,W2|Sorted],[S1,S2|Sorted]):-
arg(1,W1,W1a),arg(1,W2,W2a), arg(2,W2,W1b),arg(2,W2,W2b), W1a=:=W2a,W1b=:=W2b,
bonus_sort_by_jaccard0(Bonus,A,GroupID,[W1,W2],[S1,S2]),!.
tie_break_sbd(_,_,_,Sorted,Sorted).


dist(X1,Y1,X2,Y2,Dist):-
DiffX is X1 - X2,
DiffY is Y1 - Y2,
Dist is sqrt(DiffX * DiffX + DiffY * DiffY).

is_adjacent_same_color(R1,R2,0):- globalpoints(R1,CP1),globalpoints(R2,CP2),!,
member(C-P,CP1),member(C-P,CP2).

% TODO Directional shooter
is_adjacent_same_color(R1,R2,1):- globalpoints(R1,CP1),globalpoints(R2,CP2),!,
member(C-P1,CP1), member(C-P2,CP2),
is_adjacent_point(P1,Dir,P2), \+ is_diag(Dir),!.
is_adjacent_same_color(R1,R2,2):- globalpoints(R1,CP1),globalpoints(R2,CP2),!,
member(C-P1,CP1), member(C-P2,CP2),
is_adjacent_point(P1,Dir,PM), is_adjacent_point(PM,Dir,P2), \+ is_diag(Dir),!.

is_adjacent_same_color(R1,R2,2):- globalpoints(R1,CP1),globalpoints(R2,CP2),!,
member(C-P1,CP1), member(C-P2,CP2),
is_adjacent_point(P1,Dir,P2), is_diag(Dir),!.

distance(A,_AP,_X1,_Y1,B,Res):- A=@=B,!, Res=inf.
distance(_A,AP,_X1,_Y1,B,Res):-
must_det_ll((
Res = dist(Close,R,B),
%center2D(B,X2,Y2),
%dist(X1,Y1,X2,Y2,R),
R = 1,
globalpoints(B,BP),
maplist(is_adjacent_closeness(AP),BP,N),
sumlist(N,Sum),
Close is R*Sum)).

is_adjacent_closeness(AP,B,Sum):- maplist(is_adjacent_close(B),AP,N), sumlist(N,Sum).

is_adjacent_close(A,B,Diff):- is_adjacent_point(A,Dir,B),!, (\+ is_diag(Dir) -> Diff = -2 ; Diff = -1).
is_adjacent_close(A,B,Diff):- center2D(A,X1,Y1),center2D(B,X2,Y2), dist(X1,Y1,X2,Y2,Dist),Diff is Dist+1.


bonus_sort_by_jaccard(_,_,_,[Obj],[Obj]):-!.
bonus_sort_by_jaccard(Bonus,A,GroupID,Candidates,Objs):- \+ \+ member(A,Candidates),!,
sort_by_distance(Bonus,A,GroupID,Candidates,Objs).
bonus_sort_by_jaccard(Bonus,A,GroupID,Candidates,Objs):- bonus_sort_by_jaccard0(Bonus,A,GroupID,Candidates,Objs).

simularity(B,A,Number):-
obj_grp_atomslist(simularity,B,PB,PBP),
obj_grp_atomslist(simularity,A,PA,PAP),
memo_op(PAP,PBP,O,Joins,_J,NJ,JO),
ord(NJ/O+JO+Joins,[PA,A],[PB,B],B) = Number.


bonus_sort_by_jaccard0(Bonus,A,GroupID,Candidates,ObjsO):-
must_det_ll((
obj_grp_atomslist(GroupID,A,PA,PAP0),
obj_atoms(Bonus,BonusAtoms),
append(PAP0,BonusAtoms,PAP),
(ord((NJ/O+JO+Joins),[PA,A],[PB,B],B) = Why),
!,
findall(Why,
(member(B,Candidates),
B\==A,
\+ is_whole_grid(B),
obj_grp_atomslist(GroupID,B,PB,PBP),
% PA\==PB,
memo_op(PAP,PBP,O,Joins,_J,NJ,JO)),
% maybe_allow_pair(PA,PB), allow_pair(PA,PB),
Pairs),
sort_safe(Pairs,RPairs),
%list_upto(3,RPairs,Some),
my_maplist(arg(4),RPairs,Objs))),!,
Objs=ObjsO.


memo_op(PAP,PBP,O,Joins,J,NJ,JO):- PAP@>PBP->memo_op_1(PBP,PAP,O,Joins,J,NJ,JO);memo_op_1(PAP,PBP,O,Joins,J,NJ,JO).

:- abolish(memo_op_then/7).
:- dynamic(memo_op_then/7).
memo_op_1(PAP,PBP,O,Joins,J,NJ,JO):- memo_op_then(PAP,PBP,O,Joins,J,NJ,JO),!.
memo_op_1(PAP,PBP,O,Joins,J,NJ,JO):- memo_op_now(PAP,PBP,O,Joins,J,NJ,JO), asserta(memo_op_then(PAP,PBP,O,Joins,J,NJ,JO)),!.

memo_op_now(PAP,PBP,O,Joins,J,NJ,JO):-
intersection(PAP,PBP,Joins,OtherA,OtherB),!,
%append([OtherA,OtherB],Other),
length(Joins,J),length(OtherA,OA),length(OtherB,OB),
O is OA+OB,
NJ is -J,
JO is - rationalize(J/(O+1)),!.

prox_mappings(TITLE,AG,BG,_BGG,APA):-
ignore((
member(E,APA),E=obj(_),!,
Expand Down Expand Up @@ -1892,3 +2020,6 @@

:- include(kaggle_arc_footer).




57 changes: 0 additions & 57 deletions packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc_learning.pl
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@
learn_rule_in_out(Mode,I,O):-
arc_assert(need_save_rule1(Mode,"INPUT <--> OUTPUT",I,O)).

sort_by_closeness(In,Objs,List):- sorted_by_closeness(In,_Sorted,Objs,List).

enum_in_objs(In,Objs):- nonvar(In),nonvar(Objs),!.
enum_in_objs(In,Objs):- var(In),see_object_atomslist(_,In,_,_),enum_in_objs(In,Objs).
%enum_in_objs(In,Objs):- is_list(Objs),var(In),select(In,Objs,Rest),Rest\==[],!, enum_in_objs(In,Objs).
Expand All @@ -568,63 +566,8 @@
enum_in_objs(In,Objs):- var(Objs),nonvar(In),in_to_out(IO_DIR,OI),has_prop(giz(g(IO_DIR)),In),
prop_group(giz(g(OI)),Objs),Objs\==[],!,enum_in_objs(In,Objs).

:- dynamic(saved_sorted_by_closeness/4).
sorted_by_closeness(In,Sorted,Objs,List):- once(var(In);var(Objs)),!,enum_in_objs(In,Objs), sorted_by_closeness(In,Sorted,Objs,List),List\==[].
sorted_by_closeness(In,Sorted,Objs,List):- var(Sorted), my_maplist(obj_to_oid,Objs,OIDS), sort_safe(OIDS,Sorted),!,sorted_by_closeness(In,Sorted,Objs,List).
sorted_by_closeness(In,Sorted,Objs,List):- saved_sorted_by_closeness(In,Sorted,Objs,List),!.
sorted_by_closeness(In,Sorted,Objs,List):-
sort_by_jaccard(In,_,Objs,List),
asserta(saved_sorted_by_closeness(In,Sorted,Objs,List)),!.



%find_prox_mappings(A,Candidates,Objs):- sort_by_jaccard(A,Candidates,Objs).
sort_by_jaccard(A,Candidates,Objs):- bonus_sort_by_jaccard([],A,sort_by_jaccard,Candidates,Objs).

find_prox_mappings(A,GroupID,Candidates,Objs):- sort_by_jaccard(A,GroupID,Candidates,Objs).
sort_by_jaccard(A,GroupID,Candidates,Objs):- bonus_sort_by_jaccard([],A,GroupID,Candidates,Objs).

bonus_sort_by_jaccard(Bonus,A,Candidates,Objs):-
bonus_sort_by_jaccard(Bonus,A,sort_by_jaccard,Candidates,Objs).

find_prox_mappings(Bonus,A,GroupID,Candidates,Objs):- bonus_sort_by_jaccard(Bonus,A,GroupID,Candidates,Objs).
bonus_sort_by_jaccard(_,_,_,[Obj],[Obj]):-!.
bonus_sort_by_jaccard(Bonus,A,GroupID,Candidates,Objs):-
must_det_ll((
obj_grp_atomslist(GroupID,A,PA,PAP0),
obj_atoms(Bonus,BonusAtoms),
append(PAP0,BonusAtoms,PAP),
ord(NJ/O+JO+Joins,[PA,A],[PB,B],B) = Why,
!,
findall(Why,
(
member(B,Candidates),
% B\==A,
% \+ is_whole_grid(B),
obj_grp_atomslist(GroupID,B,PB,PBP),
% PA\==PB,
memo_op(PAP,PBP,O,Joins,_J,NJ,JO)),
% maybe_allow_pair(PA,PB), allow_pair(PA,PB),
Pairs),
sort_safe(Pairs,RPairs),
%list_upto(3,RPairs,Some),
my_maplist(arg(4),RPairs,Objs))).


memo_op(PAP,PBP,O,Joins,J,NJ,JO):- PAP@>PBP->memo_op_1(PBP,PAP,O,Joins,J,NJ,JO);memo_op_1(PAP,PBP,O,Joins,J,NJ,JO).

:- abolish(memo_op_then/7).
:- dynamic(memo_op_then/7).
memo_op_1(PAP,PBP,O,Joins,J,NJ,JO):- memo_op_then(PAP,PBP,O,Joins,J,NJ,JO),!.
memo_op_1(PAP,PBP,O,Joins,J,NJ,JO):- memo_op_now(PAP,PBP,O,Joins,J,NJ,JO), asserta(memo_op_then(PAP,PBP,O,Joins,J,NJ,JO)),!.

memo_op_now(PAP,PBP,O,Joins,J,NJ,JO):-
intersection(PAP,PBP,Joins,OtherA,OtherB),!,
%append([OtherA,OtherB],Other),
length(Joins,J),length(OtherA,OA),length(OtherB,OB),
O is OA+OB,
NJ is -J,
JO is - rationalize(J/(O+1)),!.

maybe_exclude_whole([I],[I]).
maybe_exclude_whole(I,I):- \+ (member(Obj,I), is_fg_object(Obj), \+ is_whole_grid(Obj)),!.
Expand Down
14 changes: 13 additions & 1 deletion packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc_object.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1794,8 +1794,20 @@
center2G(I,X,Y):- indv_props(I,iz(cenGX(X))),indv_props(I,iz(cenGY(Y))),!.


% Calculate the center of mass of a list of points
center2D(I,X,Y):- is_cpoint(I),!,I=(_-P),hv_point(X,Y,P),!.
center2D(I,X,Y):- is_point(I),!,hv_point(X,Y,I),!.
center2D(I,X,Y):- is_grid(I), !, grid_size(I,H,V),X is floor(H/2),Y is floor(V/2).
center2D(I,X,Y):- indv_props(I,center2D(X,Y)),!.
center2D(I,X,Y):- indv_props(I,center2D(X,Y)),nonvar(X),nonvar(Y),!.
center2D([], inf, inf):-!.
center2D(I,X,Y):- \+ is_list(I),!, must_det_ll((globalpoints(I,Points),center2D(Points,X,Y))).
center2D(Points, CenterX, CenterY) :- maplist(center2D,Points,X,Y),
length(Points,Count),
sumlist(X,SumX),sumlist(Y,SumY),
Count > 0, % Ensure there's at least one point to avoid division by zero
CenterX is round(SumX / Count),
CenterY is round(SumY / Count).

%center2D(I,X,Y):- indv_props(I,iz(cenXD(X))),indv_props(I,iz(cenYD(Y))),!.
%center2G(Obj,CentX,CentY):- vis2D(Obj,H,V), loc2D(Obj,X,Y),CentX is X + floor(H/2),CentY is Y + floor(V/2).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@

is_input(VM):- VM.id = _ * _ * in.

is_input_object(Obj):- is_object(Obj),obj_to_oid(Obj,OID),atom_contains(OID,'_in_'),!.
is_output_object(Obj):- is_object(Obj), obj_to_oid(Obj,OID),atom_contains(OID,'_out_'),!.
is_input_object(Obj):- is_object(Obj),obj_to_oid(Obj,OID),atom_concat(_,'_in',OID),!.
is_output_object(Obj):- is_object(Obj), obj_to_oid(Obj,OID),atom_concat(_,'_out',OID),!.
%ignore(((NewOptions\==Options;(GoneMissing\==[];SofarMaybeNewL\==SofarL)),

%show_object_changes(_VM,_S,Goal):-!, call(Goal).
Expand Down
Loading

0 comments on commit 0791758

Please sign in to comment.