Extreme Optimization > QuickStart Samples > Discrete Distributions QuickStart Sample (F#)

Extreme Optimization QuickStart Samples

Discrete Distributions QuickStart Sample (F#)

Illustrates how to use the classes that implement discrete probability distributions (Extreme.Statistics.Distributions namespace) in F#.

C# code VB.NET code Back to QuickStart Samples

#light
 
open System
 
open Extreme.Statistics
open Extreme.Statistics.Distributions
 
/// <summary>
/// Demonstrates how to use classes that implement
/// discrete probabililty distributions.
/// </summary>
 
// This QuickStart Sample demonstrates the capabilities of
// the classes that implement discrete probability distributions.
// These classes inherit from the DiscreteDistribution class.
//
// For an illustration of classes that implement discrete probability
// distributions, see the ContinuousDistributions QuickStart Sample.
// 
// We illustrate the properties and methods of discrete distribution
// open a binomial distribution. The same properties and methods
// apply to all other discrete distributions.
 
// 
// Constructing distributions
//
 
// Many discrete probability distributions are related to Bernoulli trials,
// events with a certain probability, p, of success. The number of trials
// is often one of the distribution's parameters.
 
// The binomial distribution has two constructors. Here, we create a
// binomial distribution for 6 trials with a probability of success of 0.6:
let binomial = new BinomialDistribution(6, 0.6)
 
// The distribution's parameters are available through the
// NumberOfTrials and ProbabilityOfSuccess properties:
Console.WriteLine("# of trials:          {0:F5}", binomial.NumberOfTrials)
Console.WriteLine("Prob. of success:     {0:F5}", binomial.ProbabilityOfSuccess)
 
 
//
// Basic statistics
//
 
// The Mean property returns the mean of the distribution:
Console.WriteLine("Mean:                 {0:F5}", binomial.Mean)
 
// The Variance and StandardDeviation are also available:
Console.WriteLine("Variance:             {0:F5}", binomial.Variance)
Console.WriteLine("Standard deviation:   {0:F5}", binomial.StandardDeviation)
 
// As are the skewness:
Console.WriteLine("Skewness:             {0:F5}", binomial.Skewness)
 
// The Kurtosis property returns the kurtosis supplement.
// The Kurtosis property for the normal distribution returns zero.
Console.WriteLine("Kurtosis:             {0:F5}", binomial.Kurtosis)
Console.WriteLine()
 
 
//
// Distribution functions
//
 
// The (cumulative) distribution function (CDF) is implemented by the
// DistributionFunction method:
Console.WriteLine("CDF(4) =            {0:F5}", binomial.DistributionFunction(4))
 
// The probability density function (PDF) is available as the 
// Probability method:
Console.WriteLine("PDF(4) =            {0:F5}", binomial.Probability(4))
 
// The Probability method has an overload that returns the probability
// that a variate lies between two values:
Console.WriteLine("Probability(3, 5) = {0:F5}", binomial.Probability(3, 5))
Console.WriteLine()
 
//
// Random variates
//
 
// The GetRandomVariate method returns a single random variate 
// open the specified random number generator:
let rng = new Random.MersenneTwister()
let x = binomial.GetRandomVariate(rng)
// The GetRandomVariates method fills an array or vector with
// random variates. It has several overloads:
open Microsoft.FSharp.Collections.Array
let xArray = (Array.create 100) 1
// 1. Fill all values:
binomial.GetRandomVariates(rng, xArray)
// 2. Fill only a range (start index and length are supplied)
binomial.GetRandomVariates(rng, xArray, 20, 50)
 
// The GetExpectedHistogram method returns a Histogram that contains the
// expected number of samples in each bin:
let h = binomial.GetExpectedHistogram(100.0)
Console.WriteLine("Expected distribution of 100 samples:")
for bin in h.Bins do 
  Console.WriteLine("Between {0} and {1} -> {2}", bin.LowerBound, bin.UpperBound, bin.Value)
done
 
for bin in h.Bins do 
   Console.WriteLine("{0} success(es) -> {1}", bin.LowerBound, bin.Value)
done
 
Console.WriteLine()
 
Console.Write("Press any key to exit.")
Console.ReadLine()
Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Information
Resources
Contact Us
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army