Skip to content

Commit

Permalink
use normal(0,1) to generate the orthogonal matrix
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <kemingy94@gmail.com>
  • Loading branch information
kemingy committed Sep 25, 2024
1 parent 8001d3f commit e4f1ec3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ faer = "0.19"
log = "0.4"
num-traits = "0.2"
rand = "0.8"
rand_distr = "0.4.3"
serde = "1"
serde_json = "1"

Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use std::path::Path;
use faer::{Col, ColRef, Mat, MatRef};
use num_traits::{FromBytes, ToBytes};
use rand::distributions::{Distribution, Uniform};
use rand_distr::StandardNormal;

use crate::consts::THETA_LOG_DIM;

/// Generate a random orthogonal matrix from QR decomposition.
pub fn gen_random_qr_orthogonal(dim: usize) -> Mat<f32> {
let mut rng = rand::thread_rng();
let uniform = Uniform::<f32>::new(0.0, 1.0);
let random = Mat::from_fn(dim, dim, |_, _| uniform.sample(&mut rng));
let random: Mat<f32> = Mat::from_fn(dim, dim, |_, _| StandardNormal.sample(&mut rng));
random.qr().compute_q()
}

Expand Down

0 comments on commit e4f1ec3

Please sign in to comment.