Extreme Optimization > QuickStart Samples > Discrete Distributions QuickStart Sample (VB.NET)

Extreme Optimization QuickStart Samples

Discrete Distributions QuickStart Sample (VB.NET)

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

C# code F# code Back to QuickStart Samples

Imports System.Data
Imports Extreme.Statistics
Imports Extreme.Statistics.Distributions

Namespace Extreme.Statistics.QuickStart.VB
    ' Demonstrates how to use classes that implement
    ' discrete probabililty distributions.
    Module DiscreteDistributions

        Sub Main()
            ' 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 using 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:
            Dim binomial As BinomialDistribution = _
                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 
            ' using the specified random number generator:
            Dim rng As System.Random = New Random.MersenneTwister
            Dim x As Integer = binomial.GetRandomVariate(rng)
            ' The GetRandomVariates method fills an array or vector with
            ' random variates. It has several overloads:
            Dim xArray As Integer() = New Integer(100) {}
            ' 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:
            Dim h As Histogram = binomial.GetExpectedHistogram(100)
            Console.WriteLine("Expected distribution of 100 samples:")
            For Each bin As HistogramBin In h.Bins
                Console.WriteLine("{0} success(es) -> {1}", _
                    bin.LowerBound, bin.Value)
            Next
            Console.WriteLine()

            Console.WriteLine("Press Enter key to continue.")
            Console.ReadLine()
        End Sub

    End Module

End Namespace
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