Skip to content

Commit

Permalink
Adapted requirements: now boring code but no warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhanika committed Jun 12, 2024
1 parent 50a12e6 commit 3463568
Show file tree
Hide file tree
Showing 40 changed files with 118 additions and 71 deletions.
6 changes: 4 additions & 2 deletions src/main/clojure/conexp/api/namespace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
conexp.layouts.freese
conexp.layouts.layered
conexp.layouts.dim-draw
conexp.api.shorthands))
conexp.api.shorthands
clojure.set))

;;;

Expand All @@ -24,7 +25,8 @@
conexp.layouts.freese
conexp.layouts.layered
conexp.layouts.dim-draw
conexp.api.shorthands]))
conexp.api.shorthands
clojure.set])) ;; basic set operations

(def functions
(concat
Expand Down
42 changes: 22 additions & 20 deletions src/main/clojure/conexp/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
(ns conexp.base
"Basic definitions for conexp-clj."
(:require [clojure.math.combinatorics :as comb]
[clojure.java.io :as io]))
[clojure.java.io :as io]
[clojure.set :refer [difference union subset? intersection]]
[clojure.math.numeric-tower :as nt]))

;;; def macros, inspired and partially copied from clojure.contrib.def

Expand Down Expand Up @@ -77,24 +79,24 @@ metadata (as provided by def) merged into the metadata of the original."
(last dforms)))))
;;; Namespace tools

(defn immigrate
"Create a public var in this namespace for each public var in the
namespaces named by ns-names. The created vars have the same name, root
binding, and metadata as the original except that their :ns metadata
value is this namespace.
This function is literally copied from the clojure.contrib.ns-utils library."
[& ns-names]
(doseq [ns ns-names]
(require ns)
(doseq [[sym, ^clojure.lang.Var var] (ns-publics ns)]
(let [sym (with-meta sym (assoc (meta var) :ns *ns*))]
(if (.hasRoot var)
(intern *ns* sym (.getRawRoot var))
(intern *ns* sym))))))

(immigrate 'clojure.set
'clojure.math.numeric-tower)
;; (defn immigrate
;; "Create a public var in this namespace for each public var in the
;; namespaces named by ns-names. The created vars have the same name, root
;; binding, and metadata as the original except that their :ns metadata
;; value is this namespace.

;; This function is literally copied from the clojure.contrib.ns-utils library."
;; [& ns-names]
;; (doseq [ns ns-names]
;; (require ns)
;; (doseq [[sym, ^clojure.lang.Var var] (ns-publics ns)]
;; (let [sym (with-meta sym (assoc (meta var) :ns *ns*))]
;; (if (.hasRoot var)
;; (intern *ns* sym (.getRawRoot var))
;; (intern *ns* sym))))))

;; (immigrate 'clojure.set
;; 'clojure.math.numeric-tower)

;;; Version

Expand Down Expand Up @@ -586,7 +588,7 @@ metadata (as provided by def) merged into the metadata of the original."
and returns double otherwise."
[a b]
(if (not (and (integer? a) (integer? b)))
(clojure.math.numeric-tower/expt a b)
(nt/expt a b)
(let [^clojure.lang.BigInt a (bigint a),
b (long b)]
(if (< b 0)
Expand Down
30 changes: 15 additions & 15 deletions src/main/clojure/conexp/fca/causal_implications.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[conexp.io.contexts :refer :all]
[conexp.fca.contexts :refer :all]
[conexp.fca.implications :refer :all]
[clojure.set :as set]))
[clojure.set :refer [difference union subset? intersection]]))

;For a full Explanation of the Concepts refer to *Mining Causal Association Rules*
;https://www.researchgate.net/publication/262240022_Mining_Causal_Association_Rules
Expand All @@ -26,9 +26,9 @@
(and (subset? premise b-attributes) (not (subset? premise a-attributes))))
;check whether controlled variables have same realizations in both objects
(subset? controlled-variables
(set/union (set/intersection a-attributes b-attributes)
(set/intersection (set/difference controlled-variables a-attributes)
(set/difference controlled-variables b-attributes)))))))
(union (intersection a-attributes b-attributes)
(intersection (difference controlled-variables a-attributes)
(difference controlled-variables b-attributes)))))))

(defn find-matched-record-pair [ctx impl controlled-variables objs-considered a]
"Searches objs-considered for an object that forms a matched record pair with a,
Expand All @@ -47,13 +47,13 @@
(let [objs (objects ctx)]
(filter seq
(reduce (fn [present-objs new-obj]
(if (contains? (reduce set/union present-objs) new-obj)
(if (contains? (reduce union present-objs) new-obj)
present-objs
(conj present-objs (find-matched-record-pair
ctx
impl
controlled-variables
(set/difference objs (reduce set/union present-objs))
(difference objs (reduce union present-objs))
new-obj))))
#{} objs))))

Expand Down Expand Up @@ -103,10 +103,10 @@
"Used to compute the bounds of the confidence interval within the confidence-interval method.
Computes the upper bound if + is supplied as op, lower bound if - is supplied."
(Math/exp (op (Math/log odds-ratio)
(* zconf (Math/sqrt (+ (/ 1 (absolute-support ctx [(set/union premise conclusion) #{}]))
(* zconf (Math/sqrt (+ (/ 1 (absolute-support ctx [(union premise conclusion) #{}]))
(/ 1 (absolute-support ctx [premise conclusion]))
(/ 1 (absolute-support ctx [conclusion premise]))
(/ 1 (absolute-support ctx [#{} (set/union premise conclusion)]))))))))
(/ 1 (absolute-support ctx [#{} (union premise conclusion)]))))))))

(defn confidence-interval [ctx impl odds-ratio zconf]
"Computes the confidence interval of the implication. odds-ratio is the regular odds ratio of
Expand Down Expand Up @@ -180,9 +180,9 @@
confidence interval is greather than 1."
(let [premise (premise impl)
conclusion (conclusion impl)
E (reduce set/union (exclusive-variables ctx premise thresh))
controlled-variables (set/difference (attributes ctx)
(set/union conclusion irrelevant-vars E premise))
E (reduce union (exclusive-variables ctx premise thresh))
controlled-variables (difference (attributes ctx)
(union conclusion irrelevant-vars E premise))
fair-data (fair-data-set ctx impl controlled-variables)
fair-odds (fair-odds-ratio ctx impl fair-data)]

Expand Down Expand Up @@ -217,8 +217,8 @@
(causal-association-rule-discovery
ctx ;context
#{} ;current causal rules
(set/difference frequent-vars #{response-var}) ;frequent single variables
(for [x (set/difference frequent-vars #{response-var})] #{x}) ;itemsets of the current iteration
(difference frequent-vars #{response-var}) ;frequent single variables
(for [x (difference frequent-vars #{response-var})] #{x}) ;itemsets of the current iteration
ivars ;irrelevant variables in respect to response-var
min-lsupp ;minimum local support
0 ;counter, counts up to max-length
Expand All @@ -237,9 +237,9 @@

(causal-association-rule-discovery
ctx
(set/union rule-set new-causal-rules)
(union rule-set new-causal-rules)
variables
(set/difference (filter #(> (local-support ctx (->Implication #{%} #{response-var})) min-lsupp) new-item-sets)
(difference (filter #(> (local-support ctx (->Implication #{%} #{response-var})) min-lsupp) new-item-sets)
(find-redundant ctx current new-item-sets response-var));filter item sets
ivars
min-lsupp
Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/concept_transform.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
(ns conexp.fca.concept-transform
(:require [conexp.base :refer :all]
[conexp.fca.contexts :refer :all]
[conexp.fca.cover :refer :all]))
[conexp.fca.cover :refer :all]
[clojure.set :refer [difference union subset? intersection]]))



Expand Down
4 changes: 3 additions & 1 deletion src/main/clojure/conexp/fca/contexts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
(ns conexp.fca.contexts
"Provides the implementation of formal contexts and functions on them."
(:require [clojure.core.reducers :as r]
[conexp.base :refer :all]))
[clojure.set :refer [difference intersection union subset?]]
[conexp.base :refer :all]
))

;;;

Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/cover.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
to-binary-matrix
bitwise-context-attribute-closure]]
[clojure.core.reducers :as r]
[clojure.core.async :refer [<!!]])
[clojure.core.async :refer [<!!]]
[clojure.set :refer [difference union subset? intersection]])
(:import [java.util BitSet]))

;;;;;;;;;;;;;;;;;;;;; General Cover Methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
1 change: 1 addition & 0 deletions src/main/clojure/conexp/fca/dependencies.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'Dependencies of many-valued attributes', 1987, Rudolf Wille
http://www.opengrey.eu/item/display/10068/148205 "
(:require [clojure.core.reducers :as r]
[clojure.set :refer [intersection subset?]]
[conexp.base :refer :all]
[conexp.fca.implications :refer [premise conclusion
stem-base-from-base
Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/exploration.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
(:use conexp.base
conexp.fca.contexts
conexp.fca.implications)
(:require [clojure.core.reducers :as r]))
(:require [clojure.core.reducers :as r]
[clojure.set :refer [difference union intersection subset? ]]))


(defn exploration-step
Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/graph.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[conexp.math.algebra :as alg]
[conexp.fca.lattices :as lat]
[conexp.util.graph :refer :all]
[conexp.base :exclude [transitive-closure] :refer :all]))
[conexp.base :exclude [transitive-closure] :refer :all]
[clojure.set :refer [difference union subset? intersection]]))


;;; graph <-> lattice
Expand Down
14 changes: 8 additions & 6 deletions src/main/clojure/conexp/fca/implications.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
[conexp.base :refer :all]
[conexp.math.algebra :refer :all]
[conexp.fca.contexts :refer :all]
[clojure.set :as set]))
[clojure.set :refer [difference union subset? intersection]]
[clojure.math.numeric-tower :as nt]
))

;;;

Expand Down Expand Up @@ -604,15 +606,15 @@
"Computes the confidence of an implication using the absolute-support method."
[ctx impl]
(let [premise (premise impl) conclusion (conclusion impl)]
(/ (absolute-support ctx [(set/union premise conclusion) #{}])
(/ (absolute-support ctx [(union premise conclusion) #{}])
(absolute-support ctx [premise #{}]))))

(defn odds-ratio
"Computes the odds ratio of an implication using the asupp method."
[ctx impl]
(let [premise (premise impl) conclusion (conclusion impl)]
(/ (* (absolute-support ctx [(set/union premise conclusion) #{}])
(absolute-support ctx [#{} (set/union premise conclusion)]))
(/ (* (absolute-support ctx [(union premise conclusion) #{}])
(absolute-support ctx [#{} (union premise conclusion)]))
(* (absolute-support ctx [premise conclusion])
(absolute-support ctx [conclusion premise]))
)))
Expand All @@ -621,7 +623,7 @@
"Computes the local support of an implication by dividing the support of the implication
by the support of its conclusion. Uses the absolute-support function."
(let [premise (premise impl) conclusion (conclusion impl)]
(/ (absolute-support ctx [(set/union premise conclusion) #{}])
(/ (absolute-support ctx [(union premise conclusion) #{}])
(absolute-support ctx [conclusion #{}]))))

(defn- frequent-itemsets
Expand Down Expand Up @@ -812,7 +814,7 @@
(learn-implications-by-queries (attributes ctx)
intent?
(fn [implications]
(let [nr-iter (ceil (* (/ ε) (+ (swap! iter-counter inc)
(let [nr-iter (nt/ceil (* (/ ε) (+ (swap! iter-counter inc)
(/ (Math/log (/ δ))
(Math/log 2)))))]
(or (some (fn [test-set]
Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/incremental_ganter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
https://link.springer.com/article/10.1007/s10472-007-9057-2 "
(:require [conexp.base :refer :all]
[conexp.fca.implications :refer :all]
[conexp.fca.contexts :refer :all]))
[conexp.fca.contexts :refer :all]
[clojure.set :refer [difference union subset? intersection]]))

;;;

Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/lattices.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
conexp.math.algebra
conexp.fca.contexts
conexp.fca.posets)
(:require [clojure.set :refer [difference union subset? intersection]])
(:gen-class))

;;; Datastructure
Expand Down Expand Up @@ -466,7 +467,7 @@
(let [lat-join (sup lat)
lat-meet (inf lat)]
(loop [X generators]
(let [X-new (clojure.set/union (into #{} (for [a X b X] (lat-join a b)))
(let [X-new (union (into #{} (for [a X b X] (lat-join a b)))
(into #{} (for [a X b X] (lat-meet a b))))]
(if (= X X-new) (make-lattice X lat-meet lat-join)
(recur X-new)))))
Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/many_valued_contexts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

(ns conexp.fca.many-valued-contexts
"Many-Valued-Contexts and some functions for scaling."
(:require [conexp.base :refer :all]
(:require [clojure.set :refer [difference union subset? intersection]]
[conexp.base :refer :all]
[conexp.fca.contexts :refer :all]))

;;;
Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/metrics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
bitwise-attribute-derivation concepts]]
[implications :refer :all]
[lattices :refer [inf sup lattice-base-set make-lattice concept-lattice lattice-order]]]
[conexp.math.util :refer [eval-polynomial binomial-coefficient]])
[conexp.math.util :refer [eval-polynomial binomial-coefficient]]
[clojure.set :refer [difference union subset? intersection]])
(:import [conexp.fca.lattices Lattice]
[java.util ArrayList BitSet]))

Expand Down
1 change: 1 addition & 0 deletions src/main/clojure/conexp/fca/more.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"More on FCA."
(:require [conexp.base :refer :all]
[clojure.core.reducers :as r]
[clojure.set :refer [difference union subset? intersection]]
[conexp.fca
[contexts :refer :all]
[exploration :refer :all]
Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/fca/posets.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
;; You must not remove this notice, or any other, from this software.

(ns conexp.fca.posets
(:require [conexp.base :refer :all]
(:require [clojure.set :refer [union difference subset?]]
[conexp.base :refer :all]
[conexp.math.algebra :refer :all]
[conexp.fca.contexts :refer :all]))

Expand Down
4 changes: 3 additions & 1 deletion src/main/clojure/conexp/fca/protoconcepts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
[conexp.math.algebra :refer :all]
[conexp.fca.contexts :refer :all]
[conexp.fca.lattices :refer :all]
[conexp.fca.posets :refer :all]))
[conexp.fca.posets :refer :all]
[clojure.set :refer [difference union subset? intersection]]
))

(deftype Protoconcepts [base-set order-function]
Object
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/conexp/fca/random_contexts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[conexp.base :refer [set-of exists forall => defalias]]
[conexp.fca.contexts :as contexts]
[clojure.set :refer [subset? difference union intersection select]]
[clojure.math.numeric-tower :refer :all]
[clojure.math.numeric-tower :refer [expt]]
[clojure.math.combinatorics :refer [cartesian-product]]
)
(:import [org.apache.commons.math3.distribution
Expand Down
1 change: 1 addition & 0 deletions src/main/clojure/conexp/fca/smeasure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[clojure.math.combinatorics :as comb]
[loom.graph :as lg] [loom.alg :as la]
[clojure.core.reducers :as r]
[clojure.set :refer [difference union subset? intersection]]
[conexp.fca.implications :refer :all]))

(defprotocol Smeasure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
[conexp.gui.editors.context-editor.table-control :refer :all]
[conexp.gui.editors.context-editor.widgets :refer :all]
[conexp.gui.util :refer :all]
[seesaw.core :refer [button toolbar top-bottom-split]])
[seesaw.core :refer [button toolbar top-bottom-split]]
[clojure.set :refer [difference union subset? intersection]])
(:import [java.awt.event ActionEvent KeyEvent]
[javax.swing Box JTable KeyStroke]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
(:require [clojure.string :refer [split split-lines]]
[conexp.base :refer :all]
[conexp.gui.editors.context-editor.widgets :refer :all]
[conexp.gui.util :refer :all])
[conexp.gui.util :refer :all]
[clojure.set :refer [difference union subset? intersection join map-invert]])
(:import [java.awt.event ActionEvent ActionListener InputEvent KeyEvent MouseEvent]
java.awt.Point
[javax.swing AbstractAction DefaultCellEditor JComponent JScrollPane JTable JTextField KeyStroke]
Expand Down
3 changes: 2 additions & 1 deletion src/main/clojure/conexp/io/contexts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
[clojure.data.json :as json]
[json-schema.core :as json-schema]
[clojure.data.csv :as csv]
[clojure.java.io :as io])
[clojure.java.io :as io]
[clojure.set :refer [difference union]])
(:import [java.io PushbackReader]))


Expand Down

0 comments on commit 3463568

Please sign in to comment.