Skip to content

Comments

mir.random.discrete - fix for zero probilities#236

Merged
9il merged 2 commits intolibmir:masterfrom
wilzbach:fix_mixture3
Jun 26, 2016
Merged

mir.random.discrete - fix for zero probilities#236
9il merged 2 commits intolibmir:masterfrom
wilzbach:fix_mixture3

Conversation

@wilzbach
Copy link
Member

(in reference to #235)

As @WebDrake pointed out Discrete doesn't handle zero probabilities well.
Also as we don't use chi-squared tests, but I think it's at least helpful to insert the assert's for the currently tested distributions.

With zero probs we can't use lowerBound, because it will it will not stop on the first element, but go to all equal element. Hence we either count the first category twice or the third one.
Here's an example of what's going on:

import std.stdio;
import std.range;
auto cdPoints = [1, 3, 3, 4];
foreach (el; 0..5)
{
    writeln(el, "->", cdPoints.assumeSorted!"a < b".lowerBound(el));
}

foreach (el; 0..5)
    writeln(el, "->", cdPoints.assumeSorted!"a <= b".lowerBound(el));
0->[]
1->[] // would count first category twice
2->[1]
3->[1]
4->[1, 3, 3] // only for "[]"

0->[]
1->[1]
2->[1]
3->[1, 3, 3] // would count third category (the zero one)
4->[1, 3, 3, 4] //only for "[]"

// sample from the discrete distribution
auto obs = new uint[cdPoints.length];
foreach (i; 0..1000)
foreach (i; 0..10_000)
Copy link
Member Author

@wilzbach wilzbach Jun 26, 2016

Choose a reason for hiding this comment

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

the split looks too random with 1000

@codecov-io
Copy link

codecov-io commented Jun 26, 2016

Current coverage is 96.53%

Merging #236 into master will increase coverage by <.01%

@@             master       #236   diff @@
==========================================
  Files            19         19          
  Lines          3253       3262     +9   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           3140       3149     +9   
  Misses          113        113          
  Partials          0          0          

Sunburst

Powered by Codecov. Last updated by 220b2c8...4a03dd9

unittest
{
import std.random : Random;
auto gen = Random(42);
Copy link
Member

@9il 9il Jun 26, 2016

Choose a reason for hiding this comment

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

OK, but don not use Random alias then. Use exact name instead.

Choose a reason for hiding this comment

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

Agree, it's better to specify an exact generator just in case someone later adds some tests that depend on the pseudo-random sequence.

@wilzbach
Copy link
Member Author

OK, but don not use Random alias then. Use exact name instead.

Ok - done ;-)

@9il 9il merged commit 819ea03 into libmir:master Jun 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants