QR-decomoposition of a square-matrix using the Gram-Schmidt method

shows a simple implementation of a vector and matrix type together with a QR-decomposition using the Gram-Schmidt method. The algorithms themselfes are rather easy but I think the implementation of the types and the computations using recursive techniques might be interessting

Copy Source
Copy Link
Tools:

Helpers

1: module Helpers =
2:     let curry f a b = f (a,b)
3:     let uncurry f (a,b) = f a b

Vector-type

 1: /// Represent a vector as an float array
 2: type Vector =  | Vector of float array
 3:     with 
 4:     /// shortcut to access the float array
 5:     member private v.Values = match v with Vector v' -> v'
 6:     /// access a component of the vector
 7:     member v.Item(i) = v.Values.[i]
 8:     /// the vectors dimension = nr of components
 9:     member v.Dim = Array.length v.Values
10: 
11:     // your normal vector-operators
12:     static member (+) (a : Vector, b : Vector) = Array.zip a.Values b.Values |> Array.map (Helpers.uncurry (+)) |> Vector
13:     static member (-) (a : Vector, b : Vector) = Array.zip a.Values b.Values |> Array.map (Helpers.uncurry (-)) |> Vector
14:     static member (*) (s : float, a : Vector) = a.Values |> Array.map ((*) s) |> Vector
15: 
16:     /// computes the inner product (also known as scalar product) of two vectors
17:     static member InnerProd (a : Vector, b : Vector) = Array.zip a.Values b.Values |> Array.sumBy (Helpers.uncurry (*))
18:     static member (.*.) (a,b) = Vector.InnerProd(a,b)
19: 
20:     /// the squared length of a vector
21:     static member Len2 (a : Vector) = a .*. a
22:     /// the length of a vector
23:     static member Len = System.Math.Sqrt << Vector.Len2
24:     member v.Length = Vector.Len v
25: 
26:     /// normalize a vector (the result will have the same direction but length 1)
27:     static member Normalize (a : Vector) = (1.0 / a.Length) * a
28:     member v.Normal = Vector.Normalize v
29: 
30:     /// create a zero-vector
31:     static member Zero(n) = Array.zeroCreate n |> Vector

Matrix - type

 1: /// represent a matrix as a 2-dimensional float array
 2: type Matrix = Matrix of float [,]
 3:     with
 4:     /// shortcut to the array
 5:     member private m.Values = match m  with Matrix m' -> m'
 6:     
 7:     /// the number of rows
 8:     member m.NrRows = Array2D.length1 m.Values
 9:     /// the number of columns
10:     member m.NrColumns = Array2D.length2 m.Values
11: 
12:     /// access a column-vector via its zero-based index
13:     member m.Column(i) = [| 0..Array2D.length1 m.Values-1 |] |> Array.map (fun z -> m.Values.[z,i]) |> Vector
14: 
15:     /// get all column-vectors as an array
16:     member m.Columns = [|0..Array2D.length2 m.Values-1 |] |> Array.map m.Column
17:     static member ColVectors (m : Matrix) = m.Columns
18: 
19:     /// Matrix-multiplication
20:     static member (*) (a : Matrix, b : Matrix) =
21:         Array2D.init 
22:             a.NrRows b.NrColumns
23:             (fun r c -> [0..a.NrColumns-1] 
24:                         |> List.map (fun i -> a.Values.[r,i] * b.Values.[i,c])
25:                         |> List.sum)
26:         |> Matrix
27:         
28:     /// Matrix-addition
29:     static member (+) (a : Matrix, b : Matrix) =
30:         Array2D.init 
31:             a.NrRows b.NrColumns
32:             (fun r c -> a.Values.[r,c] + b.Values.[r,c])
33:         |> Matrix
34:         
35:     /// Matrix-substraction
36:     static member (-) (a : Matrix, b : Matrix) =
37:         Array2D.init 
38:             a.NrRows b.NrColumns
39:             (fun r c -> a.Values.[r,c] + b.Values.[r,c])
40:         |> Matrix
41:         
42:     /// scalar - multiplication
43:     static member (*) (s : float, b : Matrix) =
44:         Array2D.init 
45:             b.NrRows b.NrColumns
46:             (fun r c -> s * b.Values.[r,c])
47:         |> Matrix
48:         
49: 
50:     /// computes the transpose of a matrix
51:     static member Transpose (m : Matrix) = Array2D.init m.NrRows m.NrColumns (fun x y -> m.Values.[y,x]) |> Matrix
52: 
53:     /// creates a matrix from a array of columnvectors
54:     static member Create (vs : Vector array) =
55:         let l = vs.[0].Dim
56:         Array2D.init l vs.Length (fun r c -> vs.[c].[r])
57:         |> Matrix
58: 
59:     /// creates a matrix with an generator-function (the row r and col c of the matrix will have a value of f(r,c))
60:     static member Create (rows, cols, f) =
61:         Array2D.init rows cols f
62:         |> Matrix
63: 
64:     /// creates a zero-Matrix
65:     static member Zero (rows, cols) = Array2D.zeroCreate rows cols 

Gram-Schmidt method

 1: /// computes a set of orthogonal or orthonormal vectors that spans the same
 2: /// subspace as the given vector-set
 3: module GramSchmidt =
 4: 
 5:     /// projects a vector onto another vector
 6:     let private project (baseV : Vector) (v : Vector) : Vector 
 7:         = (v .*. baseV)/(baseV .*. baseV) * baseV
 8: 
 9:     /// computes a set of orthogonal vectors that span the same subspace as the vectors in vs
10:     /// see the Wikipedia-article at http://en.wikipedia.org/wiki/Gram_schmidt for a good
11:     /// explanation of this method
12:     let Orthogonalize (vs : Vector list) =
13:         // computes one vector based on the allready found vectors
14:         let rec calcNextVec cur found =
15:             match found with
16:             | [] -> cur
17:             | v::vs' -> calcNextVec (cur - project v cur) vs'
18:         // computes the vectors
19:         let rec calcVecs toDo found =
20:             match toDo with
21:             | [] -> found
22:             | cur::rest -> calcVecs rest ((calcNextVec cur found)::found)
23:         calcVecs vs [] |> List.rev
24: 
25:     /// computes a set of orthonormal vectors that span the same subspace as the vectors in vs
26:     let OrthogonalizeNormal = Orthogonalize >> List.map Vector.Normalize

QR-decomposition

 1: /// decomposes a square matrix into a product of an orthongal and an upper triangular matrix
 2: module QRdecomposition =
 3:     
 4:     /// computes the QR-decomposition using the Gram-Schmidt method
 5:     /// see the Wikipedia-article at http://en.wikipedia.org/wiki/QR_decomposition for a good
 6:     /// explanation of this method
 7:     let UsingGramSchmidt (m : Matrix) =
 8:         let colVs = m.Columns
 9:         let normVs = Array.ofList <| GramSchmidt.OrthogonalizeNormal (List.ofArray colVs)
10:         let Q = Matrix.Create normVs
11:         let f r c = if r <= c then normVs.[r] .*. colVs.[c] else 0.0
12:         let R = Matrix.Create (m.NrRows, m.NrColumns, f)
13:         Q,R
val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c

Full name: Snippet.Helpers.curry
val f : ('a * 'b -> 'c)
val a : 'a
val b : 'b
val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c

Full name: Snippet.Helpers.uncurry
val f : ('a -> 'b -> 'c)
Multiple items
union case Vector.Vector: float array -> Vector

--------------------

module Vector

from Microsoft.FSharp.Math

--------------------

type Vector<'T>
with
  interface System.Collections.Generic.IEnumerable<'T>
  interface System.Collections.IStructuralEquatable
  interface System.Collections.IStructuralComparable
  interface System.IComparable
  member Copy : unit -> Vector<'T>
  override Equals : obj -> bool
  override GetHashCode : unit -> int
  member GetSlice : start:int option * finish:int option -> Vector<'T>
  member Permute : permutation:(int -> int) -> Vector<'T>
  member SetSlice : start:int option * finish:int option * source:Vector<'T> -> unit
  member ToArray : unit -> 'T []
  member ElementOps : INumeric<'T>
  member InternalValues : 'T []
  member Item : int -> 'T with get
  member Length : int
  member Norm : float
  member NumRows : int
  member StructuredDisplayAsArray : 'T []
  member Transpose : RowVector<'T>
  member Item : int -> 'T with set
  static member ( + ) : Vector<'T> * Vector<'T> -> Vector<'T>
  static member ( .* ) : Vector<'T> * Vector<'T> -> Vector<'T>
  static member ( * ) : Vector<'T> * 'T -> Vector<'T>
  static member ( * ) : Vector<'T> * RowVector<'T> -> Matrix<'T>
  static member ( * ) : 'T * Vector<'T> -> Vector<'T>
  static member ( - ) : Vector<'T> * Vector<'T> -> Vector<'T>
  static member ( ~- ) : Vector<'T> -> Vector<'T>
  static member ( ~+ ) : Vector<'T> -> Vector<'T>
end

Full name: Microsoft.FSharp.Math.Vector<_>

  type: Vector<'T>
  implements: System.Collections.Generic.IEnumerable<'T>
  implements: System.Collections.IEnumerable
  implements: System.Collections.IStructuralEquatable
  implements: System.Collections.IStructuralComparable
  implements: System.IComparable


--------------------

type Vector =
  | Vector of float array
  with
    member Item : i:int -> float
    member Dim : int
    member Length : float
    member Normal : Vector
    member private Values : float array
    static member InnerProd : a:Vector * b:Vector -> float
    static member Len2 : a:Vector -> float
    static member Normalize : a:Vector -> Vector
    static member Zero : n:int -> Vector
    static member Len : (Vector -> float)
    static member ( + ) : a:Vector * b:Vector -> Vector
    static member ( .*. ) : a:Vector * b:Vector -> float
    static member ( * ) : s:float * a:Vector -> Vector
    static member ( - ) : a:Vector * b:Vector -> Vector
  end

Full name: Snippet.Vector

  type: Vector
  implements: System.IEquatable<Vector>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Vector>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable


Represent a vector as an float array
Multiple items
val float : 'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------

type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>

  type: float<'Measure>
  implements: System.IComparable
  implements: System.IConvertible
  implements: System.IFormattable
  implements: System.IComparable<float<'Measure>>
  implements: System.IEquatable<float<'Measure>>
  inherits: System.ValueType


--------------------

type float = System.Double

Full name: Microsoft.FSharp.Core.float

  type: float
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<float>
  implements: System.IEquatable<float>
  inherits: System.ValueType
type 'T array = 'T []

Full name: Microsoft.FSharp.Core.array<_>

  type: 'T array
  implements: System.ICloneable
  implements: System.Collections.IList
  implements: System.Collections.ICollection
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.IStructuralEquatable
  implements: System.Collections.Generic.IList<'T>
  implements: System.Collections.Generic.ICollection<'T>
  implements: seq<'T>
  implements: System.Collections.IEnumerable
  inherits: System.Array
val v : Vector

  type: Vector
  implements: System.IEquatable<Vector>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Vector>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
member private Vector.Values : float array

Full name: Snippet.Vector.Values

shortcut to access the float array
val v' : float array

  type: float array
  implements: System.ICloneable
  implements: System.Collections.IList
  implements: System.Collections.ICollection
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.IStructuralEquatable
  implements: System.Collections.Generic.IList<float>
  implements: System.Collections.Generic.ICollection<float>
  implements: seq<float>
  implements: System.Collections.IEnumerable
  inherits: System.Array
member Vector.Item : i:int -> float

Full name: Snippet.Vector.Item

access a component of the vector
val i : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
property Vector.Values: float array

shortcut to access the float array
member Vector.Dim : int

Full name: Snippet.Vector.Dim

the vectors dimension = nr of components
module Array

from Microsoft.FSharp.Collections
val length : 'T [] -> int

Full name: Microsoft.FSharp.Collections.Array.length
val a : Vector

  type: Vector
  implements: System.IEquatable<Vector>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Vector>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
val b : Vector

  type: Vector
  implements: System.IEquatable<Vector>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Vector>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
val zip : 'T1 [] -> 'T2 [] -> ('T1 * 'T2) []

Full name: Microsoft.FSharp.Collections.Array.zip
val map : ('T -> 'U) -> 'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
module Helpers

from Snippet
val s : float

  type: float
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<float>
  implements: System.IEquatable<float>
  inherits: System.ValueType
static member Vector.InnerProd : a:Vector * b:Vector -> float

Full name: Snippet.Vector.InnerProd

computes the inner product (also known as scalar product) of two vectors
val sumBy : ('T -> 'U) -> 'T [] -> 'U (requires member ( + ) and member get_Zero)

Full name: Microsoft.FSharp.Collections.Array.sumBy
static member Vector.InnerProd : a:Vector * b:Vector -> float

computes the inner product (also known as scalar product) of two vectors
static member Vector.Len2 : a:Vector -> float

Full name: Snippet.Vector.Len2

the squared length of a vector
static member Vector.Len : (Vector -> float)

Full name: Snippet.Vector.Len

the length of a vector
namespace System
type Math =
  class
    static val PI : float
    static val E : float
    static member Abs : System.SByte -> System.SByte
    static member Abs : int16 -> int16
    static member Abs : int -> int
    static member Abs : int64 -> int64
    static member Abs : float32 -> float32
    static member Abs : float -> float
    static member Abs : decimal -> decimal
    static member Acos : float -> float
    static member Asin : float -> float
    static member Atan : float -> float
    static member Atan2 : float * float -> float
    static member BigMul : int * int -> int64
    static member Ceiling : decimal -> decimal
    static member Ceiling : float -> float
    static member Cos : float -> float
    static member Cosh : float -> float
    static member DivRem : int * int * int -> int
    static member DivRem : int64 * int64 * int64 -> int64
    static member Exp : float -> float
    static member Floor : decimal -> decimal
    static member Floor : float -> float
    static member IEEERemainder : float * float -> float
    static member Log : float -> float
    static member Log : float * float -> float
    static member Log10 : float -> float
    static member Max : System.SByte * System.SByte -> System.SByte
    static member Max : System.Byte * System.Byte -> System.Byte
    static member Max : int16 * int16 -> int16
    static member Max : uint16 * uint16 -> uint16
    static member Max : int * int -> int
    static member Max : uint32 * uint32 -> uint32
    static member Max : int64 * int64 -> int64
    static member Max : uint64 * uint64 -> uint64
    static member Max : float32 * float32 -> float32
    static member Max : float * float -> float
    static member Max : decimal * decimal -> decimal
    static member Min : System.SByte * System.SByte -> System.SByte
    static member Min : System.Byte * System.Byte -> System.Byte
    static member Min : int16 * int16 -> int16
    static member Min : uint16 * uint16 -> uint16
    static member Min : int * int -> int
    static member Min : uint32 * uint32 -> uint32
    static member Min : int64 * int64 -> int64
    static member Min : uint64 * uint64 -> uint64
    static member Min : float32 * float32 -> float32
    static member Min : float * float -> float
    static member Min : decimal * decimal -> decimal
    static member Pow : float * float -> float
    static member Round : float -> float
    static member Round : decimal -> decimal
    static member Round : float * int -> float
    static member Round : float * System.MidpointRounding -> float
    static member Round : decimal * int -> decimal
    static member Round : decimal * System.MidpointRounding -> decimal
    static member Round : float * int * System.MidpointRounding -> float
    static member Round : decimal * int * System.MidpointRounding -> decimal
    static member Sign : System.SByte -> int
    static member Sign : int16 -> int
    static member Sign : int -> int
    static member Sign : int64 -> int
    static member Sign : float32 -> int
    static member Sign : float -> int
    static member Sign : decimal -> int
    static member Sin : float -> float
    static member Sinh : float -> float
    static member Sqrt : float -> float
    static member Tan : float -> float
    static member Tanh : float -> float
    static member Truncate : decimal -> decimal
    static member Truncate : float -> float
  end

Full name: System.Math
System.Math.Sqrt(d: float) : float
static member Vector.Len2 : a:Vector -> float

the squared length of a vector
member Vector.Length : float

Full name: Snippet.Vector.Length
property Vector.Len: Vector -> float

the length of a vector
static member Vector.Normalize : a:Vector -> Vector

Full name: Snippet.Vector.Normalize

normalize a vector (the result will have the same direction but length 1)
property Vector.Length: float
member Vector.Normal : Vector

Full name: Snippet.Vector.Normal
static member Vector.Normalize : a:Vector -> Vector

normalize a vector (the result will have the same direction but length 1)
static member Vector.Zero : n:int -> Vector

Full name: Snippet.Vector.Zero

create a zero-vector
val n : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
val zeroCreate : int -> 'T []

Full name: Microsoft.FSharp.Collections.Array.zeroCreate
Multiple items
union case Matrix.Matrix: float [,] -> Matrix

--------------------

module Matrix

from Microsoft.FSharp.Math

--------------------

type Matrix<'T>
with
  interface System.Collections.Generic.IEnumerable<'T>
  interface System.Collections.IStructuralEquatable
  interface System.Collections.IStructuralComparable
  interface System.IComparable
  member Column : index:int -> Vector<'T>
  member Columns : start:int * length:int -> Matrix<'T>
  member Copy : unit -> Matrix<'T>
  override Equals : obj -> bool
  member GetDiagonal : int -> Vector<'T>
  override GetHashCode : unit -> int
  member GetSlice : start1:int option * finish1:int option * start2:int option * finish2:int option -> Matrix<'T>
  member PermuteColumns : permutation:(int -> int) -> Matrix<'T>
  member PermuteRows : permutation:(int -> int) -> Matrix<'T>
  member Region : starti:int * startj:int * lengthi:int * lengthj:int -> Matrix<'T>
  member Row : index:int -> RowVector<'T>
  member Rows : start:int * length:int -> Matrix<'T>
  member SetSlice : start1:int option * finish1:int option * start2:int option * finish2:int option * source:Matrix<'T> -> unit
  member ToArray2 : unit -> 'T [,]
  member ToArray2D : unit -> 'T [,]
  member ToRowVector : unit -> RowVector<'T>
  member ToVector : unit -> Vector<'T>
  member Diagonal : Vector<'T>
  member Dimensions : int * int
  member ElementOps : INumeric<'T>
  member InternalDenseValues : 'T [,]
  member InternalSparseColumnValues : int []
  member InternalSparseRowOffsets : int []
  member InternalSparseValues : 'T []
  member IsDense : bool
  member IsSparse : bool
  member Item : int * int -> 'T with get
  member NonZeroEntries : seq<int * int * 'T>
  member Norm : float
  member NumCols : int
  member NumRows : int
  member StructuredDisplayAsArray : obj
  member Transpose : Matrix<'T>
  member Item : int * int -> 'T with set
  static member ( + ) : Matrix<'T> * Matrix<'T> -> Matrix<'T>
  static member ( .* ) : Matrix<'T> * Matrix<'T> -> Matrix<'T>
  static member ( * ) : 'T * Matrix<'T> -> Matrix<'T>
  static member ( * ) : Matrix<'T> * 'T -> Matrix<'T>
  static member ( * ) : Matrix<'T> * Vector<'T> -> Vector<'T>
  static member ( * ) : Matrix<'T> * Matrix<'T> -> Matrix<'T>
  static member ( - ) : Matrix<'T> * Matrix<'T> -> Matrix<'T>
  static member ( ~- ) : Matrix<'T> -> Matrix<'T>
  static member ( ~+ ) : Matrix<'T> -> Matrix<'T>
end

Full name: Microsoft.FSharp.Math.Matrix<_>

  type: Matrix<'T>
  implements: System.Collections.Generic.IEnumerable<'T>
  implements: System.Collections.IEnumerable
  implements: System.Collections.IStructuralEquatable
  implements: System.Collections.IStructuralComparable
  implements: System.IComparable


--------------------

type Matrix =
  | Matrix of float [,]
  with
    member Column : i:int -> Vector
    member Columns : Vector []
    member NrColumns : int
    member NrRows : int
    member private Values : float [,]
    static member ColVectors : m:Matrix -> Vector []
    static member Create : vs:Vector array -> Matrix
    static member Create : rows:int * cols:int * f:(int -> int -> float) -> Matrix
    static member Transpose : m:Matrix -> Matrix
    static member Zero : rows:int * cols:int -> 'a [,]
    static member ( + ) : a:Matrix * b:Matrix -> Matrix
    static member ( * ) : a:Matrix * b:Matrix -> Matrix
    static member ( * ) : s:float * b:Matrix -> Matrix
    static member ( - ) : a:Matrix * b:Matrix -> Matrix
  end

Full name: Snippet.Matrix

  type: Matrix
  implements: System.IEquatable<Matrix>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Matrix>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable


represent a matrix as a 2-dimensional float array
val m : Matrix

  type: Matrix
  implements: System.IEquatable<Matrix>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Matrix>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
member private Matrix.Values : float [,]

Full name: Snippet.Matrix.Values

shortcut to the array
val m' : float [,]

  type: float [,]
  implements: System.ICloneable
  implements: System.Collections.IList
  implements: System.Collections.ICollection
  implements: System.Collections.IEnumerable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.IStructuralEquatable
  inherits: System.Array
member Matrix.NrRows : int

Full name: Snippet.Matrix.NrRows

the number of rows
module Array2D

from Microsoft.FSharp.Collections
val length1 : 'T [,] -> int

Full name: Microsoft.FSharp.Collections.Array2D.length1
property Matrix.Values: float [,]

shortcut to the array
member Matrix.NrColumns : int

Full name: Snippet.Matrix.NrColumns

the number of columns
val length2 : 'T [,] -> int

Full name: Microsoft.FSharp.Collections.Array2D.length2
member Matrix.Column : i:int -> Vector

Full name: Snippet.Matrix.Column

access a column-vector via its zero-based index
val z : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
member Matrix.Columns : Vector []

Full name: Snippet.Matrix.Columns

get all column-vectors as an array
member Matrix.Column : i:int -> Vector

access a column-vector via its zero-based index
static member Matrix.ColVectors : m:Matrix -> Vector []

Full name: Snippet.Matrix.ColVectors
property Matrix.Columns: Vector []

get all column-vectors as an array
val a : Matrix

  type: Matrix
  implements: System.IEquatable<Matrix>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Matrix>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
val b : Matrix

  type: Matrix
  implements: System.IEquatable<Matrix>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Matrix>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
val init : int -> int -> (int -> int -> 'T) -> 'T [,]

Full name: Microsoft.FSharp.Collections.Array2D.init
property Matrix.NrRows: int

the number of rows
property Matrix.NrColumns: int

the number of columns
val r : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
val c : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------

type List<'T> =
  | ( [] )
  | ( :: ) of 'T * 'T list
  with
    interface System.Collections.IEnumerable
    interface System.Collections.Generic.IEnumerable<'T>
    member Head : 'T
    member IsEmpty : bool
    member Item : index:int -> 'T with get
    member Length : int
    member Tail : 'T list
    static member Cons : head:'T * tail:'T list -> 'T list
    static member Empty : 'T list
  end

Full name: Microsoft.FSharp.Collections.List<_>

  type: List<'T>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<'T>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<'T>
  implements: System.Collections.IEnumerable
val map : ('T -> 'U) -> 'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.map
val sum : 'T list -> 'T (requires member ( + ) and member get_Zero)

Full name: Microsoft.FSharp.Collections.List.sum
static member Matrix.Transpose : m:Matrix -> Matrix

Full name: Snippet.Matrix.Transpose

computes the transpose of a matrix
val x : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
val y : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
static member Matrix.Create : vs:Vector array -> Matrix

Full name: Snippet.Matrix.Create

creates a matrix from a array of columnvectors
val vs : Vector array

  type: Vector array
  implements: System.ICloneable
  implements: System.Collections.IList
  implements: System.Collections.ICollection
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.IStructuralEquatable
  implements: System.Collections.Generic.IList<Vector>
  implements: System.Collections.Generic.ICollection<Vector>
  implements: seq<Vector>
  implements: System.Collections.IEnumerable
  inherits: System.Array
val l : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
property System.Array.Length: int
static member Matrix.Create : rows:int * cols:int * f:(int -> int -> float) -> Matrix

Full name: Snippet.Matrix.Create

creates a matrix with an generator-function (the row r and col c of the matrix will have a value of f(r,c))
val rows : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
val cols : int

  type: int
  implements: System.IComparable
  implements: System.IFormattable
  implements: System.IConvertible
  implements: System.IComparable<int>
  implements: System.IEquatable<int>
  inherits: System.ValueType
val f : (int -> int -> float)
static member Matrix.Zero : rows:int * cols:int -> 'a [,]

Full name: Snippet.Matrix.Zero

creates a zero-Matrix
val zeroCreate : int -> int -> 'T [,]

Full name: Microsoft.FSharp.Collections.Array2D.zeroCreate
val private project : Vector -> Vector -> Vector

Full name: Snippet.GramSchmidt.project

projects a vector onto another vector
val baseV : Vector

  type: Vector
  implements: System.IEquatable<Vector>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Vector>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
val Orthogonalize : Vector list -> Vector list

Full name: Snippet.GramSchmidt.Orthogonalize

computes a set of orthogonal vectors that span the same subspace as the vectors in vs
 see the Wikipedia-article at http://en.wikipedia.org/wiki/Gram_schmidt for a good
 explanation of this method

val vs : Vector list

  type: Vector list
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<Vector>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<Vector>
  implements: System.Collections.IEnumerable
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>

  type: 'T list
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<'T>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<'T>
  implements: System.Collections.IEnumerable
val calcNextVec : (Vector -> Vector list -> Vector)
val cur : Vector

  type: Vector
  implements: System.IEquatable<Vector>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Vector>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
val found : Vector list

  type: Vector list
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<Vector>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<Vector>
  implements: System.Collections.IEnumerable
val vs' : Vector list

  type: Vector list
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<Vector>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<Vector>
  implements: System.Collections.IEnumerable
val calcVecs : (Vector list -> Vector list -> Vector list)
val toDo : Vector list

  type: Vector list
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<Vector>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<Vector>
  implements: System.Collections.IEnumerable
val rest : Vector list

  type: Vector list
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<Vector>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<Vector>
  implements: System.Collections.IEnumerable
val rev : 'T list -> 'T list

Full name: Microsoft.FSharp.Collections.List.rev
val OrthogonalizeNormal : (Vector list -> Vector list)

Full name: Snippet.GramSchmidt.OrthogonalizeNormal

computes a set of orthonormal vectors that span the same subspace as the vectors in vs
module QRdecomposition

from Snippet

decomposes a square matrix into a product of an orthongal and an upper triangular matrix
val UsingGramSchmidt : Matrix -> Matrix * Matrix

Full name: Snippet.QRdecomposition.UsingGramSchmidt

computes the QR-decomposition using the Gram-Schmidt method
 see the Wikipedia-article at http://en.wikipedia.org/wiki/QR_decomposition for a good
 explanation of this method

val colVs : Vector []

  type: Vector []
  implements: System.ICloneable
  implements: System.Collections.IList
  implements: System.Collections.ICollection
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.IStructuralEquatable
  implements: System.Collections.Generic.IList<Vector>
  implements: System.Collections.Generic.ICollection<Vector>
  implements: seq<Vector>
  implements: System.Collections.IEnumerable
  inherits: System.Array
val normVs : Vector []

  type: Vector []
  implements: System.ICloneable
  implements: System.Collections.IList
  implements: System.Collections.ICollection
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.IStructuralEquatable
  implements: System.Collections.Generic.IList<Vector>
  implements: System.Collections.Generic.ICollection<Vector>
  implements: seq<Vector>
  implements: System.Collections.IEnumerable
  inherits: System.Array
val ofList : 'T list -> 'T []

Full name: Microsoft.FSharp.Collections.Array.ofList
module GramSchmidt

from Snippet

computes a set of orthogonal or orthonormal vectors that spans the same
 subspace as the given vector-set

val ofArray : 'T [] -> 'T list

Full name: Microsoft.FSharp.Collections.List.ofArray
val Q : Matrix

  type: Matrix
  implements: System.IEquatable<Matrix>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Matrix>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
Multiple overloads
static member Matrix.Create : vs:Vector array -> Matrix

creates a matrix from a array of columnvectors
static member Matrix.Create : rows:int * cols:int * f:(int -> int -> float) -> Matrix

creates a matrix with an generator-function (the row r and col c of the matrix will have a value of f(r,c))
val R : Matrix

  type: Matrix
  implements: System.IEquatable<Matrix>
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<Matrix>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable

More information

Link: http://fssnip.net/3p
Posted: 3 years ago
Author: Carsten König
Tags: QR-decomposition, Gram-Schmidt, linear algebra, matrix, vector