OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-matrix commits / e465f25

Work on new API
e465f257caef2b9f9f20c27670468983a40e3a2d
by Linas Vepštas <linasvepstas@gmail.com> · 2025-02-01T19:11:37.000Z

Changed files (1) +42 -5

design/Design-similarity.md +42 -5
……@@ -46,8 +46,8 @@ marked, the embedding vectors are already implicit in the graph, and
4646all that was needed was an API to work with these (sparse) vectors.
4747Given a vector API, a cornucopia of similarity measures can be created.
4848
49Queries as Tensors
50------------------
49Review of the existing API
50--------------------------
5151The original matrix API was invented to work with word-pairs. Each word
5252is a vertex; the edge between them forms a word-pair. Given a collection
5353of edges, one could think of this as forming an adjacency matrix, with
……@@ -62,10 +62,10 @@ called "parametric polymorphism", defining a base class API, that all
6262higher analysis layers could be stacked on top of. The base class
6363consisted of these parts:
6464
65 1) Get the types of the left and reight vertexes, and the edge.
65 1) Get the types of the left and right vertexes, and the edge.
6666 2) Given an edge, get the left and right vertexes.
67 3) Given the matrix, get left and right marginals (edges with the
68 left or right vertexes replaced by wild-cards).
67 3) Given the matrix, get left and right wild-cards (marginals; edges
68 with the left or right vertexes replaced by wild-cards).
6969 4) A list of all edges.
7070 5) Ability to get all edges from a StorageNode
7171 6) Delete all edges (and the correspodning entries in a StorageNode)
……@@ -83,3 +83,40 @@ that almost all otherlayers above need. These are:
8383 10) List of the left and right duals to a given Atom. The left dual
8484 for a given Atom Y is `{x | (x,Y) given fixed Y}`
8585
86The "problem" with this API is that it is implemented in scheme, and
87all of the data is stored in scheme structures. This is a fatal flaw,
88and probmpts these re-design notes.
89
90Queries as Tensors
91------------------
92It appears that the original API can be completely replaced and
93generalized by using MeetLink, and generalized by using RuleLink and/or
94QueryLink. In retrospect, this is "obvious", and I'm quite mystified why
95I didn't do it this way from the beginning. Perhaps it just wasn't so
96obvious at first. Let's spell out the obvious.
97
98The current word-pair representation for the pair (some, thing) is:
99```
100 (Edge (Predicate "word-pair") (List (Word "some") (Word "thing")))
101```
102All such edges can be found by executing the query
103```
104 (Query
105 (VariableList
106 (TypedVariable (Variable "$left") (Type 'Word))
107 (TypedVariable (Variable "$right") (Type 'Word)))
108 (Present
109 (Edge (Predicate "word-pair")
110 (List (Variable "$left") (Variable "$right"))))
111 (Edge (Predicate "word-pair")
112 (List (Variable "$left") (Variable "$right"))))
113```
114Running this query provides item (4) above. The query results are cached
115on the query itself, using itself as the key. That is, `(cog-value q q)`
116will return the query results from the most recent execute of Query `q`.
117
118Obviously, the above can be replaced by "any" query at all. The current
119rules seem to require explicit variable declarations, so that the types
120become visible for item (1).
121
122For item (3),