Commit 37729abe authored by josd's avatar josd

implementing ccd:transformer in ./reasoning/ccd/ccd_rules.n3

parent 7618e978
EYE release
[v18.1225.2318] making e:ccdTransform built-in more robust and scalable
[v18.1223.1751] adding e:ccdTransform built-in to transform case control datamodels
[v18.1230.1307] implementing ccd:transformer in ./reasoning/ccd/ccd_rules.n3
[v18.1214.1911] reintroducing --carl switch and original N3 parser
[v18.1130.1238] updating reasoning to always use PREFIX instead of @prefix
[v18.1123.1028] removing libgmp dependency
......
EYE v18.1225.2318 josd
EYE v18.1230.1307 josd
......@@ -25,7 +25,6 @@ e:binaryEntropy a e:Builtin.
e:calculate a e:Builtin.
e:call a e:Builtin.
e:cartesianProduct a e:Builtin.
e:ccdTransform a e:Builtin.
e:compoundTerm a e:Builtin.
e:cov a e:Builtin.
e:csvTuple a e:Builtin.
......
......@@ -36,7 +36,7 @@
:- set_prolog_flag(encoding, utf8).
:- endif.
version_info('EYE v18.1225.2318 josd').
version_info('EYE v18.1230.1307 josd').
license_info('MIT License
......@@ -5086,32 +5086,6 @@ djiti_assertz(A) :-
B
).
'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#ccdTransform>'([A, B], [Y, Z]) :-
findall([F, G, H],
( length(A, I),
member([F, G, J, K], A),
( J =:= 0
-> H is -2*log(I)
; ( K =:= 0
-> H is 2*log(I)
; H is log(J)-log(K)
)
)
),
Y
),
findall(H,
( member([_, _, H], Y)
),
L
),
sum(L, M),
length(L, N),
( N > 0
-> Z is 1/(1+(1/B-1)*exp(-M/N))
; Z is B
).
% DEPRECATED
'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#closure>'(Sc, A) :-
within_scope(Sc),
......
No preview for this file type
......@@ -130,11 +130,6 @@ e:cartesianProduct a rdf:Property, e:Builtin;
rdfs:domain rdf:List;
rdfs:range rdf:List.
e:ccdTransform a rdf:Property, e:Builtin;
rdfs:comment "built-in to transform case control datamodels";
rdfs:domain rdf:List;
rdfs:range rdf:List.
e:clashesWith a rdf:Property;
rdfs:comment "to say that the graph is XSD-inconsistent or has a datatype clash";
rdfs:domain rdfs:Literal;
......
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
PREFIX math: <http://www.w3.org/2000/10/swap/math#>
PREFIX e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
PREFIX ccd: <http://josd.github.io/eye/reasoning/ccd#>
{
(?A ?B) ccd:transformer (?Y ?Z).
} <= {
?SCOPE e:findall (
(?F ?G ?H)
{
?A math:memberCount ?I.
?A list:member (?F ?G ?J ?K).
("if_then_else"
{
?J math:equalTo 0.
}
{
("-2*log(_I)" ?I) e:calculate ?H.
}
{
("if_then_else"
{
?K math:equalTo 0.
}
{
("2*log(_I)" ?I) e:calculate ?H.
}
{
("log(_J)-log(_K)" ?J ?K) e:calculate ?H.
}
) e:derive true.
}
) e:derive true.
}
?Y
).
?SCOPE e:findall (
?H
{
?Y list:member (?U ?V ?H).
}
?L
).
?L math:sum ?M.
?L math:memberCount ?N.
("if_then_else"
{
?N math:greaterThan 0.
}
{
("1/(1+(1/_B-1)*exp(-_M/_N))" ?B ?M ?N) e:calculate ?Z.
}
{
("_B" ?B) e:calculate ?Z.
}
) e:derive true.
}.
#!/bin/bash
eye --nope --turtle http://josd.github.io/eye/reasoning/ccd/train_data.ttl --n3 http://josd.github.io/eye/reasoning/ccd/train_rules.n3 --query http://josd.github.io/eye/reasoning/ccd/train_query.n3 > train_model.ttl
eye --nope --turtle http://josd.github.io/eye/reasoning/ccd/test_data.ttl --turtle http://josd.github.io/eye/reasoning/ccd/train_model.ttl --query http://josd.github.io/eye/reasoning/ccd/test_query.n3 > test_answer.ttl
eye --nope --turtle http://josd.github.io/eye/reasoning/ccd/test_data.ttl --turtle http://josd.github.io/eye/reasoning/ccd/train_model.ttl --n3 http://josd.github.io/eye/reasoning/ccd/ccd_rules.n3 --query http://josd.github.io/eye/reasoning/ccd/test_query.n3 > test_answer.ttl
#Processed by EYE v18.1225.2318 josd
#eye --nope --turtle http://josd.github.io/eye/reasoning/ccd/test_data.ttl --turtle http://josd.github.io/eye/reasoning/ccd/train_model.ttl --query http://josd.github.io/eye/reasoning/ccd/test_query.n3
#eye --nope --turtle test_data.ttl --turtle train_model.ttl --n3 ccd_rules.n3 --query test_query.n3
PREFIX : <http://josd.github.io/eye/reasoning#>
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
PREFIX ccd: <http://josd.github.io/eye/reasoning/ccd#>
PREFIX math: <http://www.w3.org/2000/10/swap/math#>
PREFIX e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
_:t_0 :answer (:expected 1 :predicted 1 :belief 0.7040031411428228 :evidence ((:input1 "xyz" 0.6931471805599453) (:input3 (0 1) 0.0) (:input4 :v4 0.0) (:input5 "b" 2.772588722239781))).
_:t_1 :answer (:expected 0 :predicted 0 :belief 0.6101493074464512 :evidence ((:input1 "abc" -0.4054651081081645) (:input2 60 -0.6931471805599453) (:input4 :v3 -0.6931471805599453) (:input5 "a" 0.0))).
_:t_2 :answer (:expected 1 :predicted 1 :belief 0.7238134704678372 :evidence ((:input1 "xyz" 0.6931471805599453) (:input2 40 2.1972245773362196) (:input5 "a" 0.0))).
_:t_3 :answer (:expected 0 :predicted 0 :belief 0.5857864376269049 :evidence ((:input3 (0 1) 0.0) (:input4 :v3 -0.6931471805599453))).
#2018-12-25T23:21:20.557Z in=33 out=4 ent=0 step=0 brake=1 inf=31377 sec=0.092 inf/sec=341054
#2018-12-30T13:05:50.190Z in=35 out=4 ent=0 step=0 brake=1 inf=50607 sec=0.094 inf/sec=538372
#ENDS
......@@ -2,5 +2,5 @@ PREFIX : <http://josd.github.io/eye/reasoning#>
[] :input1 "xyz"; :input3 (0 1); :input4 :v4; :input5 "b"; :output1 1.
[] :input1 "abc"; :input2 60; :input4 :v3; :input5 "a"; :output1 0.
[] :input1 "xyz"; :input2 40; :input5 "a"; :output1 1.
[] :input1 "xyz"; :input2 40; :input5 "a"; :input9 8; :output1 1.
[] :input1 "def"; :input2 50; :input3 (0 1); :input4 :v3; :output1 0.
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
PREFIX math: <http://www.w3.org/2000/10/swap/math#>
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
PREFIX e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
PREFIX ccd: <http://josd.github.io/eye/reasoning/ccd#>
PREFIX : <http://josd.github.io/eye/reasoning#>
{
......@@ -19,17 +19,22 @@ PREFIX : <http://josd.github.io/eye/reasoning#>
:input5
) list:member ?P.
?S ?P ?O.
(?P ?O) :ccd (?C ?N).
(?P ?O) ccd:model (:output1 ?C ?N).
}
?CL
).
(?CL 0.5) e:ccdTransform (?E ?Q).
?SCOPE e:optional {
?Q math:greaterThan 0.5.
(?V ?B) log:equalTo (1 ?Q).
}.
?SCOPE e:optional {
(1 ?Q) math:difference ?D.
(?V ?B) log:equalTo (0 ?D).
}.
(?CL 0.5) ccd:transformer (?E ?Q).
("if_then_else"
{
?Q math:greaterThan 0.5.
}
{
("1") e:calculate ?V.
("_Q" ?Q) e:calculate ?B.
}
{
("0") e:calculate ?V.
("1-_Q" ?Q) e:calculate ?B.
}
) e:derive true.
}.
#Processed by EYE v18.1225.2318 josd
#eye --nope --turtle http://josd.github.io/eye/reasoning/ccd/train_data.ttl --n3 http://josd.github.io/eye/reasoning/ccd/train_rules.n3 --query http://josd.github.io/eye/reasoning/ccd/train_query.n3
#eye --nope --turtle train_data.ttl --n3 train_rules.n3 --query train_query.n3
PREFIX : <http://josd.github.io/eye/reasoning#>
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
PREFIX ccd: <http://josd.github.io/eye/reasoning/ccd#>
PREFIX math: <http://www.w3.org/2000/10/swap/math#>
PREFIX e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
(:input1 "abc") :ccd (2 3).
(:input1 "xyz") :ccd (2 1).
(:input2 40) :ccd (3 0).
(:input2 60) :ccd (2 4).
(:input3 (0 1)) :ccd (2 2).
(:input3 (2 3)) :ccd (1 3).
(:input4 :v1) :ccd (2 0).
(:input4 :v2) :ccd (1 1).
(:input4 :v4) :ccd (1 1).
(:input4 :v3) :ccd (1 2).
(:input5 "b") :ccd (2 0).
(:input5 "c") :ccd (0 3).
(:input5 "a") :ccd (1 1).
(:input1 "abc") ccd:model (:output1 2 3).
(:input1 "xyz") ccd:model (:output1 2 1).
(:input2 40) ccd:model (:output1 3 0).
(:input2 60) ccd:model (:output1 2 4).
(:input3 (0 1)) ccd:model (:output1 2 2).
(:input3 (2 3)) ccd:model (:output1 1 3).
(:input4 :v1) ccd:model (:output1 2 0).
(:input4 :v2) ccd:model (:output1 1 1).
(:input4 :v4) ccd:model (:output1 1 1).
(:input4 :v3) ccd:model (:output1 1 2).
(:input5 "b") ccd:model (:output1 2 0).
(:input5 "c") ccd:model (:output1 0 3).
(:input5 "a") ccd:model (:output1 1 1).
#2018-12-25T23:21:19.428Z in=53 out=13 ent=13 step=82 brake=2 inf=32370 sec=0.095 inf/sec=340737
#2018-12-30T12:42:58.907Z in=53 out=13 ent=13 step=82 brake=2 inf=36116 sec=0.087 inf/sec=415126
#ENDS
PREFIX math: <http://www.w3.org/2000/10/swap/math#>
PREFIX e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
PREFIX ccd: <http://josd.github.io/eye/reasoning/ccd#>
PREFIX : <http://josd.github.io/eye/reasoning#>
{
(?IN ?IV) :ccd (?C ?N).
(?IN ?IV) ccd:model (:output1 ?C ?N).
} <= {
(?IN ?IV) a :Input.
(?IN ?IV) a ccd:Input.
?SCOPE e:findall (1 {?CASE ?IN ?IV; :output1 1} ?CL).
?SCOPE e:findall (1 {?CASE ?IN ?IV; :output1 0} ?NL).
?CL math:sum ?C.
......
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
PREFIX ccd: <http://josd.github.io/eye/reasoning/ccd#>
PREFIX : <http://josd.github.io/eye/reasoning#>
{
......@@ -11,5 +12,5 @@ PREFIX : <http://josd.github.io/eye/reasoning#>
) list:member ?IN.
?S ?IN ?IV.
} => {
(?IN ?IV) a :Input.
(?IN ?IV) a ccd:Input.
}.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment