Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampling is not accurate? #8

Open
kchuangk opened this issue Oct 17, 2024 · 1 comment
Open

Sampling is not accurate? #8

kchuangk opened this issue Oct 17, 2024 · 1 comment

Comments

@kchuangk
Copy link

kchuangk commented Oct 17, 2024

Taking the code sample below, the maximum sample is always below 5.0.

use kernel_density_estimation::prelude::*;

fn main() {

    let observations: Vec<f32> = vec![4.99,5.0,5.01];
    
    let kde=KernelDensityEstimator::new(observations,Scott,Normal);
    let pdf_dataset: Vec<f32> = (0..101).into_iter().map(|x| x as f32 * 0.1).collect();
    let sample=kde.sample(pdf_dataset.as_slice(),10000);
    println!("{:?}",sample);
}
@kchuangk
Copy link
Author

There's definitely an issue on the cut off on the RHS - the max is always 0.5 Here's another sample code.

The summary stats for the sample are - multiple runs produce a similar result.
25%:0.4925
50%:0.495
75%:0.4974
max:0.5
mean:0.495
median:0.495
min:0.49

use kernel_density_estimation::prelude::*;

fn main() {

    let kde=KernelDensityEstimator::new(vec![0.4999999,0.50,0.5000001],Scott,Normal);
    let sample3=kde.sample(pdf_dataset.as_slice(),10000);
    // println!("{:?}",sample);
    let mut df = df!("tester"=>sample1,"tester2"=>sample2,"test_5"=>sample3).unwrap();
    let mut file = std::fs::File::create("tmp.csv").unwrap();
    CsvWriter::new(&mut file).finish(&mut df).unwrap();
}

@kchuangk kchuangk reopened this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant