Skip to content

Commit

Permalink
10% +
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed May 6, 2023
1 parent 93c9134 commit be25685
Show file tree
Hide file tree
Showing 9 changed files with 598 additions and 235 deletions.
2 changes: 1 addition & 1 deletion packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@
%copy with mod
'08ed6ac7', 'ea32f347', '0a2355a6', '37d3e8b2', 'a61ba2ce', 'b230c067', 'd2abd087', '6e82a1ae',
%copy with mod (harder?)
'705a3229', 'e41c6fd3', 'a61f2674', '0d3d703e', 'makesboxsq', 'a79310a0', '27a77e38',
'705a3229', 'e41c6fd3', 'a61f2674', '0d3d703e', 'makesboxsq', 'a79310a0', '27a77e38', 'f45f5ca7','fc754716',
%todo
'f8b3ba0a', '5582e5ca', '33b52de3', '1b60fb0c',
%recolor with a pattern from output
Expand Down
12 changes: 9 additions & 3 deletions packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc_deepening.pl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@

end_of_file.

end_of_file.
end_of_file.


sdfsdf
sdfsdfs sdfdf




Expand Down Expand Up @@ -260,8 +267,8 @@
hide_propchange2(In,Out):- \+ compound(In),!,Out=In.
hide_propchange2(link(PA,_),link(PA,_)).
hide_propchange2(pg(_,P,rank1,N),pg(_,P,rank1,N)).
hide_propchange2(occurs_in_links(PA,_),occurs_in_links(PA,_)).
hide_propchange2(links_count(PA,_),links_count(PA,_)).
%hide_propchange2(occurs_in_links(PA,_),occurs_in_links(PA,_)).
%hide_propchange2(links_count(PA,_),links_count(PA,_)).
hide_propchange2(giz(example_num(ExampleNum)),giz(example_num(ExampleNum))).
hide_propchange2(giz(gid(_)),giz(gid(_))).
hide_propchange2(giz(A),giz(B)):- make_unifiable_u(A,B).
Expand Down Expand Up @@ -943,7 +950,6 @@
must_det_ll((
ensure_individuals(TestID),
ignore((ExampleNum=trn+_)),
retractall(arc_cache:causes(TestID,_,_,_,_)),
forall(kaggle_arc(TestID,ExampleNum,_,_),
learn_object_dependancy(TestID,ExampleNum)),
induction_update(TestID,in_out),
Expand Down
179 changes: 177 additions & 2 deletions packs_sys/logicmoo_agi/prolog/kaggle_arc/kaggle_arc_generalization.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
```prolog
*/


ensure_ground(C):- compound(C), C=not(TV),!,ensure_ground(TV).
ensure_ground(Type:Value):- var(Value),!,feature(_, Type:Value).
ensure_ground(_:_).
Expand Down Expand Up @@ -476,6 +475,7 @@

lgg_property(A, B, C):- merge_vals(A, B, C).

/*
%lgg_property(A, A, A) :- !. lgg_property(_, _, _).
% Original rule (unchanged)
lgg_property_unused(S, S, S) :-
Expand All @@ -497,7 +497,7 @@
constant_vals(_, _, A, _, _, _, _, _, _, _, _, _, _, _, _, _, _),
constant_vals(_, _, _, B, _, _, _, _, _, _, _, _, _, _, _, _, _),
A \= B.

*/
% Add other rules for different property types as needed

% Predicate for applying rules to a property
Expand Down Expand Up @@ -648,10 +648,185 @@



end_of_file.



:- dynamic positive/1.
:- dynamic negative/1.

% Sample data - positive and negative examples
positive(properties([color(silver), shape(circle), size(1), texture(rough)])).
positive(properties([color(silver), shape(circle), size(2), texture(smooth)])).
% ... add more positive examples

negative(properties([color(blue), shape(circle), size(2), texture(smooth)])).
negative(properties([color(silver), shape(square), size(1), texture(smooth)])).
% ... add more negative examples

% List of attributes
attributes([color(_), shape(_), size(_), texture(_)]).

% Checks if a given example is covered by a list of attribute-value pairs
covered(Example, AttrValues) :-
forall(member(AttrValue, AttrValues), member(AttrValue, Example)).

% Generates a star from an example
star(Example, Star) :-
findall(AttrValue, (member(AttrValue, Example), not(member(neg(AttrValue), Example))), Star).

% Determines if a hypothesis covers only positive examples
valid_hypothesis(Hypothesis) :-
forall(positive(Example), covered(Example, Hypothesis)),
forall(negative(Example), not(covered(Example, Hypothesis))).

% AQ Algorithm
aq_algorithm :-
findall(Star, (positive(Example), star(Example, Star)), Stars),
find_star_combinations(Stars, [], Hypothesis),
valid_hypothesis(Hypothesis),
write('Hypothesis: '), writeln(Hypothesis).

% Finds a combination of stars that covers all positive examples and no negative examples
find_star_combinations(_, Hypothesis, Hypothesis) :-
valid_hypothesis(Hypothesis).
find_star_combinations([Star|Stars], CurrentHypothesis, Hypothesis) :-
append(CurrentHypothesis, Star, NewHypothesis),
(valid_hypothesis(NewHypothesis) ->
Hypothesis = NewHypothesis
;
find_star_combinations(Stars, NewHypothesis, Hypothesis)
).








% Candidate Elimination Algorithm

run_candidate_elim :- candidate_elim([[_,_,_]], [],
[[small, medium, large], [red, blue, green], [ball, brick, cube]]).

% Candidate_elim implements a top level read-process loop
% It prints out the current G set
% the S set
%
% and calls process to process the input.
candidate_elim([G],[S],_) :-
covers(G,S),covers(S,G),
write("target concept is "), write(G),nl.

candidate_elim(G, S, Types) :-
write("G= "), write(G),nl,
write("S= "), write(S),nl,
write("Enter Instance "),
read(Instance),
process(Instance, G, S, Updated_G, Updated_S, Types),
candidate_elim(Updated_G, Updated_S, Types).

% Process takes the instance,
% a set of concepts, G and
% and a set of concepts, S
% it implements a step of the candidate elimination algorithm.


process(negative(Instance), G, S, Updated_G, Updated_S, Types) :-
delete(X, S, covers(X, Instance), Updated_S),
specialize_set(G,Spec_G, Instance, Types),
delete(X, Spec_G, (member(Y, Spec_G), more_general(Y, X)), Pruned_G),
delete(X, Pruned_G, (member(Y, Updated_S), not(covers(X, Y))), Updated_G).

process(positive(Instance), G, [], Updated_G, [Instance],_):-
% Initialize S

delete(X, G, not(covers(X, Instance)), Updated_G).

process(positive(Instance), G, S, Updated_G, Updated_S,_) :-
delete(X, G, not(covers(X, Instance)), Updated_G),
generalize_set(S,Gen_S, Instance),
delete(X, Gen_S, (member(Y, Gen_S), more_general(X, Y)), Pruned_S),
delete(X, Pruned_S, not((member(Y, Updated_G), covers(Y, X))), Updated_S).

process(Input, G, P, G, P,_):-
Input \= positive(_),
Input \= negative(_),
write("Enter either positive(Instance) or negative(Instance) "), nl

% The following predicate definitions are duplicated in either
% the general to specific searches or the specific to genearal searches.
%
specialize_set([], [], _, _).
specialize_set([Hypothesis|Rest],Updated_H,Instance, Types):-
covers(Hypothesis, Instance),
(bagof(Hypothesis, specialize(Hypothesis, Instance, Types), Updated_head); Updated_head = []),
specialize_set(Rest, Updated_rest, Instance, Types),
append(Updated_head, Updated_rest, Updated_H).

specialize_set([Hypothesis|Rest],[Hypothesis|Updated_rest],Instance, Types):-
not (covers(Hypothesis, Instance)),
specialize_set(Rest,Updated_rest, Instance, Types).

specialize([Prop|_], [Inst_prop|_], [Instance_values|_]):-
var(Prop),
member(Prop, Instance_values),
Prop \= Inst_prop.

specialize([_|Tail], [_|Inst_tail], [_|Types]):-
specialize(Tail, Inst_tail, Types).

%

generalize_set([], [], _).

generalize_set([Hypothesis|Rest],Updated_H,Instance):-
not(covers(Hypothesis, Instance)),
(bagof(X, generalize(Hypothesis, Instance, X), Updated_H); Updated_head = []),
generalize_set(Rest,Updated_rest, Instance),
append(Updated_head, Updated_rest, Updated_H).

generalize_set([Hypothesis|Rest],[Hypothesis|Updated_rest],Instance):-
covers(Hypothesis, Instance),
generalize_set(Rest,Updated_rest, Instance).

%

generalize([],[],[]).
generalize([Feature|Rest], [Inst_prop|Rest_inst], [Feature|Rest_gen]) :-
not(Feature \= Inst_prop),
generalize(Rest, Rest_inst, Rest_gen).

generalize([Feature|Rest], [Inst_prop|Rest_inst], [_|Rest_gen]) :-
Feature \= Inst_prop,
generalize(Rest, Rest_inst, Rest_gen).

% more_general(Feature_vector_1, Feature_vector_2) :- succeeds if
% Feature_vector_1 is strictly more general than Feature_vector_2

more_general(X, Y) :- not(covers(Y, X)), covers(X, Y).

% covers(Feature_list_1, Feature_list_2) :- Succeeds if Feature_list_1
% covers Feature_list_2. Note that covers, unlike unification is
% not symmetric: variables in Feature_list_2 will not match constants
% in Feature_list_1.

covers([],[]).
covers([H1|T1], [H2|T2]) :-
var(H1), var(H2),
covers(T1, T2).
covers([H1|T1], [H2|T2]) :-
var(H1), atom(H2),
covers(T1, T2).
covers([H1|T1], [H2|T2]) :-
atom(H1), atom(H2), H1 = H2,
covers(T1, T2).

% delete(Element, List1, Goal, List2) :- List2 contains all bindings
% of Element to a member of List1 except those that cause
% Goal to succeed

delete(X, L, Goal, New_L) :-
(bagof(X, (member(X, L), not(Goal)), New_L);New_L = []).

Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,12 @@
never_is_prop((_>_)).
never_is_prop((_*_)).
never_is_prop((_-_)).
never_is_prop((_:-_)).
never_is_prop((_/_)).
never_is_prop(into_new(_,_,_)).
never_is_prop(ac_db(_,_,_,_)).
never_is_prop(ac_rules(_,_,_,_)).
never_is_prop(rhs(_)).


is_obj_props(Props):- is_list(Props), Props\==[], maplist(is_prop1,Props).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

my_menu_call(E):- locally(set_prolog_flag(gc,true),ui_menu_call(E)).

my_submenu_call(G):- current_predicate(_,G), \+ is_list(G),!, locally(set_prolog_flag(nogc,false),ui_menu_call(G)),!.
my_submenu_call(G):- current_predicate(_,G), \+ is_list(G),!, locally(set_prolog_flag(gc,false),ui_menu_call(G)),!.
my_submenu_call0(E):- peek_vm(VM),!, ui_menu_call(run_dsl(VM,E,VM.grid,Out)), set(VM.grid) = Out.

key_read_borked(PP):- fail, in_pp(PP), PP\==ansi,PP\==bfly.
Expand Down
Loading

0 comments on commit be25685

Please sign in to comment.