hjugement-2.0.2.20190414: Majority Judgment.

Majority.Rank

Synopsis

Convenient type aliases

type JS = Integer Source #

Number of judges.

type GS = Integer Source #

type Rank = Integer Source #

Rank of a MajorityValue.

Type Median

newtype Median Source #

A median. First G (lower median) is lower or equal to the second G (higher median).

Constructors

 Median (G, G)
Instances
 Source # Instance detailsDefined in Majority.Rank Methods(==) :: Median -> Median -> Bool #(/=) :: Median -> Median -> Bool # Source # Instance detailsDefined in Majority.Rank MethodsshowsPrec :: Int -> Median -> ShowS #showList :: [Median] -> ShowS #

median :: G -> G -> Median Source #

Median constructor enforcing its invariant.

Ranking and unranking MajorityValues

rankOfMajorityValue :: GS -> MajorityValue (Ranked grade) -> Rank Source #

(rankOfMajorityValue gs mv) returns the number of possible MajorityValues lower than given mv.

rankOfMajorityValue gs . majorityValueOfRank js gs
<\$> [0..lastRank js gs] == [0..lastRank js gs]


The inverse of rankOfMajorityValue.

majorityValueOfRank js gs . rankOfMajorityValue gs == id


Counting Merits

(countMerits js gs) returns the number of possible Merits of size js using grades gs. That is the number of ways to divide a segment of length js into at most gs segments whose size is between '0' and js.

The formula is: (js+gs-1)·(js+gs-2)·…·(js+1)·js / (gs-1)·(gs-2)·…·2·1 which is: (js+gs-1)nCk(gs-1)

lastRank :: JS -> GS -> Rank Source #

(lastRank js gs) returns the rank of the MajorityValue composed of js times the highest grade of gs.

lastRank js gs == countMerits js gs - 1.

Counting Medians

(countMedian js gs (Median (l,h))) returns the number of possible Merits of length js using grades gs, which have (l,h) as lower and upper median grades. This is done by multiplying together the countMerits to the left of l and the countMerits to the right of h.

(countMediansBefore js gs previousHigh (Median (low,high))) returns the number of possible Merits with js judges and gs grades, whose Median (l,h) is such that ((l,h) < (low, high)) and (previousHigh <= h).

listMediansBefore :: JS -> GS -> G -> Median -> [Median] Source #

(listMediansBefore js gs previousHigh (Median (low,high))) returns the Medians of possible Merits with js judges and gs grades with a Median strictly lower than (low,high).

probaMedian :: JS -> GS -> [Rational] Source #

(probaMedian js gs) compute the probability of each grade to be a MajorityGrade given js judges and gs grades.

Utils

nCk :: Integral i => i -> i -> i infix 7 Source #

(nCk n k) returns the binomial coefficient of n and k, that is number of combinations of size k from a set of size n.

Computed using the formula: nCk n (k+1) == nCk n (k-1) * (n-k+1) / k