eyeling 1.5.42 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/cobalt-kepler-kitchen.n3 +220 -0
- package/examples/jade-eigen-loom.n3 +322 -0
- package/examples/not-includes.n3 +32 -0
- package/examples/output/cobalt-kepler-kitchen.n3 +7112 -0
- package/examples/output/cranberry-calculus.n3 +495 -495
- package/examples/output/jade-eigen-loom.n3 +4749 -0
- package/examples/output/not-includes.n3 +69 -0
- package/examples/output/ruby-runge-workshop.n3 +628 -0
- package/examples/output/topaz-markov-mill.n3 +4231 -0
- package/examples/output/traffic-skos-aggregate.n3 +3298 -0
- package/examples/output/ultramarine-simpson-forge.n3 +3936 -0
- package/examples/ruby-runge-workshop.n3 +256 -0
- package/examples/topaz-markov-mill.n3 +260 -0
- package/examples/traffic-skos-aggregate.n3 +319 -0
- package/examples/ultramarine-simpson-forge.n3 +178 -0
- package/eyeling.js +203 -133
- package/package.json +1 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# ================================================================
|
|
2
|
+
# Heavy-Math N3 Demo: "Cobalt Kepler Kitchen"
|
|
3
|
+
# ------------------------------------------------
|
|
4
|
+
# A math-stress N3 ruleset for orbital mechanics (Kepler-ish) plus
|
|
5
|
+
# a Hohmann transfer, intended to exercise strict W3C/N3 math builtins.
|
|
6
|
+
#
|
|
7
|
+
# What it does:
|
|
8
|
+
# 1) For each orbit (a,e,M):
|
|
9
|
+
# - periapsis/apopsis
|
|
10
|
+
# - period (Kepler's 3rd law)
|
|
11
|
+
# - specific orbital energy
|
|
12
|
+
# - specific angular momentum
|
|
13
|
+
# - approximate E (eccentric anomaly) from M using a series
|
|
14
|
+
# - true anomaly nu via tan-half-angle
|
|
15
|
+
# - radius r and (x,y) in orbital plane
|
|
16
|
+
# 2) Computes average period across the orbit list
|
|
17
|
+
# 3) Hohmann transfer between two circular radii: dv1, dv2, total dv, time
|
|
18
|
+
#
|
|
19
|
+
# Notes:
|
|
20
|
+
# - Uses only: math:, list:, log:
|
|
21
|
+
# - Numbers are written as numeric literals (strict typing friendly).
|
|
22
|
+
# ================================================================
|
|
23
|
+
|
|
24
|
+
@prefix : <http://example.org/cobalt-kepler#> .
|
|
25
|
+
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
|
|
26
|
+
@prefix list: <http://www.w3.org/2000/10/swap/list#> .
|
|
27
|
+
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
|
|
28
|
+
|
|
29
|
+
############
|
|
30
|
+
# DATA (units: km, s; mu in km^3/s^2)
|
|
31
|
+
############
|
|
32
|
+
|
|
33
|
+
:Earth :mu 398600.4418 .
|
|
34
|
+
|
|
35
|
+
:OrbitSet :orbits (
|
|
36
|
+
[ :name "LEO" ; :a 7000.0 ; :e 0.001 ; :M 1.0 ]
|
|
37
|
+
[ :name "MEO" ; :a 26560.0 ; :e 0.01 ; :M 0.3 ]
|
|
38
|
+
[ :name "GEO" ; :a 42164.0 ; :e 0.0001 ; :M 2.0 ]
|
|
39
|
+
) .
|
|
40
|
+
|
|
41
|
+
:Transfer1 :centralBody :Earth ;
|
|
42
|
+
:r1 7000.0 ;
|
|
43
|
+
:r2 42164.0 .
|
|
44
|
+
|
|
45
|
+
############
|
|
46
|
+
# (1) ORBIT METRICS + STATE AT MEAN ANOMALY
|
|
47
|
+
############
|
|
48
|
+
|
|
49
|
+
{
|
|
50
|
+
:Earth :mu ?mu .
|
|
51
|
+
:OrbitSet :orbits ?os .
|
|
52
|
+
?os list:member ?orb .
|
|
53
|
+
?orb :a ?a ; :e ?e ; :M ?M .
|
|
54
|
+
|
|
55
|
+
# periapsis/apopsis: rp=a(1-e), ra=a(1+e)
|
|
56
|
+
(1.0 ?e) math:difference ?oneMinusE .
|
|
57
|
+
(1.0 ?e) math:sum ?onePlusE .
|
|
58
|
+
(?a ?oneMinusE) math:product ?rp .
|
|
59
|
+
(?a ?onePlusE) math:product ?ra .
|
|
60
|
+
|
|
61
|
+
# period T = 2*pi*sqrt(a^3/mu)
|
|
62
|
+
(?a 3.0) math:exponentiation ?a3 .
|
|
63
|
+
(?a3 ?mu) math:quotient ?a3OverMu .
|
|
64
|
+
(?a3OverMu 0.5) math:exponentiation ?sqrtTerm .
|
|
65
|
+
(2.0 3.141592653589793) math:product ?twoPi .
|
|
66
|
+
(?twoPi ?sqrtTerm) math:product ?T .
|
|
67
|
+
|
|
68
|
+
# specific orbital energy: eps = -mu/(2a)
|
|
69
|
+
(2.0 ?a) math:product ?twoA .
|
|
70
|
+
(?mu ?twoA) math:quotient ?muOver2a .
|
|
71
|
+
(0.0 ?muOver2a) math:difference ?eps .
|
|
72
|
+
|
|
73
|
+
# specific angular momentum: h = sqrt(mu*a*(1-e^2))
|
|
74
|
+
(?e 2.0) math:exponentiation ?e2 .
|
|
75
|
+
(1.0 ?e2) math:difference ?oneMinusE2 .
|
|
76
|
+
(?mu ?a) math:product ?muA .
|
|
77
|
+
(?muA ?oneMinusE2) math:product ?muAterm .
|
|
78
|
+
(?muAterm 0.5) math:exponentiation ?h .
|
|
79
|
+
|
|
80
|
+
# Approx eccentric anomaly from mean anomaly (series):
|
|
81
|
+
# E ≈ M + e*sin(M) + 0.5*e^2*sin(2M)
|
|
82
|
+
?M math:sin ?sinM .
|
|
83
|
+
(?e ?sinM) math:product ?eSinM .
|
|
84
|
+
(2.0 ?M) math:product ?twoM .
|
|
85
|
+
?twoM math:sin ?sin2M .
|
|
86
|
+
(?e2 ?sin2M) math:product ?e2Sin2M .
|
|
87
|
+
(0.5 ?e2Sin2M) math:product ?halfE2Sin2M .
|
|
88
|
+
(?M ?eSinM) math:sum ?Mplus .
|
|
89
|
+
(?Mplus ?halfE2Sin2M) math:sum ?E .
|
|
90
|
+
|
|
91
|
+
# True anomaly via tan-half-angle:
|
|
92
|
+
# tan(nu/2) = sqrt((1+e)/(1-e)) * tan(E/2)
|
|
93
|
+
(1.0 ?e) math:sum ?onePlusE2a .
|
|
94
|
+
(1.0 ?e) math:difference ?oneMinusE2a .
|
|
95
|
+
(?onePlusE2a ?oneMinusE2a) math:quotient ?ratio .
|
|
96
|
+
(?ratio 0.5) math:exponentiation ?factor .
|
|
97
|
+
|
|
98
|
+
(2.0 ?E) math:quotient ?Ehalf .
|
|
99
|
+
?Ehalf math:tan ?tanEhalf .
|
|
100
|
+
(?factor ?tanEhalf) math:product ?tanNuHalf .
|
|
101
|
+
?tanNuHalf math:atan ?nuHalf .
|
|
102
|
+
(2.0 ?nuHalf) math:product ?nu .
|
|
103
|
+
|
|
104
|
+
# r = a(1 - e*cos(E))
|
|
105
|
+
?E math:cos ?cosE .
|
|
106
|
+
(?e ?cosE) math:product ?eCosE .
|
|
107
|
+
(1.0 ?eCosE) math:difference ?oneMinusECosE .
|
|
108
|
+
(?a ?oneMinusECosE) math:product ?r .
|
|
109
|
+
|
|
110
|
+
# position in orbital plane: x=r*cos(nu), y=r*sin(nu)
|
|
111
|
+
?nu math:cos ?cosNu .
|
|
112
|
+
?nu math:sin ?sinNu .
|
|
113
|
+
(?r ?cosNu) math:product ?x .
|
|
114
|
+
(?r ?sinNu) math:product ?y .
|
|
115
|
+
}
|
|
116
|
+
=>
|
|
117
|
+
{
|
|
118
|
+
?orb :periapsis ?rp ;
|
|
119
|
+
:apoapsis ?ra ;
|
|
120
|
+
:period ?T ;
|
|
121
|
+
:specificEnergy ?eps ;
|
|
122
|
+
:angularMomentum ?h ;
|
|
123
|
+
:stateAtM [
|
|
124
|
+
:M ?M ;
|
|
125
|
+
:E ?E ;
|
|
126
|
+
:nu ?nu ;
|
|
127
|
+
:r ?r ;
|
|
128
|
+
:x ?x ;
|
|
129
|
+
:y ?y
|
|
130
|
+
] .
|
|
131
|
+
} .
|
|
132
|
+
|
|
133
|
+
############
|
|
134
|
+
# (2) AVERAGE PERIOD ACROSS ORBITS
|
|
135
|
+
############
|
|
136
|
+
|
|
137
|
+
{
|
|
138
|
+
:OrbitSet :orbits ?os .
|
|
139
|
+
|
|
140
|
+
( ?T { ?os list:member ?orb . ?orb :period ?T . } ?Ts ) log:collectAllIn _:avgScope .
|
|
141
|
+
?Ts list:length ?n .
|
|
142
|
+
?Ts math:sum ?sumT .
|
|
143
|
+
(?sumT ?n) math:quotient ?avgT .
|
|
144
|
+
}
|
|
145
|
+
=>
|
|
146
|
+
{
|
|
147
|
+
:OrbitSet :avgPeriod ?avgT .
|
|
148
|
+
} .
|
|
149
|
+
|
|
150
|
+
############
|
|
151
|
+
# (3) HOHMANN TRANSFER (circular r1 -> r2)
|
|
152
|
+
#
|
|
153
|
+
# aT = (r1+r2)/2
|
|
154
|
+
# v1 = sqrt(mu/r1), v2 = sqrt(mu/r2)
|
|
155
|
+
# vT1 = sqrt(mu*(2/r1 - 1/aT))
|
|
156
|
+
# vT2 = sqrt(mu*(2/r2 - 1/aT))
|
|
157
|
+
# dv1 = vT1 - v1
|
|
158
|
+
# dv2 = v2 - vT2
|
|
159
|
+
# dvTotal = |dv1| + |dv2|
|
|
160
|
+
# tTransfer = pi * sqrt(aT^3/mu)
|
|
161
|
+
############
|
|
162
|
+
|
|
163
|
+
{
|
|
164
|
+
:Transfer1 :centralBody :Earth ; :r1 ?r1 ; :r2 ?r2 .
|
|
165
|
+
:Earth :mu ?mu .
|
|
166
|
+
|
|
167
|
+
(?r1 ?r2) math:sum ?r1r2 .
|
|
168
|
+
(?r1r2 2.0) math:quotient ?aT .
|
|
169
|
+
|
|
170
|
+
# v1, v2
|
|
171
|
+
(?mu ?r1) math:quotient ?muOverR1 .
|
|
172
|
+
(?muOverR1 0.5) math:exponentiation ?v1 .
|
|
173
|
+
(?mu ?r2) math:quotient ?muOverR2 .
|
|
174
|
+
(?muOverR2 0.5) math:exponentiation ?v2 .
|
|
175
|
+
|
|
176
|
+
# vT at r1: sqrt(mu*(2/r1 - 1/aT))
|
|
177
|
+
(2.0 ?r1) math:quotient ?twoOverR1 .
|
|
178
|
+
(1.0 ?aT) math:quotient ?oneOverAT .
|
|
179
|
+
(?twoOverR1 ?oneOverAT) math:difference ?term1 .
|
|
180
|
+
(?mu ?term1) math:product ?muTerm1 .
|
|
181
|
+
(?muTerm1 0.5) math:exponentiation ?vT1 .
|
|
182
|
+
|
|
183
|
+
# vT at r2
|
|
184
|
+
(2.0 ?r2) math:quotient ?twoOverR2 .
|
|
185
|
+
(?twoOverR2 ?oneOverAT) math:difference ?term2 .
|
|
186
|
+
(?mu ?term2) math:product ?muTerm2 .
|
|
187
|
+
(?muTerm2 0.5) math:exponentiation ?vT2 .
|
|
188
|
+
|
|
189
|
+
# deltas
|
|
190
|
+
(?vT1 ?v1) math:difference ?dv1 .
|
|
191
|
+
(?v2 ?vT2) math:difference ?dv2 .
|
|
192
|
+
?dv1 math:absoluteValue ?adv1 .
|
|
193
|
+
?dv2 math:absoluteValue ?adv2 .
|
|
194
|
+
(?adv1 ?adv2) math:sum ?dvTotal .
|
|
195
|
+
|
|
196
|
+
# transfer time: pi*sqrt(aT^3/mu)
|
|
197
|
+
(?aT 3.0) math:exponentiation ?aT3 .
|
|
198
|
+
(?aT3 ?mu) math:quotient ?aT3OverMu .
|
|
199
|
+
(?aT3OverMu 0.5) math:exponentiation ?sqrtTT .
|
|
200
|
+
(3.141592653589793 ?sqrtTT) math:product ?tTransfer .
|
|
201
|
+
}
|
|
202
|
+
=>
|
|
203
|
+
{
|
|
204
|
+
:Transfer1 :transferSemiMajorAxis ?aT ;
|
|
205
|
+
:v1 ?v1 ; :v2 ?v2 ;
|
|
206
|
+
:vTransferAtR1 ?vT1 ;
|
|
207
|
+
:vTransferAtR2 ?vT2 ;
|
|
208
|
+
:deltaV1 ?dv1 ;
|
|
209
|
+
:deltaV2 ?dv2 ;
|
|
210
|
+
:deltaVTotal ?dvTotal ;
|
|
211
|
+
:timeOfFlight ?tTransfer .
|
|
212
|
+
} .
|
|
213
|
+
|
|
214
|
+
############
|
|
215
|
+
# STRICTNESS REGRESSION HOOK (should fail in strict math)
|
|
216
|
+
############
|
|
217
|
+
# {
|
|
218
|
+
# "7000"^^<http://example.org/not-a-number> math:quotient 2.0 .
|
|
219
|
+
# } => { :bad :datatype :accepted . } .
|
|
220
|
+
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# ================================================================
|
|
2
|
+
# Heavy-Math N3 Demo: "Jade Eigen Loom"
|
|
3
|
+
# ------------------------------------------------
|
|
4
|
+
# A math-stress N3 ruleset for 2D PCA (principal component analysis)
|
|
5
|
+
# using only standard N3 builtins (math:, list:, log:).
|
|
6
|
+
#
|
|
7
|
+
# What it does:
|
|
8
|
+
# 1) Mean-center a cloud of 2D points and compute covariance matrix:
|
|
9
|
+
# [ covXX covXY ]
|
|
10
|
+
# [ covXY covYY ]
|
|
11
|
+
# 2) Closed-form eigenvalues λ1, λ2 (principal variances)
|
|
12
|
+
# 3) Principal axis angle θ (piecewise, without atan2)
|
|
13
|
+
# 4) Per-point PCA scores (u,v) and Mahalanobis distance squared:
|
|
14
|
+
# md2 = u^2/λ1 + v^2/λ2
|
|
15
|
+
# Flags outliers if md2 > 5.991 (≈ 95% ellipse, df=2)
|
|
16
|
+
# 5) Ellipse radii for 1σ and 95% (scaled by sqrt(5.991)), plus area
|
|
17
|
+
#
|
|
18
|
+
# Notes:
|
|
19
|
+
# - Uses only: math:, list:, log:
|
|
20
|
+
# - Designed to be strict-datatype friendly: all numbers are numeric literals.
|
|
21
|
+
# ================================================================
|
|
22
|
+
|
|
23
|
+
@prefix : <http://example.org/jade-eigen-loom#> .
|
|
24
|
+
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
|
|
25
|
+
@prefix list: <http://www.w3.org/2000/10/swap/list#> .
|
|
26
|
+
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
|
|
27
|
+
|
|
28
|
+
############
|
|
29
|
+
# DATA
|
|
30
|
+
############
|
|
31
|
+
|
|
32
|
+
:PCA1 :points (
|
|
33
|
+
[ :id 1 ; :x 2.0 ; :y 1.0 ]
|
|
34
|
+
[ :id 2 ; :x 3.0 ; :y 2.0 ]
|
|
35
|
+
[ :id 3 ; :x 4.0 ; :y 3.2 ]
|
|
36
|
+
[ :id 4 ; :x 5.0 ; :y 5.1 ]
|
|
37
|
+
[ :id 5 ; :x 6.0 ; :y 7.9 ]
|
|
38
|
+
[ :id 6 ; :x 7.0 ; :y 13.0 ]
|
|
39
|
+
[ :id 7 ; :x 20.0 ; :y -3.0 ] # outlier-ish
|
|
40
|
+
) .
|
|
41
|
+
|
|
42
|
+
############
|
|
43
|
+
# (1) MEANS + COVARIANCE
|
|
44
|
+
# covXX = Σ(dx^2)/n, covYY = Σ(dy^2)/n, covXY = Σ(dx*dy)/n (population form)
|
|
45
|
+
############
|
|
46
|
+
|
|
47
|
+
{
|
|
48
|
+
:PCA1 :points ?pts .
|
|
49
|
+
?pts list:length ?n .
|
|
50
|
+
|
|
51
|
+
( ?x { ?pts list:member ?p . ?p :x ?x . } ?xs ) log:collectAllIn _:m1 .
|
|
52
|
+
( ?y { ?pts list:member ?p . ?p :y ?y . } ?ys ) log:collectAllIn _:m1 .
|
|
53
|
+
|
|
54
|
+
?xs math:sum ?sumX .
|
|
55
|
+
?ys math:sum ?sumY .
|
|
56
|
+
(?sumX ?n) math:quotient ?meanX .
|
|
57
|
+
(?sumY ?n) math:quotient ?meanY .
|
|
58
|
+
|
|
59
|
+
( ?dx2 {
|
|
60
|
+
?pts list:member ?p . ?p :x ?x .
|
|
61
|
+
(?x ?meanX) math:difference ?dx .
|
|
62
|
+
(?dx 2.0) math:exponentiation ?dx2 .
|
|
63
|
+
} ?dx2s ) log:collectAllIn _:m1 .
|
|
64
|
+
?dx2s math:sum ?ssXX .
|
|
65
|
+
(?ssXX ?n) math:quotient ?covXX .
|
|
66
|
+
|
|
67
|
+
( ?dy2 {
|
|
68
|
+
?pts list:member ?p . ?p :y ?y .
|
|
69
|
+
(?y ?meanY) math:difference ?dy .
|
|
70
|
+
(?dy 2.0) math:exponentiation ?dy2 .
|
|
71
|
+
} ?dy2s ) log:collectAllIn _:m1 .
|
|
72
|
+
?dy2s math:sum ?ssYY .
|
|
73
|
+
(?ssYY ?n) math:quotient ?covYY .
|
|
74
|
+
|
|
75
|
+
( ?dxdy {
|
|
76
|
+
?pts list:member ?p .
|
|
77
|
+
?p :x ?x ; :y ?y .
|
|
78
|
+
(?x ?meanX) math:difference ?dx .
|
|
79
|
+
(?y ?meanY) math:difference ?dy .
|
|
80
|
+
(?dx ?dy) math:product ?dxdy .
|
|
81
|
+
} ?dxdys ) log:collectAllIn _:m1 .
|
|
82
|
+
?dxdys math:sum ?ssXY .
|
|
83
|
+
(?ssXY ?n) math:quotient ?covXY .
|
|
84
|
+
}
|
|
85
|
+
=>
|
|
86
|
+
{
|
|
87
|
+
:PCA1 :n ?n ;
|
|
88
|
+
:meanX ?meanX ;
|
|
89
|
+
:meanY ?meanY ;
|
|
90
|
+
:covXX ?covXX ;
|
|
91
|
+
:covYY ?covYY ;
|
|
92
|
+
:covXY ?covXY .
|
|
93
|
+
} .
|
|
94
|
+
|
|
95
|
+
############
|
|
96
|
+
# (2) EIGENVALUES of 2x2 symmetric covariance matrix
|
|
97
|
+
# tr = a + d
|
|
98
|
+
# det = a*d - b^2
|
|
99
|
+
# disc = tr^2 - 4*det
|
|
100
|
+
# λ1 = (tr + sqrt(disc))/2
|
|
101
|
+
# λ2 = (tr - sqrt(disc))/2
|
|
102
|
+
############
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
:PCA1 :covXX ?a ; :covYY ?d ; :covXY ?b .
|
|
106
|
+
|
|
107
|
+
(?a ?d) math:sum ?tr .
|
|
108
|
+
(?a ?d) math:product ?ad .
|
|
109
|
+
(?b 2.0) math:exponentiation ?b2 .
|
|
110
|
+
(?ad ?b2) math:difference ?det .
|
|
111
|
+
|
|
112
|
+
(?tr 2.0) math:exponentiation ?tr2 .
|
|
113
|
+
(4.0 ?det) math:product ?fourDet .
|
|
114
|
+
(?tr2 ?fourDet) math:difference ?disc .
|
|
115
|
+
(?disc 0.5) math:exponentiation ?sqrtDisc .
|
|
116
|
+
|
|
117
|
+
(?tr ?sqrtDisc) math:sum ?trPlus .
|
|
118
|
+
(?tr ?sqrtDisc) math:difference ?trMinus .
|
|
119
|
+
(?trPlus 2.0) math:quotient ?lambda1 .
|
|
120
|
+
(?trMinus 2.0) math:quotient ?lambda2 .
|
|
121
|
+
|
|
122
|
+
(?lambda1 ?tr) math:quotient ?explained1 . # λ1 / (λ1+λ2) since tr=λ1+λ2
|
|
123
|
+
}
|
|
124
|
+
=>
|
|
125
|
+
{
|
|
126
|
+
:PCA1 :lambda1 ?lambda1 ;
|
|
127
|
+
:lambda2 ?lambda2 ;
|
|
128
|
+
:explainedVar1 ?explained1 .
|
|
129
|
+
} .
|
|
130
|
+
|
|
131
|
+
############
|
|
132
|
+
# (3) PRINCIPAL AXIS ANGLE θ
|
|
133
|
+
# θ = 0.5 * atan2(2b, a-d)
|
|
134
|
+
# We emulate atan2 with piecewise rules using atan(ratio) and π adjustments.
|
|
135
|
+
############
|
|
136
|
+
|
|
137
|
+
# Common helpers (only when diff != 0): phi = atan((2b)/(a-d))
|
|
138
|
+
{
|
|
139
|
+
:PCA1 :covXX ?a ; :covYY ?d ; :covXY ?b .
|
|
140
|
+
(?a ?d) math:difference ?diff .
|
|
141
|
+
?diff math:notEqualTo 0.0 .
|
|
142
|
+
(2.0 ?b) math:product ?twoB .
|
|
143
|
+
(?twoB ?diff) math:quotient ?ratio .
|
|
144
|
+
?ratio math:atan ?phi .
|
|
145
|
+
}
|
|
146
|
+
=>
|
|
147
|
+
{
|
|
148
|
+
:PCA1 :_phi ?phi ;
|
|
149
|
+
:_diff ?diff ;
|
|
150
|
+
:_twoB ?twoB ;
|
|
151
|
+
:_b ?b .
|
|
152
|
+
} .
|
|
153
|
+
|
|
154
|
+
# Case 1: diff > 0 => theta = 0.5*phi
|
|
155
|
+
{
|
|
156
|
+
:PCA1 :_phi ?phi ; :_diff ?diff .
|
|
157
|
+
?diff math:greaterThan 0.0 .
|
|
158
|
+
(0.5 ?phi) math:product ?theta .
|
|
159
|
+
?theta math:degrees ?thetaDeg .
|
|
160
|
+
}
|
|
161
|
+
=>
|
|
162
|
+
{
|
|
163
|
+
:PCA1 :thetaRad ?theta ;
|
|
164
|
+
:thetaDeg ?thetaDeg .
|
|
165
|
+
} .
|
|
166
|
+
|
|
167
|
+
# Case 2: diff < 0 and b >= 0 => theta = 0.5*(phi + pi)
|
|
168
|
+
{
|
|
169
|
+
:PCA1 :_phi ?phi ; :_diff ?diff ; :_b ?b .
|
|
170
|
+
?diff math:lessThan 0.0 .
|
|
171
|
+
?b math:notLessThan 0.0 .
|
|
172
|
+
(?phi 3.141592653589793) math:sum ?phiP .
|
|
173
|
+
(0.5 ?phiP) math:product ?theta .
|
|
174
|
+
?theta math:degrees ?thetaDeg .
|
|
175
|
+
}
|
|
176
|
+
=>
|
|
177
|
+
{
|
|
178
|
+
:PCA1 :thetaRad ?theta ;
|
|
179
|
+
:thetaDeg ?thetaDeg .
|
|
180
|
+
} .
|
|
181
|
+
|
|
182
|
+
# Case 3: diff < 0 and b < 0 => theta = 0.5*(phi - pi)
|
|
183
|
+
{
|
|
184
|
+
:PCA1 :_phi ?phi ; :_diff ?diff ; :_b ?b .
|
|
185
|
+
?diff math:lessThan 0.0 .
|
|
186
|
+
?b math:lessThan 0.0 .
|
|
187
|
+
(?phi 3.141592653589793) math:difference ?phiM .
|
|
188
|
+
(0.5 ?phiM) math:product ?theta .
|
|
189
|
+
?theta math:degrees ?thetaDeg .
|
|
190
|
+
}
|
|
191
|
+
=>
|
|
192
|
+
{
|
|
193
|
+
:PCA1 :thetaRad ?theta ;
|
|
194
|
+
:thetaDeg ?thetaDeg .
|
|
195
|
+
} .
|
|
196
|
+
|
|
197
|
+
# Case 4: diff == 0 and b > 0 => theta = +pi/4
|
|
198
|
+
{
|
|
199
|
+
:PCA1 :covXX ?a ; :covYY ?d ; :covXY ?b .
|
|
200
|
+
(?a ?d) math:difference ?diff .
|
|
201
|
+
?diff math:equalTo 0.0 .
|
|
202
|
+
?b math:greaterThan 0.0 .
|
|
203
|
+
0.7853981633974483 math:degrees ?thetaDeg .
|
|
204
|
+
}
|
|
205
|
+
=>
|
|
206
|
+
{
|
|
207
|
+
:PCA1 :thetaRad 0.7853981633974483 ;
|
|
208
|
+
:thetaDeg ?thetaDeg .
|
|
209
|
+
} .
|
|
210
|
+
|
|
211
|
+
# Case 5: diff == 0 and b < 0 => theta = -pi/4
|
|
212
|
+
{
|
|
213
|
+
:PCA1 :covXX ?a ; :covYY ?d ; :covXY ?b .
|
|
214
|
+
(?a ?d) math:difference ?diff .
|
|
215
|
+
?diff math:equalTo 0.0 .
|
|
216
|
+
?b math:lessThan 0.0 .
|
|
217
|
+
(0.0 0.7853981633974483) math:difference ?theta .
|
|
218
|
+
?theta math:degrees ?thetaDeg .
|
|
219
|
+
}
|
|
220
|
+
=>
|
|
221
|
+
{
|
|
222
|
+
:PCA1 :thetaRad ?theta ;
|
|
223
|
+
:thetaDeg ?thetaDeg .
|
|
224
|
+
} .
|
|
225
|
+
|
|
226
|
+
# Case 6: diff == 0 and b == 0 => theta = 0
|
|
227
|
+
{
|
|
228
|
+
:PCA1 :covXX ?a ; :covYY ?d ; :covXY ?b .
|
|
229
|
+
(?a ?d) math:difference ?diff .
|
|
230
|
+
?diff math:equalTo 0.0 .
|
|
231
|
+
?b math:equalTo 0.0 .
|
|
232
|
+
0.0 math:degrees ?thetaDeg .
|
|
233
|
+
}
|
|
234
|
+
=>
|
|
235
|
+
{
|
|
236
|
+
:PCA1 :thetaRad 0.0 ;
|
|
237
|
+
:thetaDeg ?thetaDeg .
|
|
238
|
+
} .
|
|
239
|
+
|
|
240
|
+
############
|
|
241
|
+
# (4) PER-POINT PCA SCORES + MAHALANOBIS DISTANCE AND OUTLIERS
|
|
242
|
+
# u = dx*cosθ + dy*sinθ
|
|
243
|
+
# v = -dx*sinθ + dy*cosθ
|
|
244
|
+
# md2 = u^2/λ1 + v^2/λ2
|
|
245
|
+
# outlier if md2 > 5.991 (≈ 95% ellipse, df=2)
|
|
246
|
+
############
|
|
247
|
+
|
|
248
|
+
{
|
|
249
|
+
:PCA1 :points ?pts ;
|
|
250
|
+
:meanX ?mx ; :meanY ?my ;
|
|
251
|
+
:thetaRad ?theta ;
|
|
252
|
+
:lambda1 ?l1 ; :lambda2 ?l2 .
|
|
253
|
+
|
|
254
|
+
?theta math:cos ?c .
|
|
255
|
+
?theta math:sin ?s .
|
|
256
|
+
|
|
257
|
+
?pts list:member ?p .
|
|
258
|
+
?p :x ?x ; :y ?y .
|
|
259
|
+
|
|
260
|
+
(?x ?mx) math:difference ?dx .
|
|
261
|
+
(?y ?my) math:difference ?dy .
|
|
262
|
+
|
|
263
|
+
(?dx ?c) math:product ?dxC .
|
|
264
|
+
(?dy ?s) math:product ?dyS .
|
|
265
|
+
(?dxC ?dyS) math:sum ?u .
|
|
266
|
+
|
|
267
|
+
(?dx ?s) math:product ?dxS .
|
|
268
|
+
(0.0 ?dxS) math:difference ?negDxS .
|
|
269
|
+
(?dy ?c) math:product ?dyC .
|
|
270
|
+
(?negDxS ?dyC) math:sum ?v .
|
|
271
|
+
|
|
272
|
+
(?u 2.0) math:exponentiation ?u2 .
|
|
273
|
+
(?v 2.0) math:exponentiation ?v2 .
|
|
274
|
+
(?u2 ?l1) math:quotient ?u2Over .
|
|
275
|
+
(?v2 ?l2) math:quotient ?v2Over .
|
|
276
|
+
(?u2Over ?v2Over) math:sum ?md2 .
|
|
277
|
+
}
|
|
278
|
+
=>
|
|
279
|
+
{
|
|
280
|
+
:PCA1 :score [ :point ?p ; :u ?u ; :v ?v ; :md2 ?md2 ] .
|
|
281
|
+
} .
|
|
282
|
+
|
|
283
|
+
{
|
|
284
|
+
:PCA1 :score [ :point ?p ; :u ?u ; :v ?v ; :md2 ?md2 ] .
|
|
285
|
+
?md2 math:greaterThan 5.991 .
|
|
286
|
+
}
|
|
287
|
+
=>
|
|
288
|
+
{
|
|
289
|
+
:PCA1 :outlier [ :point ?p ; :u ?u ; :v ?v ; :md2 ?md2 ; :threshold 5.991 ] .
|
|
290
|
+
} .
|
|
291
|
+
|
|
292
|
+
############
|
|
293
|
+
# (5) ELLIPSE RADII (1σ and ~95%) + AREA
|
|
294
|
+
############
|
|
295
|
+
|
|
296
|
+
{
|
|
297
|
+
:PCA1 :lambda1 ?l1 ; :lambda2 ?l2 .
|
|
298
|
+
|
|
299
|
+
(?l1 0.5) math:exponentiation ?sigma1 .
|
|
300
|
+
(?l2 0.5) math:exponentiation ?sigma2 .
|
|
301
|
+
|
|
302
|
+
(5.991 0.5) math:exponentiation ?k95 .
|
|
303
|
+
(?k95 ?sigma1) math:product ?a95 .
|
|
304
|
+
(?k95 ?sigma2) math:product ?b95 .
|
|
305
|
+
|
|
306
|
+
(3.141592653589793 ?a95) math:product ?piA .
|
|
307
|
+
(?piA ?b95) math:product ?area95 .
|
|
308
|
+
}
|
|
309
|
+
=>
|
|
310
|
+
{
|
|
311
|
+
:PCA1 :sigma1 ?sigma1 ;
|
|
312
|
+
:sigma2 ?sigma2 ;
|
|
313
|
+
:ellipse95 [ :k ?k95 ; :a ?a95 ; :b ?b95 ; :area ?area95 ] .
|
|
314
|
+
} .
|
|
315
|
+
|
|
316
|
+
############
|
|
317
|
+
# STRICTNESS REGRESSION HOOK (should fail in strict math)
|
|
318
|
+
############
|
|
319
|
+
# {
|
|
320
|
+
# "1"^^<http://example.org/not-a-number> math:sum 2.0 .
|
|
321
|
+
# } => { :bad :datatype :accepted . } .
|
|
322
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# =======================
|
|
2
|
+
# log:notIncludes example
|
|
3
|
+
# =======================
|
|
4
|
+
|
|
5
|
+
@prefix : <http://example.org/> .
|
|
6
|
+
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
|
|
7
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
8
|
+
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
|
|
9
|
+
|
|
10
|
+
{
|
|
11
|
+
1 math:equalTo 1.
|
|
12
|
+
}
|
|
13
|
+
=>
|
|
14
|
+
{
|
|
15
|
+
:x :y 1 .
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
:x :y 1
|
|
19
|
+
}
|
|
20
|
+
=>
|
|
21
|
+
{
|
|
22
|
+
:a :b :c
|
|
23
|
+
}.
|
|
24
|
+
}.
|
|
25
|
+
|
|
26
|
+
{
|
|
27
|
+
?SCOPE log:notIncludes { :a :b :c }.
|
|
28
|
+
}
|
|
29
|
+
=>
|
|
30
|
+
{
|
|
31
|
+
:test :is false
|
|
32
|
+
}.
|