DISCUSSION
|#
-(in-package metabang.graph)
+(in-package #:metabang.graph)
+(eval-always
+ (import '(cl-mathstats:matrix-trace
+ cl-mathstats:sum-of-array-elements
+ cl-mathstats:matrix-multiply
+ cl-mathstats:normalize-matrix
+ cl-mathstats:combination-count
+ )))
(defun vertex-degree-counts (g)
"Returns an associative-container mapping edge-counts to the number of vertexes with that edge-count."
(incf (item-at c (edge-count v)))))
c))
-;;; ---------------------------------------------------------------------------
(defun average-vertex-degree (graph &key
(vertex-filter (constantly t))
(values (float (/ total size)))
nil)))
-;;; ---------------------------------------------------------------------------
(defun vertex-degree (vertex &key
(edge-filter (constantly t))
(declare (inline %vertex-degree))
(%vertex-degree vertex edge-filter edge-size))
-;;; ---------------------------------------------------------------------------
(defun %vertex-degree (vertex edge-filter edge-size)
"Called internally by `vertex-degree` and `average-vertex-degree`."
(incf degree (funcall edge-size e)))))
degree))
-;;; ---------------------------------------------------------------------------
(defun vertex-degree-summary (graph vertex-classifier
&key (edge-size (constantly 1)))
"Prints a summary of vertex degrees in `graph` to standard-out. Both the average degree of all vertexes and the average degree between all pairs of vertex classes \(as determined by the vertex-classifier\) will be printed. The `edge-size` parameter is passed on to `vertex-degree` to allow for weighted edges."
- (bind ((counts (node-counts graph :key vertex-classifier))
+ (let ((counts (node-counts graph :key vertex-classifier))
(kinds (collect-elements counts :transform #'first)))
(format t "~%Vertex counts: ")
(loop for (kind count) in counts do
"Average vertex degree between ~A and ~A:"
k-1 k-2))))))
-;;; ---------------------------------------------------------------------------
#|
Transitivity or Clustering.
(float (/ (vertex-triangle-count vertex)
(combination-count (edge-count vertex) 2)))))
-;;; ---------------------------------------------------------------------------
(defun vertex-triangle-count (vertex)
(let ((neighbors (neighbor-vertexes vertex)))
(member v neighbors))
(neighbor-vertexes neighbor)) 2))))
-;;; ---------------------------------------------------------------------------
(defun row-sums (matrix)
(let* ((row-count (array-dimension matrix 1))
(incf (aref result row) (aref matrix column row))))
result))
-;;; ---------------------------------------------------------------------------
(defun column-sums (matrix)
(let* ((column-count (array-dimension matrix 0))
(incf (aref result column) (aref matrix column row))))
result))
-;;; ---------------------------------------------------------------------------
(defmethod assortativity-coefficient ((matrix array))
(values 1)
(values (/ (- trace sum-squared) (- 1 sum-squared))))))
-;;; ---------------------------------------------------------------------------
(defmethod graph-edge-mixture-matrix ((graph basic-graph) vertex-classifier &key
(edge-weight (constantly 1)))
(0.013 0.023 0.306 0.035)
(0.005 0.007 0.024 0.016)))
-;;; ---------------------------------------------------------------------------
;;OPT we call the classifier a lot, probably better to make a new ht for that