fslaborg / FSharp.Stats

statistical testing, linear algebra, machine learning, fitting and signal processing in F#
https://fslab.org/FSharp.Stats/
Other
210 stars 56 forks source link

[Feature Request] generic binning (binmap) function #259

Closed kMutagene closed 1 year ago

kMutagene commented 1 year ago

Is your feature request related to a problem? Please describe.

While functions such as Distributions.Empirical.create are great for investigating frequency of float values in a dataset, it might be nice to have a generic binning function that keeps the original data.

Describe the solution you'd like A generic binning function that returns bin => data in bin map.

As a specific example, when I have a dataset of the following type:

type MyType {A: string; B: float}

I would like to use a function e.g. bin<'T> with signature

let bin<'T> (projection: 'T -> float) (binSize: float) (data: seq<'T>) : Map<float,seq<'T>> = ...

That bins data based on the projection function and returns a Map with the binned data. The advantage of this approach here is that i would not loose the association of the fields A and B in the record type.

Describe alternatives you've considered Proceeding my life without having this function