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

[Feature Request] Add Parameter field to Distributions #271

Closed
bvenn opened this issue Jun 29, 2023 · 1 comment
Closed

[Feature Request] Add Parameter field to Distributions #271

bvenn opened this issue Jun 29, 2023 · 1 comment

Comments

@bvenn
Copy link
Member

bvenn commented Jun 29, 2023

Problem

Currently the only option to get access to parameters from already initialized distribution is toString(). Of course in most cases it is not necessary to provide the parameters from a distribution because you still have access to the parameters the distribution was initialized with.

However in special cases in which an algorithm takes instances of the Distribution interface as input and e.g. fits the best fitting distribution, it may be beneficial to have access to the parameters to report them along with the optimized distribution.

Example

open FSharp.Stats


let normal = 
    Distributions.Continuous.Normal.Init 12. 0.4

let bernoulli = 
    Distributions.Discrete.Bernoulli.Init 0.2

let functionThatTakesDistributionAsInput (dists: Distributions.Distribution<'a> []) (sample: float []) =
    dists
    |> Array.map (fun singleDistribution -> 
        //do some stuff to assess the quality of the distribution fit to the sample
        let fitQuality = 13.37
        match singleDistribution.Parameters with 
            | Distributions.Normal x -> printfn "The normal distribution with Mean: %.2f and StDev: %f has a fit quality of %.2f" x.Mean x.StandardDeviation fitQuality
            | Distributions.Bernoulli x -> printfn "The bernoulli distribution with P: %f has a fit quality of %.2f" x.P fitQuality
            | _ -> failwithf "Distribution type was not expected within this function!"
        fitQuality
    ) 


functionThatTakesDistributionAsInput [|normal;bernoulli|] [|0..10|]

The result would be:

The bernoulli distribution with P: 0.200000 has a fit quality of 13.37
val it: float array = [|13.37; 13.37|]```


## Solution

Add parameter types for each distribution that are summarized as `DistributionParameter` type. This type should be added to the distribution interface.
bvenn added a commit that referenced this issue Jun 29, 2023
@bvenn
Copy link
Member Author

bvenn commented Jun 29, 2023

closed by 3a0940f

@bvenn bvenn closed this as completed Jun 29, 2023
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

No branches or pull requests

1 participant