Method: Stick::Vector#house
- Defined in:
- lib/stick/matrix.rb
#house ⇒ Object
Computes the Householder vector (MC, Golub, p. 210, algorithm 5.1.1)
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/stick/matrix.rb', line 160 def house s = self[1..length-1] sigma = s.inner_product(s) v = clone; v[0] = 1 if sigma == 0 beta = 0 else mu = Math.sqrt(self[0] ** 2 + sigma) if self[0] <= 0 v[0] = self[0] - mu else v[0] = - sigma.quo(self[0] + mu) end v2 = v[0] ** 2 beta = 2 * v2.quo(sigma + v2) v /= v[0] end return v, beta end |