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

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
problems. This allows to create complex integrated AI systems by combining
robust and well-studied components.
You can find the most recent version under [[http:www.aiddl.org][aiddl.org]].
* Overview
#+CAPTION: Overview of AIDDL components and interactions.
......@@ -240,8 +242,6 @@ readability we assume name spaces ~eval.aiddl~ and ~type.aiddl~ are used):
(<= #self 10)))
#+END_EXAMPLE
* Support
Contact Uwe Köckemann (uwe.kockemann_at_oru.se) in case of questions,
suggestions, feature requests, bug reports.
......
......@@ -3,3 +3,46 @@
The AIDDL Common Library contains type definitions, implementations and test
cases for many common AI algorithms. These implementations can be used as
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)
(#nms EVAL "eval.aiddl")
(#nms EVAL org.aiddl.eval)
(#def Map
(and
......@@ -11,7 +11,7 @@
(#def MapGen
(match (?KT ?VT) #self
^(lambda ?M ($MapOf (?KT ?VT ?M)))))
(lambda ?M ($MapOf (?KT ?VT ?M)))))
(#def MapOf
(match (?KeyType ?ValueType ?Map) #self
......@@ -24,16 +24,21 @@
)))))
(#def SetGen
^(lambda ?Set
($SetOf #self ?Set) ))
(lambda ?Set
(and
(type ?Set ^set)
(forall ?e ?Set (type ?e #self)))))
(#def (SetOf ?Type ?Set)
(and
(type ?Set ^set)
(forall ?e ?Set (type ?e ?Type))))
(#def ListGen
^(lambda ?List
(ListOf ?List #self) ))
(lambda ?List
(and
(type ?List ^list)
(forall ?e ?List (type ?e #self)))))
(#def (ListOf ?Type)
(and
......@@ -49,7 +54,18 @@
)))
(#def KeyValuedType
^(lambda ?x
(lambda ?x
(forall ?k:?t #self
(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 {= < > >= <=}))
......@@ -21,3 +23,11 @@
(type #self #list)
(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 @@
(#nms EVAL org.aiddl.eval)
(#req T org.aiddl.common.domain)
(#req FoL org.aiddl.common.reasoning.logic.first-order)
(#req LA org.aiddl.common.math.linear-algebra)
(#def WildcardDomain
(= #self *))
(#def Attribute
(and
(type #self #tuple)
(signature #self [term {Domain@T $WildcardDomain}])))
(match (?Name ?Type) #self
(and
(type ?Name ^term)
(type ?Type ^fun-ref) )))
(#def Attributes
(and
(type #self list)
(type #self ^list)
(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
(type #self {list set})
(forall ?e #self
(type ?e $DataPoint))))
(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 ^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
(and
......@@ -33,17 +66,13 @@
(match (attributes : ?Attributes label : ?Label data : ?Data) #self
(and
(type ?Attributes $Attributes)
(type ?Data $DataPoints)
(exists (?Label _) ?Attributes true)
(forall ?Datapoint ?Data
(and
(= (size ?Datapoint) (size ?Attributes))
(zip (?Att ?Val) [?Attributes ?Datapoint]
(match (?Var ?Domain) ?Att
(or
(= ?Domain *)
(in ?Val ?Domain)
)
(type ?Val ?Domain)
)
)
)
......@@ -58,4 +87,17 @@
(type ?M Matrix@LA)
(= (size ?A) (size ?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 @@
(type #self ^$UndirectedEdge)
(type #self ^$DirectedEdge) ))
(#def Label
(type #self ^term))
(#def UndirectedEdge
(and
(type #self {^tuple ^list ^set})
(type (get-key e #self) ^set)
(= (size (get-key e #self)) 2)
(forall ?e (get-key e #self)
(type ?e ^$Node) )))
(type #self ^set)
(= (size #self) 2)
(forall ?e #self
(type ?e ^$Node) )))
(#def DirectedEdge
(and
(type #self {^tuple ^list ^set})
(exists e:?e #self
(and
(type ?e ^tuple)
(signature ?e [^$Node ^$Node])
(= (size ?e) 2) ))))
(type #self ^tuple)
(signature #self [^$Node ^$Node])
))
(#def LabeledEdge
(#def Graph
(and
(type #self ^$Edge)
(exists label:?L #self
(type ?L ^$Label) )))
(type #self ^tuple)
(let [?V:(get-key V #self) ?E:(get-key E #self)]
(and
(forall ?v ?V (type ?v ^$Node))
(forall ?e ?E
(and
(type ?e ^$UndirectedEdge)
(contains-all ?V ?e) ))))))
(#def WeightedEdge
(#def DiGraph
(and
(type #self ^$Edge)
(exists w:?w #self
(type ?w ^numerical) )))
(type #self ^tuple)
(let [?V:(get-key V #self) ?E:(get-key E #self)]
(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
(match (?NodeType ?EdgeType ?G) #self
(#def TypedGraphFun
(match (?NodeType ?G) #self
(and
(type ?G ^tuple)
(match (V:?V E:?E) ?G
(and
(type ?V {^set ^list})
(forall ?v ?V (call ?NodeType ?v)) ;; (type ?v ?NodeType))
(forall ?e ?E
(and
(call ?EdgeType ?e) ;; (type ?e ?EdgeType)
(cond
(type ?e ^$UndirectedEdge) :
(contains-all ?V (get-key e ?e))
(type ?e ^$DirectedEdge) :
(and
(contains ?V (get-idx 0 (get-key e ?e)))
(contains ?V (get-idx 1 (get-key e ?e))) )))))))))
(#def Simple
(type (get-key V #self) ^set))
(#def Multi
(type (get-key V #self) ^list))
(#def Directed
(forall ?e (get-key E #self)
(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}) )))))
(type ?G ^tuple)
(let [?V:(get-key V #self) ?E:(get-key E #self)]
(and
(forall ?v ?V (type ?v ?NodeType))
(forall ?e ?E
(and
(type ?e ^$UndirectedEdge)
(contains-all ?V ?e) )))))))
(#def (TypedDiGraph ?NodeType)
(lambda ?G
(type (?NodeType ?G) ^$TypedDiGraphFun)))
(#def TypedDiGraphFun
(match (?NodeType ?G) #self
(and
(type ?G ^tuple)
(let [?V:(get-key V #self) ?E:(get-key E #self)]
(and
(forall ?v ?V (type ?v ?NodeType))
(forall ?e ?E
(and
(type ?e ^$DirectedEdge)
(contains-all ?V ?e) )))))))
(#def Path
(and
(type #self ^list)
(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
(and
(type #self ^collection)
......@@ -116,33 +113,44 @@
(type ?k ^$Node)
(type ?v ^$Node) ))))
(#interface transpose (
uri : org.aiddl.common.math.graph.transpose
input : ^$Graph
output : ^$Graph
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Interfaces
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(#interface bellman-ford (
uri : org.aiddl.common.math.graph.bellman-ford
input : (KeyValuedType@C [graph:^$Graph start:^$Node target:^$Node])
output : (KeyValuedType@C [path:^$Path distance:^$DistanceMap predecessor:^$PredecessorMap])
(#interface single-source-shortest-path (
uri : org.aiddl.common.math.graph.single-source-shortest-path
input : (TypedTuple@C [^$DiGraph {^fun-ref ^$WeightMap} ^$Node])
output : (KeyValuedType@C [distance:^$DistanceMap predecessor:^$PredecessorMap])
))
(#interface depth-first-search (
uri : org.aiddl.common.match.graph.depth-first-search
input : $Graph
uri : org.aiddl.common.math.graph.depth-first-search
input : ^$DiGraph
output : (KeyValuedType@C [
pi:^(MapGen@C ^$Node ^$Node)
distances:^(MapGen ^$Node ^numerical)
finish-times:^(MapGen@C ^$Node ^numerical)
components:^(SetGen@C ^(SetGen@C ^$Node)) ]
pi:(MapGen@C ^$Node ^$Node)
distances:(MapGen@C ^$Node ^numerical)
finish-times:(MapGen@C ^$Node ^numerical)
components:(SetGen@C (SetGen@C ^$Node)) ]
)
))
(#interface strongly-connected-components (
uri : org.aiddl.common.math.graph.scc-computer
input : ^$Graph
output : ^(SetGen@C ^(SetGen@C ^$Node))
input : ^$DiGraph
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 @@
(#nms E org.aiddl.eval)
(#req G org.aiddl.common.math.graph)
(#req P org.aiddl.common.planning.state-variable)
(#req FL org.aiddl.common.reasoning.logic.first-order)
;; (#def RelaxedPlanningGraph
;; (and
;; (type #self list)
;; (forall ?idx (domain {min:0 max:(- (size #self) 1)})
;; (let [?L:(get-idx ?idx #self)]
;; (and
;; (type ?L set)
;; (if (= (modulo ?idx 2) 0)
;; (forall ?e ?L
;; (or
;; (type ?e Atom@FL)
;; (type ?e StateVariableAssignment@P)))
;; (forall ?e ?L
;; (type ?e Operator@P) )))))))
(#def DomainTransitionEdge
(and
(type #self ^DirectedEdge@G)
(type (get-key label #label) ^StateVariableAssignments) ))
(#def DomainTransitionGraphs
(and
(type #self ^set)
(forall (?x:?dtg) #self
(and
(type ?x {^Atom@FL ^symbolic})
(type ?dtg (TypedDiGraph@G {^Atom@FL ^symbolic}))
(let [?L:(get-key labels ?dtg)]
(type ?L (MapGen@C {^Atom@FL ^symbolic} ^$DomainTransitionEdge))
)))))
(#def RelaxedPlanningGraph
(and
(type #self ^list)
(let
[?O:(reduce
(lambda (?c ?x) (union {(get-idx ?x #self) ?c}))
[?O:(reduce (lambda (?c ?x) (union {(get-idx ?x #self) ?c}))
(filter (lambda ?x (= (modulo ?x 2) 1)) (domain {min:0 max:(- (size #self) 1)}))
initial-value:{})
?P:(reduce (lambda (?c ?x) (union {(get-idx ?x #self) ?c}))
......@@ -36,8 +37,18 @@
(type ?e ^StateVariableAssignment@P))
(forall ?e ?O
(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 (
uri : (sym-concat $self domain-transition-graph-creator)
input : ^Operators@P
output : ^$DomainTransitionGraphs ))
(#interface relaxed-planning-graph-creator (
uri : (sym-concat $self rpg-creator)
input : ^Problem@P
output : ^$RelaxedPlanningGraph
......
(#mod self org.aiddl.common.planning.hierarchical-task-network)
(#req C org.aiddl.common)
(#req G org.aiddl.common.math.graph)
(#req FOL org.aiddl.common.reasoning.logic.first-order)
(#req SVP org.aiddl.common.state-variable)
(#def Task (type #self Atom@FOL))
(#def TotallyOrderedTaskNetwork
(type #self (List $Task)@C))