-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Rustify lempel_ziv_complexity (#107)
- Loading branch information
1 parent
14fa081
commit c5a87f6
Showing
8 changed files
with
162 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1 @@ | ||
pub mod feature_extractor; | ||
use ndarray::{Array2, ArrayView2}; | ||
use faer::{IntoFaer, IntoNdarray, Side}; | ||
use faer::prelude::*; | ||
|
||
|
||
pub fn faer_lstsq( | ||
x: ArrayView2<f64>, | ||
y: ArrayView2<f64>, | ||
) -> Array2<f64> { | ||
|
||
// Solving X * beta = rhs using Faer-rs | ||
// This speeds things up significantly but is only suitable for m x k matrices | ||
// where m >> k. | ||
|
||
// Zero Copy | ||
let x_ = x.into_faer(); | ||
let y_ = y.into_faer(); | ||
// Solver. Use closed form solution to solve the least square | ||
// This is faster because xtx has small dimension. So we use the closed | ||
// form solution approach. | ||
let xt = x_.transpose(); | ||
let xtx = xt * x_; | ||
let cholesky = xtx.cholesky(Side::Lower).unwrap(); // Can unwrap because xtx is positive semidefinite | ||
let xtx_inv = cholesky.inverse(); | ||
// Solution | ||
let beta = xtx_inv * xt * y_; | ||
// To Ndarray (for NumPy Interop), generate output. Will Copy. | ||
let out = beta.as_ref().into_ndarray(); | ||
out.to_owned() | ||
} | ||
pub mod feature_extractor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.