-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
random init and iris pipeline update
- Loading branch information
Showing
7 changed files
with
198 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
iris.csv |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::prelude::*; | ||
use num::{Float, NumCast}; | ||
use rand::prelude::*; | ||
use rand_distr::{Distribution, Normal, StandardNormal}; | ||
|
||
impl<T> ChunkedArray<T> | ||
where | ||
T: PolarsNumericType, | ||
T::Native: Float + NumCast, | ||
{ | ||
/// Create `ChunkedArray` with samples from a Normal distribution. | ||
pub fn rand_normal(name: &str, length: usize, mean: f64, std_dev: f64) -> Result<Self> { | ||
let normal = Normal::new(mean, std_dev)?; | ||
let mut builder = PrimitiveChunkedBuilder::<T>::new(name, length); | ||
for _ in 0..length { | ||
let smpl = normal.sample(&mut rand::thread_rng()); | ||
let smpl = NumCast::from(smpl).unwrap(); | ||
builder.append_value(smpl) | ||
} | ||
Ok(builder.finish()) | ||
} | ||
|
||
/// Create `ChunkedArray` with samples from a Standard Normal distribution. | ||
pub fn rand_standard_normal(name: &str, length: usize) -> Self { | ||
let mut builder = PrimitiveChunkedBuilder::<T>::new(name, length); | ||
for _ in 0..length { | ||
let smpl: f64 = thread_rng().sample(StandardNormal); | ||
let smpl = NumCast::from(smpl).unwrap(); | ||
builder.append_value(smpl) | ||
} | ||
builder.finish() | ||
} | ||
} |
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