1.2.3-SNAPSHOT Arrow_down_16x16

symmetric-matrix

incanter.core

  • (symmetric-matrix data & options)

Returns a symmetric matrix from the given data, which represents the lower triangular elements
ordered by row. This is not the inverse of half-vectorize which returns a vector of the upper-triangular
values, unless the :lower option is set to false.

Options:
:lower (default true) -- lower-triangular. Set :lower to false to reverse the half-vectorize function.

Examples:

(use 'incanter.core)
(symmetric-matrix [1
2 3
4 5 6
7 8 9 10])


(half-vectorize
(symmetric-matrix [1
2 3
4 5 6
7 8 9 10] :lower false))


0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/core.clj:2298 top

(defn symmetric-matrix
"
  Returns a symmetric matrix from the given data, which represents the lower triangular elements
  ordered by row. This is not the inverse of half-vectorize which returns a vector of the upper-triangular
  values, unless the :lower option is set to false.

  Options:
    :lower (default true) -- lower-triangular. Set :lower to false to reverse the half-vectorize function.

  Examples:

    (use 'incanter.core)
    (symmetric-matrix [1
                       2 3
                       4 5 6
                       7 8 9 10])


    (half-vectorize
      (symmetric-matrix [1
                         2 3
                         4 5 6
                         7 8 9 10] :lower false))


"
  ([data & options]
   (let [opts (when options (apply assoc {} options))
         lower? (if (false? (:lower opts)) false true)
         n (count data)
         p (int (second (solve-quadratic 1/2 1/2 (- 0 n))))
         mat (incanter.Matrix. p p 0)
         indices (if lower?
                   (for [i (range p) j (range p) :when (<= j i)] [i j])
                   (for [i (range p) j (range p) :when (<= i j)] [j i]))]
     (doseq [idx (range n)]
      (let [[i j] (nth indices idx)]
        (.set mat i j (nth data idx))
        (.set mat j i (nth data idx))))
     mat)))
Vars in incanter.core/symmetric-matrix: defn doseq let nth
Used in 0 other vars

Comments top

No comments for symmetric-matrix. Log in to add a comment.