-
Notifications
You must be signed in to change notification settings - Fork 84
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
base: master
Are you sure you want to change the base?
Conversation
/// 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> { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 👍
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 |
There was a problem hiding this comment.
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.
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.