FSharp.Stats icon indicating copy to clipboard operation
FSharp.Stats copied to clipboard

[Feature Request] Unify `Support` syntax for all Distributions

Open Freymaurer opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. The syntax for the static member Support ... functions are written in a different syntax.

Bernoulli has a list, whereas hypergeometric returns a tuple.

https://github.com/fslaborg/FSharp.Stats/blob/262f1acf2cbeeaf008c272774d008d6d462f1022/src/FSharp.Stats/Distributions/Discrete.fs#L55-L57

https://github.com/fslaborg/FSharp.Stats/blob/262f1acf2cbeeaf008c272774d008d6d462f1022/src/FSharp.Stats/Distributions/Discrete.fs#L228-L230

Describe the solution you'd like Maybe use this issue to discuss not only unifying the syntax, but reworking it to be more intuitive and usable.

Freymaurer avatar Jun 24 '22 09:06 Freymaurer

I think the best way to model the support is to use FSharp.Stats.Inverval<'a>. Intervals support generic type inputs, therefore even multidimensional distributions would be covered.

bvenn avatar Jul 19 '23 12:07 bvenn

https://github.com/fslaborg/FSharp.Stats/blob/7de8b8202a7225bf3e120a0a273243ca0555d25d/src/FSharp.Stats/Intervals.fs#L7-L9

We may consider having static member (for overloads) or at least the first one:

ofTuple: ('a * 'a) -> Interval<'a>
ofTuple: ('a * 'a) option -> Interval<'a>

Should the implementation do a comparison in case the values are swapped, and what should occur if they are?

Also, may be useful to offer the reverse:

toTuple: 'a Interval -> ('a * 'a) option

If the type is meant only for closed interval (rather than a larger set of those), maybe it is better to just name it ClosedInterval also.

smoothdeveloper avatar Jul 19 '23 13:07 smoothdeveloper

Totally agree to the ofTuple and toTuple member:+1:

I'm not sure if in any case it is allowed to have endValue < startValue. I dont't think so and therefore I would add a check that fails if the input is meaningless.

It may be an option to update the Interval type with a Type property that sets if the interval is closed/halfopen_right/halfopen_left/open.

bvenn avatar Jul 19 '23 15:07 bvenn