Commit 75ead529797c35c687d45e641b28b7661caa72c0
1 parent
1e8b2315
Exists in
master
START - PEx preparation
Showing
7 changed files
with
128 additions
and
14 deletions
Show diff stats
No preview for this file type
code/asplang/ASPLang.jl
| 1 | module ASPLang | 1 | module ASPLang |
| 2 | 2 | ||
| 3 | -export parse_asp, debug_asp, | 3 | +export parse_asp, debug_asp, pstring, |
| 4 | literal_grammar, term_grammar, aggregate_grammar, asp_grammar, | 4 | literal_grammar, term_grammar, aggregate_grammar, asp_grammar, |
| 5 | - Node, Variable, StringConstant, SymbolicConstant, AnonymousVariable, NumberConstant, Variable, | 5 | + Node, Terminal, NonTerminal, Variable, StringConstant, SymbolicConstant, AnonymousVariable, NumberConstant, Variable, |
| 6 | Functor, FunctionTerm, | 6 | Functor, FunctionTerm, |
| 7 | Negated, Inverted, Product, Sum, | 7 | Negated, Inverted, Product, Sum, |
| 8 | LT, LE, EQ, NE, GE, GT, | 8 | LT, LE, EQ, NE, GE, GT, |
| @@ -13,31 +13,47 @@ export parse_asp, debug_asp, | @@ -13,31 +13,47 @@ export parse_asp, debug_asp, | ||
| 13 | Aggregate, Elements, InclusionCondition, | 13 | Aggregate, Elements, InclusionCondition, |
| 14 | Constraint, LeftBound, RightBound, | 14 | Constraint, LeftBound, RightBound, |
| 15 | Choice, RestrictedChoice, Choices, | 15 | Choice, RestrictedChoice, Choices, |
| 16 | - Disjunction, Body, Rule, Restriction, WeakRestriction, Annotation, | 16 | + Disjunction, Head, Body, Rule, Restriction, WeakRestriction, Annotation, |
| 17 | Query, Program | 17 | Query, Program |
| 18 | 18 | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +abstract type Node end | ||
| 22 | +Base.:(==)(n1::Node, n2::Node) = (typeof(n1) == typeof(n2)) && (n1.args == n2.args) | ||
| 23 | + | ||
| 24 | +pstring(x::Any, level=0) = repr(x) | ||
| 25 | +abstract type Terminal <: Node end | ||
| 19 | macro terminal(lang) | 26 | macro terminal(lang) |
| 20 | return quote | 27 | return quote |
| 21 | - struct $lang <: Node end | 28 | + struct $lang <: Terminal end |
| 22 | end | 29 | end |
| 23 | end | 30 | end |
| 31 | +pstring(x::Terminal, level=0) = "$(" "^level)$(typeof(x))" | ||
| 24 | 32 | ||
| 33 | +abstract type NonTerminal <: Node end | ||
| 25 | macro variable(lang) | 34 | macro variable(lang) |
| 26 | return quote | 35 | return quote |
| 27 | - struct $lang <: Node | 36 | + struct $lang <: NonTerminal |
| 28 | args | 37 | args |
| 29 | end | 38 | end |
| 30 | end | 39 | end |
| 31 | end | 40 | end |
| 32 | 41 | ||
| 42 | +function pstring(x::NonTerminal, level=0) | ||
| 43 | + if typeof(x.args) <: AbstractVector | ||
| 44 | + pargs = x.args .|> (z -> pstring(z, level + 2)) | ||
| 45 | + "\n$(" "^level)$(typeof(x))($(join(pargs, ","))\n$(" "^level))" | ||
| 46 | + else | ||
| 47 | + pargs = join(pstring.(x.args), ",") | ||
| 48 | + "\n$(" "^level)$(typeof(x))($pargs) - $(typeof(x.args))" | ||
| 49 | + end | ||
| 50 | +end | ||
| 51 | + | ||
| 33 | using ParserCombinator | 52 | using ParserCombinator |
| 34 | #= | 53 | #= |
| 35 | DATA STRUCTURES | 54 | DATA STRUCTURES |
| 36 | =# | 55 | =# |
| 37 | 56 | ||
| 38 | -abstract type Node end | ||
| 39 | -Base.:(==)(n1::Node, n2::Node) = (typeof(n1) == typeof(n2)) && (n1.args == n2.args) | ||
| 40 | - | ||
| 41 | @variable Variable | 57 | @variable Variable |
| 42 | @variable StringConstant | 58 | @variable StringConstant |
| 43 | @variable SymbolicConstant | 59 | @variable SymbolicConstant |
| @@ -92,6 +108,7 @@ Base.:(==)(n1::Node, n2::Node) = (typeof(n1) == typeof(n2)) && (n1.args == n2.ar | @@ -92,6 +108,7 @@ Base.:(==)(n1::Node, n2::Node) = (typeof(n1) == typeof(n2)) && (n1.args == n2.ar | ||
| 92 | @variable Disjunction | 108 | @variable Disjunction |
| 93 | @variable Annotation | 109 | @variable Annotation |
| 94 | @variable Body | 110 | @variable Body |
| 111 | +@variable Head | ||
| 95 | 112 | ||
| 96 | @variable Rule | 113 | @variable Rule |
| 97 | @variable Restriction | 114 | @variable Restriction |
| @@ -316,7 +333,7 @@ statement = | @@ -316,7 +333,7 @@ statement = | ||
| 316 | # strong restriction | 333 | # strong restriction |
| 317 | (E":-" + body + E"." > Restriction) | | 334 | (E":-" + body + E"." > Restriction) | |
| 318 | # rule | 335 | # rule |
| 319 | - (head + Opt(annotation) + Opt(E":-" + body) + E"." |> Rule) | | 336 | + ((head + Opt(annotation) |> Head) + Opt(E":-" + body) + E"." |> Rule) | |
| 320 | # weak restriction | 337 | # weak restriction |
| 321 | (E":~" + Opt(body) + E"." + spc + E"[" + weight_at_level + E"]" |> WeakRestriction) | 338 | (E":~" + Opt(body) + E"." + spc + E"[" + weight_at_level + E"]" |> WeakRestriction) |
| 322 | statements = StarList(statement, E"") | 339 | statements = StarList(statement, E"") |
code/asplang/drafts.jl
| @@ -4,8 +4,7 @@ using .ASPLang | @@ -4,8 +4,7 @@ using .ASPLang | ||
| 4 | 4 | ||
| 5 | function test_parse(source, grammar=asp_grammar) | 5 | function test_parse(source, grammar=asp_grammar) |
| 6 | expr = parse_asp(source, grammar) | 6 | expr = parse_asp(source, grammar) |
| 7 | - println("$source => $(expr).\n") | ||
| 8 | - print(pstring(expr)) | 7 | + println("$source\n$(pstring(expr))") |
| 9 | end | 8 | end |
| 10 | 9 | ||
| 11 | # test_parse("\"a\"", term_grammar) | 10 | # test_parse("\"a\"", term_grammar) |
code/asplang/sbf.plp
pex2024/candidatura.md
| 1 | -# Candidatura PeX - Zugzwang | 1 | +# Candidatura PEx - Zugzwang |
| 2 | + | ||
| 3 | + | ||
| 4 | +## 2024-01-05 - Next Research Lines | ||
| 5 | + | ||
| 6 | +> After the base-setting work of "_An Algebraic Approach to Stochastic ASP_" these are the next tasks to consider. Is summary: | ||
| 7 | +> 1. **Logic Programming** - Stratified & Non-stratified programs | ||
| 8 | +> 2. **Computer Science** - Inductive Logic Programming | ||
| 9 | +> 3. **Software** - Integration with Potassco and other frameworks | ||
| 10 | +> 4. **Applications** | ||
| 11 | + | ||
| 12 | +#### Line 1: Logic Programming - Stratified & Non-stratified programs | ||
| 13 | + | ||
| 14 | +##### Line 1a - Logic Programs Structure and Properties | ||
| 15 | + | ||
| 16 | +> _Stratified_ & _non-stratified_ programs are quoted in the "CREDAL" papers as important classes of logic programs. | ||
| 17 | + | ||
| 18 | +Minimal example of a **non-stratified program**. | ||
| 19 | + | ||
| 20 | +The following annotated LP, with clauses $c_1, c_2, c_3$ respectively, is non-stratified (because has a cycle with negated arcs) but no head is disjunctive: | ||
| 21 | +```prolog | ||
| 22 | +0.3::a. % c1 | ||
| 23 | +b :- not c, not a. % c2 | ||
| 24 | +c :- not b. % c3 | ||
| 25 | +``` | ||
| 26 | + | ||
| 27 | +This program has three stable models: | ||
| 28 | +$$ | ||
| 29 | +\begin{aligned} | ||
| 30 | +m_1 &= \set{ a, c } \cr | ||
| 31 | +m_2 &= \set{ \neg a, b } \cr | ||
| 32 | +m_3 &= \set{ \neg a, c } | ||
| 33 | +\end{aligned} | ||
| 34 | +$$ | ||
| 35 | + | ||
| 36 | +> We should **investigate** _What are stratified programs and why are they important?_ and how does our approach deals with such programs? | ||
| 37 | + | ||
| 38 | +##### Line 1b - Investigate the expressiveness of PASP | ||
| 39 | + | ||
| 40 | +Consider: | ||
| 41 | + | ||
| 42 | +- Recursion | ||
| 43 | +- Variables, | ||
| 44 | +- Functional symbols, | ||
| 45 | + | ||
| 46 | +##### Line 1c - The equivalence relation | ||
| 47 | + | ||
| 48 | +Consider the cases where only $s \subseteq e$ and $e \subseteq s$. Or other refinements. Also consider the inconsistent and independent events. | ||
| 49 | + | ||
| 50 | +##### Line 1d - Stability of the error function | ||
| 51 | + | ||
| 52 | +Consider alternative error functions. See statistics, Kullback-Leibler divergence | ||
| 53 | + | ||
| 54 | +#### Line 2: Computer Science - Inductive Logic Programming | ||
| 55 | + | ||
| 56 | +> Proceed from scoring programs to support genetic algorithms or other program space exploration methods. | ||
| 57 | + | ||
| 58 | +Scoring programs, as described in our paper, is just a step into **Inductive Logic Programming**. To go further, we need to explore algorithms that: | ||
| 59 | + | ||
| 60 | +1. Use **background knowledge**, expressed as a PLP. | ||
| 61 | +2. Consult **positive examples** that should be _soft_ induced. | ||
| 62 | +3. Consult **negative examples** that should be _soft_ excluded. | ||
| 63 | +4. Generate **PLPs** that are scored. | ||
| 64 | +5. Recombine the **best scored** into a new _population_, using recombination rules. | ||
| 65 | + | ||
| 66 | +> In order to do that, **PLPs must be expressed as data structures** to be manipulated. Also **recombination rules** must investigated before become formally expressed and supported with adequate methods. | ||
| 67 | + | ||
| 68 | +#### Line 3: Software - Integration with Potassco and other frameworks | ||
| 69 | + | ||
| 70 | +> Support annotated programs with zugzwang semantics. | ||
| 71 | + | ||
| 72 | +- Bayesian Networks (BII Alice) | ||
| 73 | + - Generate an annotated asp program from a bayesian network and run it trough `clingo`. | ||
| 74 | + - Recover the stable models from the previous ste and compute the respective probabilities. | ||
| 75 | +- Program Manipulation | ||
| 76 | + - Annotated ASP program _representation_ and a _parser_. | ||
| 77 | + | ||
| 78 | +#### Line 4: Applications | ||
| 79 | + | ||
| 80 | +> Apply zugzwang to a few showcases, besides the theoretic corner stones (non-stratified, disjunctive, bayes networks), preferably based in real world scenarios, with complex structure and large datasets. | ||
| 81 | + | ||
| 82 | +- (Stochastic) Plan Generation | ||
| 83 | +- Yale-Shooting Problem | ||
| 84 | +- (Stochastic) Situation Calculus | ||
| 85 | +- Frame Problem | ||
| 86 | +- Latent Facts - and core assumptions. | ||
| 87 | +- Given a **Bayesian Network** (or a **Markov Networks**): | ||
| 88 | + - Represent it. (**done** for BNs; MNs?) | ||
| 89 | + - Solve the common probability tasks: join (**done**), marginals, conditionals, parameter learning, inferring unobserved variables, sample generation, _etc._ | ||
| 90 | +- Given a _solved_ ASP specification: | ||
| 91 | + - What is the marginal probability of the atom `a`? (**done**) | ||
| 92 | + - What other probability queries are important to consider? | ||
| 93 | +- Given an _unsolved_ ASP specification: | ||
| 94 | + - What is the probability (distribution?) of the probabilistic fact `a`? | ||
| 95 | + - What other questions are relevant? _E.g._ the distribution family of a fact? | ||
| 96 | +- Given a _solved_ ASP specification and a set of _samples_: | ||
| 97 | + - How do the probabilities inferred from the specification match the ones from the empiric distribution? (**done** might see alternative approaches) | ||
| 98 | +- Given two _solved_ ASP specification and a set of _samples_: | ||
| 99 | + - Which specification best describes the empiric distribution? (**done**) | ||
| 2 | 100 | ||
| 3 | ## Tarefas | 101 | ## Tarefas |
| 4 | 102 |
No preview for this file type
projecto-NovaLINCS.gdlink