diff options
| author | Alexander <alexanderkabua@gmail.com> | 2022-04-27 21:07:30 +0300 |
|---|---|---|
| committer | Alexander <alexanderkabua@gmail.com> | 2022-04-27 21:07:30 +0300 |
| commit | 8ffde4938793d2d50bd72b61d5bb35f58bc14e1e (patch) | |
| tree | 48222f7d95a7ee13f3adb220007af5748f468bda /src | |
| parent | ef2de72b9afd00df2d2fdc59044dc8e2fbfee5c6 (diff) | |
| download | correlation_rust-8ffde4938793d2d50bd72b61d5bb35f58bc14e1e.tar.gz | |
implement correlation for dataset
Diffstat (limited to 'src')
| -rw-r--r-- | src/correlations.rs | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/correlations.rs b/src/correlations.rs index 506f807..7d5851d 100644 --- a/src/correlations.rs +++ b/src/correlations.rs @@ -1,3 +1,6 @@ +use core::panic; +use std::io::BufRead; + use rgsl::{ randist::t_distribution::{tdist_P, tdist_Q}, statistics::{correlation, spearman}, @@ -161,7 +164,44 @@ impl <'a> Compute<'a>{ } - fn compute(){ + fn compute(&self) -> Vec<f64>{ + + //read from file); + use crate::reader::BufferReader; + use crate::correlations::Correlation; + + let mut corr_results:Vec<(f64,f64)> = Vec::new(); + let reader = BufferReader::new(self.dataset_path); + + match reader { + Ok(mut buffer_read) => { + + let mut n_string = String::new(); + + while let Some(val) = buffer_read.read_line(& mut n_string){ + if let Ok(array_new_val) = val { + let new_array= array_new_val + .split_whitespace() + .map(|s| s.parse().expect("parse error")) + .collect::<Vec<f64>>(); + + let pearson = Pearson::new(new_array.len()); + let results = pearson.correlate(&[1.2,1.1,1.3,1.6,1.8],&[1.2,1.1,1.3,1.6,1.8]); + corr_results.push(results) + + + } + + } + + + + } + + Err(_) =>panic!("an error ocurred") + } + + todo!() @@ -219,4 +259,14 @@ mod tests { method:CorrelationMethod::Pearson }) } + + #[test] + fn test_compute(){ + let compute_obj = Compute::new("pearson","/home/kabui/correlation_rust/mock_dataset.txt",&[4. ,5. ,1. ,1. ,6. ,1. ,8. ,7. + ]); + + let corr_results = compute_obj.compute(); + + assert_eq!(corr_results,[]) + } } \ No newline at end of file |
