Skip to content

Commit

Permalink
2.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
liborty committed Jun 16, 2024
1 parent d171e6e commit 6800309
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rstats"
version = "2.1.9"
version = "2.1.10"
authors = ["Libor Spacek"]
edition = "2021"
description = "Statistics, Information Measures, Data Analysis, Linear Algebra, Clifford Algebra, Machine Learning, Geometric Median, Matrix Decompositions, Mahalanobis Distance, Hulls, Multithreading.."
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ datavec.somemethod::<f64>(arg)

Methods implemented by this trait:

* Vector additions, subtractions and products (scalar, kronecker, outer),
* Vector additions, subtractions and products (scalar, Kronecker, outer),
* Other relationships and measures of difference,
* Pearson's, Spearman's and Kendall's correlations,
* Joint pdf, joint entropy, statistical independence (based on mutual information).
Expand Down Expand Up @@ -341,6 +341,8 @@ Methods which take an additional generic vector argument, such as a vector of we

## Appendix: Recent Releases

* **Version 2.1.10** - Added `project` of a `TriangMat` to a subspace given by a subspace index.

* **Version 2.1.9** - Added multiplications and more tests for `TriangMat`.

* **Version 2.1.8** - Improved `TriangMat::diagonal()`, restored `TriangMat::determinant()`, tidied up `triangmat` test.
Expand Down
24 changes: 12 additions & 12 deletions src/triangmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,25 @@ impl TriangMat {
TriangMat { kind: 2, data }
}

/// Project symmetric/antisymmetric triangmat to a smaller one of the same kind,
/// into a subspace specified by an ascending index of dimensions.
/// Deletes all rows and columns of the missing dimensions.
/// Projects to a smaller TriangMat of the same kind,
/// in a subspace given by a subspace index.
/// Deletes all the rows and columns of the other dimensions.
/// The kept ones retain their original order.
pub fn project(&self, index: &[usize]) -> Self {
let mut res = Vec::with_capacity(sumn(index.len()));
for &row_idx in index {
let row = self.row(row_idx);
for &column_idx in index {
if column_idx >= row.len() {
break;
};
res.push(row[column_idx]);
}
}
for &rownum in index {
let row = self.row(rownum);
for &colnum in index {
if colnum > rownum { break; };
res.push(row[colnum]);
};
};
TriangMat {
kind: self.kind,
data: res,
}
}

/// Copy one raw data row from TriangMat
/// To interpret the kind (plain, symmetric, assymetric, transposed),
/// use `realrow,realcolumn,to_full`
Expand Down
10 changes: 6 additions & 4 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ fn triangmat() -> Result<(), RE> {
println!("Symmetric positive definite matrix A\n{}",cov.gr());
println!("Full form of A:\n{}",cov.to_full().gr());
let mut chol = cov.cholesky()?;
println!("Cholesky L matrix, such that A=LL'\n{}",chol.gr());
println!("Cholesky L matrix, such that A=LL'\n{}",chol.gr());
println!("Diagonal of L: {}",chol.diagonal().gr());
println!("Determinant det(A): {}",chol.determinant().gr());
let full = chol.to_full();
println!("Full L matrix\n{}",full.gr());
let tchol = &chol.clone_transpose();
println!("A reconstructed from full(L)full(L'):\n{}",full.matmult(&tchol.to_full())?.gr());
println!("A reconstructed by more efficient triangular multiplication LL'\n{}",chol.mult(tchol).gr());
println!("A reconstructed from full(L)full(L')\n{}",full.matmult(&tchol.to_full())?.gr());
println!("A reconstructed by direct triangular multiplication LL'\n{}",chol.mult(tchol).gr());
let d = 4_usize;
let v = ranv_f64(d)?;
println!("Random test vector:\n{}", v.gr());
Expand Down Expand Up @@ -281,11 +281,13 @@ fn triangmat() -> Result<(), RE> {
println!("Row[2] of C\n{}",cov.realrow(2).gr());
chol = cov.cholesky()?;
println!("Cholesky of C:\n{GR}{chol}{UN} ");
let small_chol = chol.project(&[0,2,4,5]);
println!("Projected chol:\n{GR}{small_chol}{UN} ");
println!("Determinant of C: {}",chol.determinant().gr());
println!("Row[2] of Cholesky\n{}",chol.realrow(2).gr());
println!("Column[2] of Cholesky\n{}",chol.realcolumn(2).gr());
println!("C reconstructed by triangular multiplication LL'\n{}",
chol.mult(&TriangMat{kind:chol.kind+3,data:chol.data.clone()}).gr());
chol.mult(&chol.clone_transpose()).gr());
Ok(())
}

Expand Down

0 comments on commit 6800309

Please sign in to comment.