RandProc.hs - a Haskell library for working with random processes in a mathematically rigorous way
(Concepts taken from Random Processes - a Mathematical Approach for Engineers by:
- Robert M. Gray
- Lee D. Davisson
Prentice-Hall Information and System Sciences Series, Thomas Kailath, Series Editor)
$Id: RandProc.hs 31 2011-06-22 13:49:48Z dbanas $
12 March 2011
Copyright (c) 2011 by David Banas; All rights reserved World wide.
Date SVN #
- Data structures stabilized.
isSigmaworking under minimal, discrete sample testing.
isProbMeas, as well as monadic debugging versions of both it and
isSigma. Added an example probability space representing a fair die.
- Custom intersection functions added and briefly tested.
- Custom union functions added and briefly tested. Solution is crude: it is O(N^2), and requires 2 passes over the sample list every time a join is successful. Perhaps, a pre-sort?
- Attempted fix of
smplCompfunction, as helper to revised
Pointto accept Double. Moved all sample spaces to new file,
Main.hs. Added input sorting to
range. Changed Ranges to be open intervals, in order to allow for complementing out a Point from them.
- Major re-write.
getCompEventfixed. All 5 test spaces checking out ok.
- Removed sample set order dependency from
checkSigma. All 7 test spaces checking out ok.
- Added 'union of events is an event' test to
Eventfrom data constructor to type alias, in order to eliminate many instances of 'Event . f . getSamps' code.
smpsSetIntto use a fold.
- Defined public interface.
- Modified comments for Haddock, and generated HTML docs.
- Moved into
- End of Subversion revision history
- This source has been moved to darcs.
smplSetUnionmore efficient, and tuned remaining performance bottlenecks.
- data ProbSpace = ProbSpace [Sample] [Measure]
- data Measure = Measure Event Double
- data Sample = Empty
- data TestResult
- data ErrType
- data ProbSpaceTest = ProbSpaceTest ProbSpace TestResult String
- point :: Double -> Sample
- range :: (Double, Double) -> Sample
- makeProbSpace :: [(Sample, Double)] -> ProbSpace
- checkSpace :: ProbSpaceTest -> IO Bool
- getRsltStr :: TestResult -> String
- checkProbMeas :: ProbSpace -> TestResult
- checkSigma :: ProbSpace -> TestResult
- rangeBegin :: Sample -> Double
- rangeEnd :: Sample -> Double
- getProb :: Measure -> Double
- getEvent :: Measure -> Event
- getCompEvent :: [Sample] -> Event -> Event
- eventInt :: Event -> Event -> Event
- smplComp :: Sample -> Sample -> [Sample]
- isElem :: [Sample] -> Sample -> Bool
- noDupEvents :: [Measure] -> Bool
- smplInt :: Sample -> Sample -> Sample
- smplSetInt :: [Sample] -> Sample
- smplUnion :: Sample -> Sample -> [Sample]
- smplSetUnion :: [Sample] -> [Sample]
- subs :: [a] -> [[a]]
We take a probability space to consist of the following:
- an 'abstract space' composed of either discrete or continuous (or a mix) samples
- an 'event space', which must be a Sigma field defined over the abstract space
- a 'probability measure' defined over the event space
- For the sake of efficient coding, the event space and the probability measure are combined in the Haskell data structure, below. This is permissable, because there has to be a 1:1 correspondance between them anyway. And it is preferable, because it:
- keeps the probabilities more closely associated w/ the events, and
- avoids duplication of code (i.e. - the list of events).
Measure has 2 fields:
- event - a list of samples from the space, and
- prob - a number between 0 and 1 giving the events probability of occurence.
This is our abstract data type, which represents a sample in the abstract space.
It has a constructor representing every possible element in the abstract space we're modeling. (Currently, just points and ranges of Doubles.)
Normally, none of the constructors of this type will be called directly.
Instead, helper functions are provided, such as
hide the implementation details from the user, and present a stable interface.
Currently, the sole exception to the above is the Empty constructor, which is really just a hack intended to put off the job of making the functions in this library more intelligent, with regard to their handling of empty lists.
Custom data type used for test results and error reporting.
Custom data type for reporting different errors
Custom data structure, used for constructing individual test cases.
- ps - a pointer to the ProbSpace being tested
- res - the expected result
- name - a label for identifying this test
This is the helper function intended to be used for constructing a point sample.
This is the helper function intended to be used for constructing a range sample. The range is considered open. That is, its end points are not included.
This helper function generates a complete and valid probability space, given a discrete sample space and set of probabilities.
Takes a test case and returns a string indicating the result of the test.
Turns a value of type TestResult into a human readable string.
Checks whether event space is actually a Sigma field over the sample space.
Gets the beginning point of a range, which is not included in the range, since ranges are considered to be open.
Gets the ending point of a range, which is not included in the range,
Get the complement of an event from the sample space.
Calculates the intersection of 2 events (i.e. - list of samples).
Returns that portion of the first sample that is disjoint from the second.
Determine if a sample is an element of a space.
(Need this, as opposed to just using
elem, in order to accomodate ranges.)
Reduces a list of samples to a single sample representing their intersection.
Returns the union of 2 samples.
smplInt, smplUnion must return a list since, if the 2 input
samples aren't adjacent or overlapping, the union of them is a list
Collapses a list of samples down to the maximally reduced set, which still composes a proper union of the input.