Commit 275dee48 authored by Uwe Köckemann's avatar Uwe Köckemann
Browse files

Linear algebra, regression, test cases, planning+resources example, csp solver, ...

parent 923b1fd5
...@@ -5,6 +5,8 @@ AI problems, data and how AI methods are connected in order to solve ...@@ -5,6 +5,8 @@ AI problems, data and how AI methods are connected in order to solve
problems. This allows to create complex integrated AI systems by combining problems. This allows to create complex integrated AI systems by combining
robust and well-studied components. robust and well-studied components.
You can find the most recent version under [[http:www.aiddl.org][aiddl.org]].
* Overview * Overview
#+CAPTION: Overview of AIDDL components and interactions. #+CAPTION: Overview of AIDDL components and interactions.
...@@ -240,8 +242,6 @@ readability we assume name spaces ~eval.aiddl~ and ~type.aiddl~ are used): ...@@ -240,8 +242,6 @@ readability we assume name spaces ~eval.aiddl~ and ~type.aiddl~ are used):
(<= #self 10))) (<= #self 10)))
#+END_EXAMPLE #+END_EXAMPLE
* Support * Support
Contact Uwe Köckemann (uwe.kockemann_at_oru.se) in case of questions, Contact Uwe Köckemann (uwe.kockemann_at_oru.se) in case of questions,
suggestions, feature requests, bug reports. suggestions, feature requests, bug reports.
......
...@@ -3,3 +3,46 @@ ...@@ -3,3 +3,46 @@
The AIDDL Common Library contains type definitions, implementations and test The AIDDL Common Library contains type definitions, implementations and test
cases for many common AI algorithms. These implementations can be used as cases for many common AI algorithms. These implementations can be used as
building blocks for fast prototyping of integrated AI systems. building blocks for fast prototyping of integrated AI systems.
* AIDDL
Types, interfaces, and functions written in AIDDL.
** Math
*** Graphs
| URI | Description | Example(s) |
|------------------------+-----------------------------------+-------------------------|
| org.aiddl.common.graph | | |
|------------------------+-----------------------------------+-------------------------|
| Node | A node in a graph | v1, (at a b) |
| UndirectedEdge | An undirected edge | {v1 v2} |
| DirectedEdge | A directed edge | (v1 v2) |
| Graph | Undirected Graph | (V:{v1 v2} E:{{v1 v2}}) |
| DiGraph | Directed Graph | (V:{v1 v2} E:{(v1 v2)}) |
| WeightMap | Map from Edge to weight | {(v1 v2):3 (v1 v3):2} |
| Distance Map | Map from Node to distance | {v1:0 v2:3 v3:2} |
| Predecessor Map | Map from Node to predecessor node | {v1:NIL v2:v1 v3:v1} |
** Automated Planning
*** State-Variable
** Machine Learning
*** Supervised
**** Decision Tree
* Java
Functions implemented as a Java library.
** Math
*** Graphs
**** Bellman Ford
- Implements :: org.aiddl.common.math.graph.single-source-shortest-path
- Input :: (Graph, Weight Map, Node)
- Output :: (Node-Distance Map, Node-Predecessor Map)
** Machine Learning
*** Decision Tree Learner
*** Decision Tree Classifier
** Automated Planning
*** State-Variable
(#mod self org.aiddl.common) (#mod self org.aiddl.common)
(#nms EVAL "eval.aiddl") (#nms EVAL org.aiddl.eval)
(#def Map (#def Map
(and (and
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
(#def MapGen (#def MapGen
(match (?KT ?VT) #self (match (?KT ?VT) #self
^(lambda ?M ($MapOf (?KT ?VT ?M))))) (lambda ?M ($MapOf (?KT ?VT ?M)))))
(#def MapOf (#def MapOf
(match (?KeyType ?ValueType ?Map) #self (match (?KeyType ?ValueType ?Map) #self
...@@ -24,16 +24,21 @@ ...@@ -24,16 +24,21 @@
))))) )))))
(#def SetGen (#def SetGen
^(lambda ?Set (lambda ?Set
($SetOf #self ?Set) )) (and
(type ?Set ^set)
(forall ?e ?Set (type ?e #self)))))
(#def (SetOf ?Type ?Set) (#def (SetOf ?Type ?Set)
(and (and
(type ?Set ^set) (type ?Set ^set)
(forall ?e ?Set (type ?e ?Type)))) (forall ?e ?Set (type ?e ?Type))))
(#def ListGen (#def ListGen
^(lambda ?List (lambda ?List
(ListOf ?List #self) )) (and
(type ?List ^list)
(forall ?e ?List (type ?e #self)))))
(#def (ListOf ?Type) (#def (ListOf ?Type)
(and (and
...@@ -49,7 +54,18 @@ ...@@ -49,7 +54,18 @@
))) )))
(#def KeyValuedType (#def KeyValuedType
^(lambda ?x (lambda ?x
(forall ?k:?t #self (forall ?k:?t #self
(call ?t (get-key ?k ?x))) )) (call ?t (get-key ?k ?x))) ))
(#def TypedTuple
(lambda ?x
(forall ?i (domain {min:0 inc:1 max:(- (size #self) 1)})
(type (get-idx ?i ?x) (get-idx ?i #self))
)))
(#def MapFunctionGen
(lambda ?k
(get-key ?k #self default:NIL)))
\ No newline at end of file
(#mod self org.aiddl.common.learning.decision-tree) (#mod self org.aiddl.common.learning.supervised.decision-tree)
(#nms EVAL org.aiddl.eval) (#nms EVAL org.aiddl.eval-ht)
(#req SL org.aiddl.common.learning.supervised)
(#def Comparator (in #self {= < > >= <=})) (#def Comparator (in #self {= < > >= <=}))
...@@ -21,3 +23,11 @@ ...@@ -21,3 +23,11 @@
(type #self #list) (type #self #list)
(forall ?e #self (type ?e Decision)) (forall ?e #self (type ?e Decision))
))) )))
(#interface
decision-tree-learner
(
uri:org.aiddl.common.learning.supervised.decision-tree.learner
input:Problem@SL
output:$DecisionTree
))
\ No newline at end of file
(#mod self org.aiddl.common.learning.supervised.linear-regression)
(#req LA org.aiddl.common.math.linear-algebra)
(#req SL org.aiddl.common.learning.supervised)
(#interface
linear-regression-learner
(
uri:org.aiddl.common.learning.supervised.linear-regression.learner
input:^RegressionProblem@SL
output:^Vector@LA
\ No newline at end of file
...@@ -3,29 +3,62 @@ ...@@ -3,29 +3,62 @@
(#nms EVAL org.aiddl.eval) (#nms EVAL org.aiddl.eval)
(#req T org.aiddl.common.domain) (#req T org.aiddl.common.domain)
(#req FoL org.aiddl.common.reasoning.logic.first-order)
(#req LA org.aiddl.common.math.linear-algebra) (#req LA org.aiddl.common.math.linear-algebra)
(#def WildcardDomain (#def WildcardDomain
(= #self *)) (= #self *))
(#def Attribute (#def Attribute
(and (match (?Name ?Type) #self
(type #self #tuple) (and
(signature #self [term {Domain@T $WildcardDomain}]))) (type ?Name ^term)
(type ?Type ^fun-ref) )))
(#def Attributes (#def Attributes
(and (and
(type #self list) (type #self ^list)
(forall ?e #self (forall ?e #self
(type ?e $Attribute)))) (type ?e ^$Attribute))))
(#def DataPoint (and (type #self list))) (#def Class
(or
(type #self ^symbolic)
(type #self ^Atom@FoL) ))
(#def DataPoints (#def DataPoint (and (type #self ^list)))
(#def RegressionProblem
(and (and
(type #self {list set}) (type #self ^tuple)
(forall ?e #self (match (attributes : ?Attributes label : ?Label data : ?Data) #self
(type ?e $DataPoint)))) (and
(type ?Attributes ^$Attributes)
(exists (?Label _) ?Attributes true)
(forall ?Datapoint ?Data
(and
(= (size ?Datapoint) (size ?Attributes))
(zip (?Att ?Val) [?Attributes ?Datapoint]
(match (?Var ?Domain) ?Att
(and
(type ?Val ?Domain)
(type ?Val ^numerical) )))))))))
(#def ClassificationProblem
(and
(type #self ^tuple)
(match (attributes : ?Attributes label : ?Label data : ?Data) #self
(and
(type ?Attributes ^$Attributes)
(exists (?Label _) ?Attributes true)
(forall ?Datapoint ?Data
(and
(= (size ?Datapoint) (size ?Attributes))
(zip (?Att ?Val) [?Attributes ?Datapoint]
(match (?Var ?Domain) ?Att
(and
(type ?Val ?Domain)
(type ?Val ^$Class) )))))))))
(#def Problem (#def Problem
(and (and
...@@ -33,17 +66,13 @@ ...@@ -33,17 +66,13 @@
(match (attributes : ?Attributes label : ?Label data : ?Data) #self (match (attributes : ?Attributes label : ?Label data : ?Data) #self
(and (and
(type ?Attributes $Attributes) (type ?Attributes $Attributes)
(type ?Data $DataPoints)
(exists (?Label _) ?Attributes true) (exists (?Label _) ?Attributes true)
(forall ?Datapoint ?Data (forall ?Datapoint ?Data
(and (and
(= (size ?Datapoint) (size ?Attributes)) (= (size ?Datapoint) (size ?Attributes))
(zip (?Att ?Val) [?Attributes ?Datapoint] (zip (?Att ?Val) [?Attributes ?Datapoint]
(match (?Var ?Domain) ?Att (match (?Var ?Domain) ?Att
(or (type ?Val ?Domain)
(= ?Domain *)
(in ?Val ?Domain)
)
) )
) )
) )
...@@ -58,4 +87,17 @@ ...@@ -58,4 +87,17 @@
(type ?M Matrix@LA) (type ?M Matrix@LA)
(= (size ?A) (size ?M)) (= (size ?A) (size ?M))
(= (size ?A) (size (first ?M))) (= (size ?A) (size (first ?M)))
))) )))
\ No newline at end of file
(#interface classification-function
(
uri:org.aiddl.common.learning.supervised.classification-function
input:^$DataPoint
output:$Class))
(#interface regression-function
(
uri:org.aiddl.common.learning.supervised.regression-function
input:^$DataPoint
output:^numerical))
\ No newline at end of file
...@@ -16,90 +16,87 @@ ...@@ -16,90 +16,87 @@
(type #self ^$UndirectedEdge) (type #self ^$UndirectedEdge)
(type #self ^$DirectedEdge) )) (type #self ^$DirectedEdge) ))
(#def Label
(type #self ^term))
(#def UndirectedEdge (#def UndirectedEdge
(and (and
(type #self {^tuple ^list ^set}) (type #self ^set)
(type (get-key e #self) ^set) (= (size #self) 2)
(= (size (get-key e #self)) 2) (forall ?e #self
(forall ?e (get-key e #self) (type ?e ^$Node) )))
(type ?e ^$Node) )))
(#def DirectedEdge (#def DirectedEdge
(and (and
(type #self {^tuple ^list ^set}) (type #self ^tuple)
(exists e:?e #self (signature #self [^$Node ^$Node])
(and ))
(type ?e ^tuple)
(signature ?e [^$Node ^$Node])
(= (size ?e) 2) ))))
(#def LabeledEdge (#def Graph
(and (and
(type #self ^$Edge) (type #self ^tuple)
(exists label:?L #self (let [?V:(get-key V #self) ?E:(get-key E #self)]
(type ?L ^$Label) ))) (and
(forall ?v ?V (type ?v ^$Node))
(forall ?e ?E
(and
(type ?e ^$UndirectedEdge)
(contains-all ?V ?e) ))))))
(#def WeightedEdge (#def DiGraph
(and (and
(type #self ^$Edge) (type #self ^tuple)
(exists w:?w #self (let [?V:(get-key V #self) ?E:(get-key E #self)]
(type ?w ^numerical) ))) (and
(forall ?v ?V (type ?v ^$Node))
(forall ?e ?E
(and
(type ?e ^$DirectedEdge)
(contains ?V (get-idx 0 ?e))
(contains ?V (get-idx 1 ?e)) ))))))
(#def Graph (type (^$Node ^$Edge #self) ^$TypedGraph)) (#def (TypedGraph ?NodeType)
(lambda ?G
(type (?NodeType ?G) ^$TypedGraphFun)))
(#def TypedGraph (#def TypedGraphFun
(match (?NodeType ?EdgeType ?G) #self (match (?NodeType ?G) #self
(and (and
(type ?G ^tuple) (type ?G ^tuple)
(match (V:?V E:?E) ?G (let [?V:(get-key V #self) ?E:(get-key E #self)]
(and (and
(type ?V {^set ^list}) (forall ?v ?V (type ?v ?NodeType))
(forall ?v ?V (call ?NodeType ?v)) ;; (type ?v ?NodeType)) (forall ?e ?E
(forall ?e ?E (and
(and (type ?e ^$UndirectedEdge)
(call ?EdgeType ?e) ;; (type ?e ?EdgeType) (contains-all ?V ?e) )))))))
(cond
(type ?e ^$UndirectedEdge) : (#def (TypedDiGraph ?NodeType)
(contains-all ?V (get-key e ?e)) (lambda ?G
(type ?e ^$DirectedEdge) : (type (?NodeType ?G) ^$TypedDiGraphFun)))
(and
(contains ?V (get-idx 0 (get-key e ?e))) (#def TypedDiGraphFun
(contains ?V (get-idx 1 (get-key e ?e))) ))))))))) (match (?NodeType ?G) #self
(and
(#def Simple (type ?G ^tuple)
(type (get-key V #self) ^set)) (let [?V:(get-key V #self) ?E:(get-key E #self)]
(and
(#def Multi (forall ?v ?V (type ?v ?NodeType))
(type (get-key V #self) ^list)) (forall ?e ?E
(and
(#def Directed (type ?e ^$DirectedEdge)
(forall ?e (get-key E #self) (contains-all ?V ?e) )))))))
(type ?e ^$DirectedEdge) ))
(#def Undirected
(forall ?e (get-key E #self)
(type ?e ^$UndirectedEdge) ))
(#def Weighted
(forall ?e (get-key E #self)
(type ?e ^$WeightedEdge) ))
(#def Connected
(forall ?v1 (get-key V #self)
(forall ?v2 (get-key V #self)
(or
(= ?v1 ?v2)
(exists ?e (get-key E #self)
(= (get-key e ?e) {?v1 ?v2}) )))))
(#def Path (#def Path
(and (and
(type #self ^list) (type #self ^list)
(forall ?n #self (type ?n ^$Node)))) (forall ?n #self (type ?n ^$Node))))
(#def WeightMap
(and
(type #self ^collection)
(forall ?k:?v #self
(and
(type ?k ^$Edge)
(type ?v ^numerical) ))))
(#def DistanceMap (#def DistanceMap
(and (and
(type #self ^collection) (type #self ^collection)
...@@ -116,33 +113,44 @@ ...@@ -116,33 +113,44 @@
(type ?k ^$Node) (type ?k ^$Node)
(type ?v ^$Node) )))) (type ?v ^$Node) ))))
(#interface transpose ( ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
uri : org.aiddl.common.math.graph.transpose ;; Interfaces
input : ^$Graph ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
output : ^$Graph
))
(#interface bellman-ford ( (#interface single-source-shortest-path (
uri : org.aiddl.common.math.graph.bellman-ford uri : org.aiddl.common.math.graph.single-source-shortest-path
input : (KeyValuedType@C [graph:^$Graph start:^$Node target:^$Node]) input : (TypedTuple@C [^$DiGraph {^fun-ref ^$WeightMap} ^$Node])
output : (KeyValuedType@C [path:^$Path distance:^$DistanceMap predecessor:^$PredecessorMap]) output : (KeyValuedType@C [distance:^$DistanceMap predecessor:^$PredecessorMap])
)) ))
(#interface depth-first-search ( (#interface depth-first-search (
uri : org.aiddl.common.match.graph.depth-first-search uri : org.aiddl.common.math.graph.depth-first-search
input : $Graph input : ^$DiGraph
output : (KeyValuedType@C [ output : (KeyValuedType@C [
pi:^(MapGen@C ^$Node ^$Node) pi:(MapGen@C ^$Node ^$Node)
distances:^(MapGen ^$Node ^numerical) distances:(MapGen@C ^$Node ^numerical)
finish-times:^(MapGen@C ^$Node ^numerical) finish-times:(MapGen@C ^$Node ^numerical)
components:^(SetGen@C ^(SetGen@C ^$Node)) ] components:(SetGen@C (SetGen@C ^$Node)) ]
) )
)) ))
(#interface strongly-connected-components ( (#interface strongly-connected-components (
uri : org.aiddl.common.math.graph.scc-computer uri : org.aiddl.common.math.graph.scc-computer
input : ^$Graph input : ^$DiGraph
output : ^(SetGen@C ^(SetGen@C ^$Node)) output : (SetGen@C (SetGen@C ^$Node))
))
(#interface transpose (
uri : org.aiddl.common.math.graph.transpose
input : ^$DiGraph
output : ^$DiGraph
))
(#interface path-extractor (
uri : org.aiddl.common.math.graph.path-extractor
input : ^$PredecessorMap
output : ^$Path
)) ))
\ No newline at end of file
...@@ -2,30 +2,31 @@ ...@@ -2,30 +2,31 @@
(#nms E org.aiddl.eval) (#nms E org.aiddl.eval)
(#req G org.aiddl.common.math.graph)
(#req P org.aiddl.common.planning.state-variable) (#req P org.aiddl.common.planning.state-variable)
(#req FL org.aiddl.common.reasoning.logic.first-order) (#req FL org.aiddl.common.reasoning.logic.first-order)
;; (#def RelaxedPlanningGraph (#def DomainTransitionEdge
;; (and (and
;; (type #self list) (type #self ^DirectedEdge@G)
;; (forall ?idx (domain {min:0 max:(- (size #self) 1)}) (type (get-key label #label) ^StateVariableAssignments) ))
;; (let [?L:(get-idx ?idx #self)]
;; (and (#def DomainTransitionGraphs
;; (type ?L set) (and
;; (if (= (modulo ?idx 2) 0) (type #self ^set)
;; (forall ?e ?L (forall (?x:?dtg) #self
;; (or (and
;; (type ?e Atom@FL) (type ?x {^Atom@FL ^symbolic})
;; (type ?e StateVariableAssignment@P))) (type ?dtg (TypedDiGraph@G {^Atom@FL ^symbolic}))
;; (forall ?e ?L (let [?L:(get-key labels ?dtg)]
;; (type ?e Operator@P) ))))))) (type ?L (MapGen@C {^Atom@FL ^symbolic} ^$DomainTransitionEdge))
)))))
(#def RelaxedPlanningGraph (#def RelaxedPlanningGraph
(and (and
(type #self ^list) (type #self ^list)
(let (let
[?O:(reduce [?O:(reduce (lambda (?c ?x) (union {(get-idx ?x #self) ?c}))
(lambda (?c ?x) (union {(get-idx ?x #self) ?c}))
(filter (lambda ?x (= (modulo ?x 2) 1)) (domain {min:0 max:(- (size #self) 1)})) (filter (lambda ?x (= (modulo ?x 2) 1)) (domain {min:0 max:(- (size #self) 1)}))
initial-value:{}) initial-value:{})
?P:(reduce (lambda (?c ?x) (union {(get-idx ?x #self) ?c})) ?P:(reduce (lambda (?c ?x) (union {(get-idx ?x #self) ?c}))
...@@ -36,8 +37,18 @@ ...@@ -36,8 +37,18 @@
(type ?e ^StateVariableAssignment@P)) (type ?e ^StateVariableAssignment@P))
(forall ?e ?O (forall ?e ?O
(type ?e ^Operator@P) ))))) (type ?e ^Operator@P) )))))
(#interface rpg-creator ( (#interface causal-graph-creator (
uri : (sym-concat $self causal-graph-creator)
input : ^Operators@P
output : (TypedDiGraph@G {^Atom@FL ^symbolic})) )
(#interface domain-transition-graph-creator (