Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mode-Directed Tabling for Dynamic Programming, Machine Learning, and Constraint Solving Neng-Fa Zhou (City Univ. of New York) Yoshitaka Kameya and Taisuke.

Similar presentations


Presentation on theme: "Mode-Directed Tabling for Dynamic Programming, Machine Learning, and Constraint Solving Neng-Fa Zhou (City Univ. of New York) Yoshitaka Kameya and Taisuke."— Presentation transcript:

1 Mode-Directed Tabling for Dynamic Programming, Machine Learning, and Constraint Solving
Neng-Fa Zhou (City Univ. of New York) Yoshitaka Kameya and Taisuke Sato (Tokyo Inst. of Technology) ICTAI'10, Zhou&Kameya&Sato

2 ICTAI'10, Zhou&Kameya&Sato
What is Tabling? The idea of tabling is to memorize answers to tabled subgoals and use the answers to resolve subsequent variant or subsumed subgoals. Eliminate infinite loops Reduce redundancy :-table path/2. path(X,Y):-edge(X,Y). path(X,Y):- edge(X,Z), path(Z,Y). :-table fib/2. fib(N,F):-N=<1,!,F=1. fib(N,F):- N1 is N-1, fib(N1,F1), N2 is N-2, fib(N2,F2), F is F1+F2. ICTAI'10, Zhou&Kameya&Sato

3 The Table-All Approach
Characteristics All the arguments of a tabled subgoal are used in variant or subsumption checking All answers are tabled Problems The number of answers may be too large or even infinite for DP and ML problems When computing aggregates, tabling noncontributing answers is a waste ICTAI'10, Zhou&Kameya&Sato

4 Problems of Table-All (Ex-1)
:-table path/3. path(X,Y,[(X,Y)]):-edge(X,Y). path(X,Y,[(X,Z)|P]):- edge(X,Z), path(Z,Y,P). It’s infeasible to table all the answers because the number of paths is infinite. ICTAI'10, Zhou&Kameya&Sato

5 Problems of Table-All (Ex-2) (From the PRISM User’s Manual)
pcfg(L):- pcfg(s,L-[]). pcfg(LHS,L0-L1):- ( nonterminal(LHS)-> msw(LHS,RHS), proj(RHS,L0-L1) ; L0 = [LHS|L1] ). proj([],L-L). proj([X|Xs],L0-L1):- pcfg(X,L0-L2), proj(Xs,L2-L1). It is infeasible to table all the answers of pcfg/2 if the number of parse trees is huge. ICTAI'10, Zhou&Kameya&Sato

6 Mode-Directed Tabling in B-Prolog
Table mode declaration C: Cardinality limit Modes +: input, used in variant checking -: output, not used in variant checking nt : not tabled, not used in variant checking or answer tabling min: output, table answers with minimum values max: output, table answers with maximum values :-table p(M1,...,Mn):C. ICTAI'10, Zhou&Kameya&Sato

7 Ex-1: Shortest Path Problem
:-table sp(+,+,-,min). sp(X,Y,[(X,Y)],W) :- edge(X,Y,W). sp(X,Y,[(X,Z)|Path],W) :- edge(X,Z,W1), sp(Z,Y,Path,W2), W is W1+W2. sp(X,Y,P,W) P is a shortest path between X and Y with weight W. ICTAI'10, Zhou&Kameya&Sato

8 ICTAI'10, Zhou&Kameya&Sato
Ex-2: Knapsack Problem :- table knapsack(+,+,-,max). knapsack(_,0,[],0). knapsack([_|L],K,Selected,V):- knapsack(L,K,Selected,V). knapsack([F|L],K,[F|Selected],V):- K1 is K - F, K1 >= 0, knapsack(L,K1,Selected,V1), V is V1 + 1. knapsack(L,K,Selected,V) L: the list of items K: the total capacity Selected: the list of selected items V: the length of Selected ICTAI'10, Zhou&Kameya&Sato

9 Mode-Directed Tabling for Dynamic Programming
General approach Use recursion to generate tuples of a relation Use mode-directed tabling to guide indexing subgoals and tabling answers More examples Second ASP solver competition ( How to Solve it With B-Prolog (17th Prolog Programming Contest) ICTAI'10, Zhou&Kameya&Sato

10 PRISM Prolog + Probabilistic reasoning and learning
Probability distributions and switches Sample execution: sample(Goal) Probability calculation: prob(Goal,P) Learning: learn(Facts) values(coin,[head:0.5,tail:0.5]). direction(D):- msw(coin,Face), (Face==head->D=left;D=right). ICTAI'10, Zhou&Kameya&Sato

11 ICTAI'10, Zhou&Kameya&Sato
An Example in PRISM hmm(L) :- msw(init,Si), hmm(Si,L). hmm(S,[]). hmm(S,[C|L]) :- msw(out(S),C), msw(tr(S),NextS), hmm(NextS,L). values(init,[s0,s1]). values(out(_),[a,b]). values(tr(_),[s0,s1]). hmm([a,b,a]) hmm(s0,[a,b,a]) hmm(s1,[a,b,a]) hmm(s0,[b,a]) hmm(s1,[b,a]) hmm(s0,[a]) hmm(s1,[a]) hmm(s0,[]) hmm(s1,[]) ICTAI'10, Zhou&Kameya&Sato

12 ICTAI'10, Zhou&Kameya&Sato
Use of Tabling in PRISM :-table expl_hmm/2. expl_hmm(S,[]). expl_hmm(S,[CL]) :- expl_msw(out(S),C), expl_msw(tr(S),NextS), expl_hmm(NextS,L), add_explanation(path(hmm(S,[CL]), [hmm(NextS,L)], [msw(out(S),C), msw(tr(S),NextS)])). ICTAI'10, Zhou&Kameya&Sato

13 Use of Mode-Directed Tabling in PRISM
:- table viterbi_hmm(+,-,-,max):3. viterbi_hmm(Os,E0,E1,W) :- str_length(L), viterbi_msw(init,S,W1), viterbi_hmm(1,L,S,Os,E2,E1,W2), W is W1+W2, E0=[node(hmm(Os), [path([hmm(1,L,S,Os)], [msw(init,S)])])|E2]. Perform partial Viterbi computation by declaring a cardinality limit ICTAI'10, Zhou&Kameya&Sato

14 Performance Improvement
Fig.~\ref{performance} (left) shows the execution time in Viterbi inference for the HMM program with various sequence lengths when the number of states is fixed at $50$. Fig.~\ref{performance} (right) shows the execution time with various numbers of states when the sequence length is fixed at $500$. The curve ``plain'' indicates the case {\em without} mode-directed tabling, and the curve ``mode-directed'' indicates the case {\em with} mode-directed tabling. In all runs, the cardinality limit was set to be one, and the probabilities over {\tt msw(I,V)} were set randomly. We can see from these results that the improvement by mode-directed tabling gets more significant as the model/data gets larger, and thus mode-directed tabling is effective, especially for large data and complex models. } ICTAI'10, Zhou&Kameya&Sato

15 Mode-Directed Tabling for Evaluating ASP Programs
Use tabling for programs with stratified negation Use propagation and labeling to handle non-stratified negation Use mode-directed tabling in seeking supports ICTAI'10, Zhou&Kameya&Sato

16 ICTAI'10, Zhou&Kameya&Sato
Conclusion Mode-directed tabling is useful For dynamic programming problems For machine learning applications For evaluating ASP programs More information B-Prolog version 7.4 & up (bprolog.com) ICTAI'10, Zhou&Kameya&Sato


Download ppt "Mode-Directed Tabling for Dynamic Programming, Machine Learning, and Constraint Solving Neng-Fa Zhou (City Univ. of New York) Yoshitaka Kameya and Taisuke."

Similar presentations


Ads by Google