ruby-numo / numo-linalg

Linear Algebra Library for Ruby/Numo::NArray
BSD 3-Clause "New" or "Revised" License
38 stars 9 forks source link

[Propose] Add methods for finding an orthogonal basis #23

Closed yoshoku closed 6 years ago

yoshoku commented 6 years ago

I would like to add new methods for finding an orthogonal basis like scipy.linalg.orth and scipy.linalg.null_space methods.

> a = Numo::DFloat[[2, 0, 0], [0, 5, 0]]
=> Numo::DFloat#shape=[2,3]
[[2, 0, 0],
 [0, 5, 0]]
> Numo::Linalg.orth(a)
=> Numo::DFloat(view)#shape=[2,2]
[[0, 1],
 [1, 0]]
> Numo::Linalg.orth(a.transpose)
=> Numo::DFloat(view)#shape=[3,2]
[[0, 1],
 [1, 0],
 [0, 0]]
> b = Numo::DFloat.new(3, 5).rand
> z = Numo::Linalg.null_space(b)
> z.shape
=> [5, 2]
> b.dot(z)
=> Numo::DFloat#shape=[3,2]
[[1.92144e-17, -1.90014e-17],
 [6.35517e-17, -2.31759e-17],
 [4.25885e-17, 1.67474e-17]]
> z.transpose.dot(z)
=> Numo::DFloat#shape=[2,2]
[[1, -4.2071e-17],
 [-4.2071e-17, 1]]