forked from tomhanika/conexp-clj
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add Protoconcept data type * add preconcepts? and protoconcepts? function * add protoconcept functions and tests * fix preconcepts? tests * add semiconcept? function * add protoconcepts order and visualization * add tests for protoconcept-layout * use preconcepts? as defined by R. Wille * add draw-protoconcepts function * add print method for protoconcepts * fix errors * enable draw for protoconcepts * add more protoconcepts functions and tests * remove functions that are not needed any more fore protoconcepts * add draw functions for posets and protoconcepts * improve documentation * add documentation for protoconcepts * minor changes in documentation * minor changes in documentation * minor changes in documentation
- Loading branch information
1 parent
fd78f00
commit 57015c7
Showing
13 changed files
with
422 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#+property: header-args :wrap src text | ||
#+property: header-args:text :eval never | ||
|
||
* Protoconcepts in ~conexp-clj~ | ||
|
||
Protoconcepts are defined as $(A, B)$, $A \subseteq G$ and $B \subseteq M$ with | ||
$A' = B''$ or $B' = A''$. | ||
|
||
** Computing Protoconcepts | ||
|
||
The protoconcepts of a given context can be computed. First, the respective | ||
namespace needs to be loaded. | ||
#+begin_src clojure :results silent | ||
(use 'conexp.fca.protoconcepts) | ||
#+end_src | ||
|
||
Let the context be | ||
#+begin_src clojure :exports both | ||
(def ctx | ||
(make-context-from-matrix [1 2 3 4] | ||
['A 'B 'C] | ||
[1 1 0 | ||
1 0 0 | ||
0 1 0 | ||
0 1 0])) | ||
#+end_src | ||
|
||
#+RESULTS: | ||
#+begin_src text | ||
|A B C | ||
--+------ | ||
1 |x x . | ||
2 |x . . | ||
3 |. x . | ||
4 |. x . | ||
#+end_src | ||
|
||
The protoconcepts can be computed with the ~protoconcepts~ function. | ||
#+begin_src clojure :exports both | ||
(protoconcepts ctx) | ||
#+end_src | ||
|
||
#+RESULTS: | ||
#+begin_src clojure | ||
#{[#{4 2} #{}] [#{1 3 2} #{}] [#{1 2} #{A}] [#{1} #{A B}] | ||
[#{} #{B C}] [#{} #{C}] [#{1 4 2} #{}] [#{4} #{B}] [#{1 4 3 2} #{}] | ||
[#{4 3 2} #{}] [#{1 3} #{B}] [#{3 2} #{}] [#{1 4 3} #{B}] | ||
[#{3} #{B}] [#{4 3} #{B}] [#{2} #{A}] [#{1 4} #{B}] [#{} #{A C}] | ||
[#{} #{A B C}]} | ||
#+end_src | ||
|
||
To compute the protoconcepts as an ordered set, the ~protoconcepts-order~ function can be used. | ||
#+begin_src clojure :exports both | ||
(protoconcepts-order ctx) | ||
#+end_src | ||
|
||
#+RESULTS: | ||
#+begin_src clojure | ||
Protoconcepts on 19 elements. | ||
#+end_src | ||
|
||
** Draw Protoconcepts | ||
|
||
Drawing must be enabled via | ||
#+begin_src clojure :results silent | ||
(use 'conexp.gui.draw) | ||
#+end_src | ||
|
||
To draw the ordered protoconcepts of a context, the ~draw-protoconcepts~ function can be used. | ||
#+begin_src clojure :results silent | ||
(draw-protoconcepts (protoconcepts-order ctx)) | ||
#+end_src | ||
|
||
The protoconcepts graph is shown in an additional window. | ||
|
||
#+caption: Protoconcept example | ||
[[./images/protoconcept-lattice.png]] | ||
|
||
Like for [lattices](./Concept-Lattices.org), the layout function can be specified for | ||
protoconcepts. | ||
|
||
#+begin_src clojure :results silent | ||
(draw-protoconcepts (protoconcepts-order ctx) | ||
:layout-fn conexp.layouts.dim-draw/dim-draw-layout) | ||
#+end_src | ||
|
||
#+caption: Protoconcept example with DimDraw layout | ||
[[./images/protoconcept-lattice-dimdraw.png]] | ||
|
||
Notice that the protoconcept orders do not necessarily are a lattice. As many | ||
of the value functions only work on lattices, they cannot be applied to protoconcepts. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
;; Copyright ⓒ the conexp-clj developers; all rights reserved. | ||
;; The use and distribution terms for this software are covered by the | ||
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | ||
;; which can be found in the file LICENSE at the root of this distribution. | ||
;; By using this software in any fashion, you are agreeing to be bound by | ||
;; the terms of this license. | ||
;; You must not remove this notice, or any other, from this software. | ||
|
||
(ns conexp.fca.protoconcepts | ||
"Basis datastructure and definitions for protoconcepts. | ||
DOI:https://doi.org/10.1007/11528784_2" | ||
(:require [conexp.base :refer :all] | ||
[conexp.math.algebra :refer :all] | ||
[conexp.fca.contexts :refer :all] | ||
[conexp.fca.lattices :refer :all] | ||
[conexp.fca.posets :refer :all])) | ||
|
||
(deftype Protoconcepts [base-set order-function] | ||
Object | ||
(equals [this other] | ||
(and (= (class this) (class other)) | ||
(= (.base-set this) (.base-set ^Protoconcepts other)) | ||
(let [order-this (.order this), | ||
order-other (.order other)] | ||
(or (= order-this order-other) | ||
(forall [x (.base-set this) | ||
y (.base-set this)] | ||
(<=> (order-this x y) | ||
(order-other x y))))))) | ||
(hashCode [this] | ||
(hash-combine-hash Protoconcepts base-set)) | ||
;; | ||
Order | ||
(base-set [this] base-set) | ||
(order [this] | ||
(fn order-fn | ||
([pair] (order-function (first pair) (second pair))) | ||
([x y] (order-function x y))))) | ||
|
||
(defmethod print-method Protoconcepts [^Protoconcepts protoconcepts, ^java.io.Writer out] | ||
(.write out | ||
^String (str "Protoconcepts on " (count (base-set protoconcepts)) " elements."))) | ||
|
||
(defn protoconcept? | ||
"Tests whether given pair is protoconcept in given context ctx." | ||
[ctx [set-of-obj set-of-att]] | ||
(or (= (object-derivation ctx set-of-obj) | ||
(context-attribute-closure ctx set-of-att)) | ||
(= (context-object-closure ctx set-of-obj) | ||
(attribute-derivation ctx set-of-att)))) | ||
|
||
(defn protoconcepts? | ||
"Tests whether given tuples all are protoconcepts in given context ctx." | ||
[ctx protoconcepts] | ||
(every? (partial protoconcept? ctx) protoconcepts)) | ||
|
||
(defn protoconcepts | ||
"Computes all protoconcepts of a context." | ||
[ctx] | ||
(let [object-equivalence-classes (group-by #(object-derivation ctx %) (subsets (objects ctx))) | ||
attribute-equivalence-classes (group-by #(context-attribute-closure ctx %) (subsets (attributes ctx)))] | ||
(into #{} (apply concat (map (fn [key] | ||
(for [obj (get object-equivalence-classes key) | ||
attr (get attribute-equivalence-classes key)] | ||
[obj attr])) (keys object-equivalence-classes)))))) | ||
|
||
(defn make-protoconcepts-nc | ||
"Creates a new protoconcept order from the given base-set and order-function, without any checks." | ||
[base-set order-function] | ||
(Protoconcepts. base-set order-function)) | ||
|
||
(defn make-protoconcepts | ||
"Creates a new protoconcepts order from the given base-set and order-function. | ||
Checks if the result has partial order, which may take some time. If you don't want this, use make-protoconcepts-nc." | ||
([base-set order-function] | ||
(let [protoconcepts (make-protoconcepts-nc base-set order-function)] | ||
(when-not (has-partial-order? protoconcepts) | ||
(illegal-argument "Given arguments do not describe a partial order.")) | ||
protoconcepts)) | ||
;; checks if result only contains protoconcepts of context ctx | ||
([base-set order-function ctx] | ||
(let [protoconcepts (make-protoconcepts base-set order-function)] | ||
(when-not (protoconcepts? ctx (base-set protoconcepts)) | ||
(illegal-argument "Given base-set and order-function do not describe protoconcepts in given context.")) | ||
protoconcepts))) | ||
|
||
(defn protoconcepts-order | ||
"Returns for a given context ctx its protoconcepts with order." | ||
[ctx] | ||
(make-protoconcepts-nc (protoconcepts ctx) | ||
(fn <= [[A B] [C D]] | ||
(and (subset? A C) | ||
(subset? D B))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.