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

Ideal and robust soliton distribution #119

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

refugeesus
Copy link

Hello all.

I have added in an implementation for the ideal and robust soliton distributions which are required in ECC and coding method implementations I am working on. To my knowledge these are correctly implemented as the libraries I utilize them in function as expected in their tests.

There are likely methods which should be implemented for the purposes of this library which I have not completed, and if so, I would be happy to complete them so this can be merged appropriately. I hope this has been added in appropriately, as it is a bit of an odd implementation of discrete uniform distributions. If the structure should change it would be helpful to have some guidance for what is best.

/// The 'IdealSoliton' trait provides an interface for interacting
/// with discrete statistical distributions from integers 1..N with
/// N as the single parameter for the distribution
pub trait Soliton<T, K> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traits are often, but not always, a contract on types one does not yet know about. In this case the trait is superfluous, as there only seem to be two soliton distributions, both of which are provided.

}

#[derive(Debug, Clone, PartialEq)]
pub struct RobustSolitonDistribution {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct seems forgotten code after a refactor? It's not used anywhere and has no constructor, but private fields.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, missed this. Will remove.

if max < 1 {
Err(StatsError::BadParams)
} else {
let pmf_table: Vec<f64> = Vec::with_capacity(max as usize);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is inferred and can be elided.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


impl Distribution<f64> for RobustSoliton {
fn sample<R: Rng + ?Sized>(&self, r: &mut R) -> f64 {
r.gen_range(0, 1) as f64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems off.

}

impl IdealSoliton {
/// Constructs a new discrete uniform distribution with a minimum value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are seven doc strings referencing the discrete uniform distribution instead of the (ideal|robust) soliton distribution.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to update this as had been done in robust soliton. 👍

Comment on lines +153 to +156
fn mean(&self) -> f64 {
let sum: f64 = Iterator::sum(self.cumulative_probability_table.iter());
let mean = sum / self.cumulative_probability_table.len() as f64;
mean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be clearer as .iter().sum()

Can you explain how this calculation works? As far as I know, there are two equivalent formulas for calculating the mean: Sum(n*p(n)) or when using cumulative probability Sum(P(X>n)) = Sum(1-P(X<=n)) = Sum(1-CPF(n))
I do not see either of them being used here.

@vks vks mentioned this pull request May 15, 2021
7 tasks
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

Successfully merging this pull request may close these issues.

2 participants