majurity-judgment-2.0.2.20190414: Majority Judgment voting system.
Safe HaskellNone
LanguageHaskell2010

Majurity.Judgment.Rank

Synopsis

Convenient type aliases

type JS = Integer Source #

Number of judges.

type GS = Integer Source #

Number of grades.

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

Instances details
Eq Median Source # 
Instance details

Defined in Majurity.Judgment.Rank

Methods

(==) :: Median -> Median -> Bool #

(/=) :: Median -> Median -> Bool #

Show Median Source # 
Instance details

Defined in Majurity.Judgment.Rank

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]

Counting Merits

countMerits :: JS -> GS -> Integer Source #

(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 -> Integer Source #

(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 -> G -> Median -> Integer Source #

(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