Skip to main content

orthogonal

Function orthogonal 

Source
pub fn orthogonal<T: Float>(
    key: &Key<Native>,
    rows: usize,
    cols: usize,
    scale: f64,
) -> Array<Native, T>
Expand description

An orthogonal matrix of shape [rows, cols] scaled by scale (jax.nn.initializers.orthogonal(scale) for a matrix): the Q of the QR decomposition of a matrix of standard normal values, with the signs that make the diagonal of R positive (so Q does not depend on the QR algorithm, up to rounding).

ยงExamples

use ruxla_core::random;
use ruxla_nn::init::orthogonal;

let q = orthogonal::<f32>(&random::key(0), 4, 3, 1.0);
let v = q.to_vec();
// The columns are orthonormal.
let dot = |i: usize, j: usize| (0..4).map(|r| v[r * 3 + i] * v[r * 3 + j]).sum::<f32>();
assert!((dot(0, 0) - 1.0).abs() < 1e-5 && dot(0, 1).abs() < 1e-5);