| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Majority.Merit
Contents
Synopsis
- type Choices = HashSet
- choices :: (Bounded choice, Enum choice, Eq choice, Hashable choice) => Choices choice
- type Grades = Set
- grades :: [grade] -> Grades (Ranked grade)
- newtype Ranked a = Ranked (Integer, a)
- zipRank :: [a] -> [Ranked a]
- rankKey :: [(k, a)] -> [(Ranked k, a)]
- rank :: Ranked a -> Integer
- unRank :: Ranked a -> a
- enum :: (Bounded a, Enum a, Ord a) => Set a
- type Judges = HashMap
- judges :: Eq judge => Hashable judge => [judge] -> grade -> Judges judge grade
- type Opinions judge grade = HashMap judge (Distribution grade)
- opinions :: Eq judge => Hashable judge => Judges judge grade -> Opinions judge grade -> (Opinions judge grade, HashSet judge)
- type Distribution grade = Map grade Share
- singleGrade :: grade -> Distribution grade
- type Share = Rational
- type OpinionsByChoice choice judge grade = HashMap choice (Opinions judge grade)
- opinionsByChoice :: Eq choice => Hashable choice => [(choice, Opinions judge grade)] -> OpinionsByChoice choice judge grade
- newtype Merit grade = Merit {}
- merit :: Ord grade => Foldable opinions => opinions (Distribution grade) -> Merit grade
- meritFromList :: Ord grade => Foldable opinions => Functor opinions => opinions grade -> Merit grade
- normalizeMerit :: Merit grade -> Merit grade
- newtype MeritByChoice choice grade = MeritByChoice {
- unMeritByChoice :: HashMap choice (Merit grade)
- meritByChoice :: (Ord grade, Eq choice, Hashable choice) => OpinionsByChoice choice judge grade -> MeritByChoice choice grade
Type Choices
choices :: (Bounded choice, Enum choice, Eq choice, Hashable choice) => Choices choice Source #
Return a set of Choices by enumerating the alternatives of its type. Useful on sum types.
Type Grades
How many grades should be used?
A greater number of grades permits a finer distinction but demands
a higher degree of expertise and discernment.
The optimal number is the highest number of grades that constitutes a common language,
that is, that allows Judges to make absolute judgments.
Too little grades may lead too often to ties.
Note, however, that if the inputs or grades depend on the set of choices,
i.e. if judges change their grades when choices are added or dropped,
then the Arrow paradox cannot be avoided.
To avoid this the scale of grades must be fixed and absolute
so that more or fewer choices does not change
the inputs or messages of other choices.
Type Ranked
Helper type to rank data without a good Ord instance.
enum :: (Bounded a, Enum a, Ord a) => Set a Source #
Return the Set enumerating the alternatives
of its type parameter. Useful on sum types.
Type Judges
type Judges = HashMap Source #
Map each judge to its default grade
(usually the same for all judges but not necessarily).
For instance, when a judge gives no grade or has “no opinion”,
this default grade could mean that the judge chooses “To Reject” the choice:
the rationale being that a judge having “no opinion”
concerning a choice has not even taken the time to evaluate it
and thus has implicitly rejected it.
Type Opinions
type Opinions judge grade = HashMap judge (Distribution grade) Source #
Profile of opinions of some judges about a single choice.
opinions :: Eq judge => Hashable judge => Judges judge grade -> Opinions judge grade -> (Opinions judge grade, HashSet judge) Source #
(ok, ko) = returns:opinions js os
- in
okthe opinions of thejudgesjsupdated by those inos, - in
kothe opinions ofjudges not injs.
Type Distribution
type Distribution grade = Map grade Share Source #
Usually, a judge gives a singleGrade to a given choice.
However, when applying the Majority Judgment to a Tree of Sections,
what a judge gives to a parent Section
is composed by the grades he or she has given
to the sub-Sections, and those can be different.
In that case, each grade given to a sub-Section contributes to a Share
of the parent Section which therefore is not necessarily a singleGrade,
but more generally a Distribution of grades.
And the sub-Sections can actually themselves have sub-Sections,
hence not being given a grade, but a Distribution of grades too.
singleGrade :: grade -> Distribution grade Source #
Type Share
type Share = Rational Source #
Usually a judge attributes a singleGrade to a given choice,
and then the Share of this grade is 1.
However, when introducing vote colleges (giving more power to some judges),
or when introducing Sections (decomposing a judgment into several sub-judgments),
it becomes possible that only a percentage of grade
is attributed by a judge to a given choice.
This is what a Share is used for.
Type OpinionsByChoice
type OpinionsByChoice choice judge grade = HashMap choice (Opinions judge grade) Source #
Profile of opinions of some Judges about some choices.
opinionsByChoice :: Eq choice => Hashable choice => [(choice, Opinions judge grade)] -> OpinionsByChoice choice judge grade Source #
Type Merit
Profile of merit about a single choice.
Instances
| (Ord grade, Show grade) => IsList (Merit grade) Source # | |
| Eq grade => Eq (Merit grade) Source # | |
| Ord grade => Ord (Merit grade) Source # | |
Defined in Majority.Value | |
| Show grade => Show (Merit grade) Source # | |
| Ord grade => Semigroup (Merit grade) Source # | |
| type Item (Merit grade) Source # | |
Defined in Majority.Merit | |
merit :: Ord grade => Foldable opinions => opinions (Distribution grade) -> Merit grade Source #
merit os returns the Merit given by opinions os
meritFromList :: Ord grade => Foldable opinions => Functor opinions => opinions grade -> Merit grade Source #
normalizeMerit :: Merit grade -> Merit grade Source #
Type MeritByChoice
newtype MeritByChoice choice grade Source #
Profile of merit about some choices.
Constructors
| MeritByChoice | |
Fields
| |
Instances
| (Eq choice, Hashable choice, Show choice) => IsList (MeritByChoice choice grade) Source # | |
Defined in Majority.Merit Associated Types type Item (MeritByChoice choice grade) :: Type # Methods fromList :: [Item (MeritByChoice choice grade)] -> MeritByChoice choice grade # fromListN :: Int -> [Item (MeritByChoice choice grade)] -> MeritByChoice choice grade # toList :: MeritByChoice choice grade -> [Item (MeritByChoice choice grade)] # | |
| (Eq choice, Eq grade) => Eq (MeritByChoice choice grade) Source # | |
Defined in Majority.Merit Methods (==) :: MeritByChoice choice grade -> MeritByChoice choice grade -> Bool # (/=) :: MeritByChoice choice grade -> MeritByChoice choice grade -> Bool # | |
| (Show choice, Show grade) => Show (MeritByChoice choice grade) Source # | |
Defined in Majority.Merit Methods showsPrec :: Int -> MeritByChoice choice grade -> ShowS # show :: MeritByChoice choice grade -> String # showList :: [MeritByChoice choice grade] -> ShowS # | |
| (Eq choice, Hashable choice, Ord grade) => Semigroup (MeritByChoice choice grade) Source # | |
Defined in Majority.Merit Methods (<>) :: MeritByChoice choice grade -> MeritByChoice choice grade -> MeritByChoice choice grade # sconcat :: NonEmpty (MeritByChoice choice grade) -> MeritByChoice choice grade # stimes :: Integral b => b -> MeritByChoice choice grade -> MeritByChoice choice grade # | |
| type Item (MeritByChoice choice grade) Source # | |
Defined in Majority.Merit | |
meritByChoice :: (Ord grade, Eq choice, Hashable choice) => OpinionsByChoice choice judge grade -> MeritByChoice choice grade Source #