mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-19 20:30:01 +00:00
Enhance documentation with additional compute examples and stats functions
This commit is contained in:
parent
23a01dab07
commit
68a01ab528
@ -22,8 +22,6 @@ assert_eq!(col_means.data(), &[1.5, 3.5]);
|
||||
|
||||
## Correlation
|
||||
|
||||
Correlation functions help measure linear relationships between datasets.
|
||||
|
||||
```rust
|
||||
# extern crate rustframe;
|
||||
use rustframe::compute::stats::{pearson, covariance};
|
||||
@ -51,5 +49,19 @@ let pdf = normal_pdf(x, 0.0, 1.0);
|
||||
assert_eq!(pdf.data().len(), 2);
|
||||
```
|
||||
|
||||
### More Compute Examples
|
||||
|
||||
```rust
|
||||
# extern crate rustframe;
|
||||
use rustframe::matrix::Matrix;
|
||||
use rustframe::compute::stats::inferential::t_test;
|
||||
|
||||
let sample1 = Matrix::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0], 1, 5);
|
||||
let sample2 = Matrix::from_vec(vec![6.0, 7.0, 8.0, 9.0, 10.0], 1, 5);
|
||||
let (t_statistic, p_value) = t_test(&sample1, &sample2);
|
||||
assert!((t_statistic + 5.0).abs() < 1e-5);
|
||||
assert!(p_value > 0.0 && p_value < 1.0);
|
||||
```
|
||||
|
||||
With the basics covered, explore predictive models in the
|
||||
[machine learning](./machine-learning.md) chapter.
|
||||
|
@ -73,5 +73,27 @@ assert_eq!(frame.sum_vertical(), vec![3.0, 7.0]);
|
||||
assert_eq!(frame.sum_horizontal(), vec![4.0, 6.0]);
|
||||
```
|
||||
|
||||
## Matrix Operations
|
||||
|
||||
```rust
|
||||
# extern crate rustframe;
|
||||
use rustframe::matrix::Matrix;
|
||||
|
||||
let data1 = Matrix::from_vec(vec![1.0, 2.0, 3.0, 4.0], 2, 2);
|
||||
let data2 = Matrix::from_vec(vec![5.0, 6.0, 7.0, 8.0], 2, 2);
|
||||
|
||||
let sum = data1.clone() + data2.clone();
|
||||
assert_eq!(sum.data(), vec![6.0, 8.0, 10.0, 12.0]);
|
||||
|
||||
let product = data1.clone() * data2.clone();
|
||||
assert_eq!(product.data(), vec![5.0, 12.0, 21.0, 32.0]);
|
||||
|
||||
let scalar_product = data1.clone() * 2.0;
|
||||
assert_eq!(scalar_product.data(), vec![2.0, 4.0, 6.0, 8.0]);
|
||||
|
||||
let equals = data1 == data1.clone();
|
||||
assert_eq!(equals, true);
|
||||
```
|
||||
|
||||
With the basics covered, continue to the [compute features](./compute.md)
|
||||
chapter for statistics and analytics.
|
||||
|
@ -35,6 +35,25 @@ let v2 = rng.next_u64();
|
||||
assert_ne!(v1, v2);
|
||||
```
|
||||
|
||||
## Stats Functions
|
||||
|
||||
```rust
|
||||
# extern crate rustframe;
|
||||
use rustframe::matrix::Matrix;
|
||||
use rustframe::compute::stats::descriptive::{mean, median, stddev};
|
||||
|
||||
let data = Matrix::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0], 1, 5);
|
||||
|
||||
let mean_value = mean(&data);
|
||||
assert_eq!(mean_value, 3.0);
|
||||
|
||||
let median_value = median(&data);
|
||||
assert_eq!(median_value, 3.0);
|
||||
|
||||
let std_value = stddev(&data);
|
||||
assert_eq!(std_value, 2.0_f64.sqrt());
|
||||
```
|
||||
|
||||
Upcoming utilities will cover:
|
||||
|
||||
- Data import/export helpers
|
||||
|
Loading…
x
Reference in New Issue
Block a user