Issues with ProbFraction and ProbDecimal

Issue #56 resolved
Pierre Denis repo owner created an issue

When using fractions or decimals probabilities, Lea returns ProbFraction and ProbDecimal instances. These are checked to be in the range [0,1]. When these are used in arithmetic expression, these return new ProbFraction and ProbDecimal instances, with same checks. Actually, the range check is done at display time, so to allow temporary out of bounds for partial results. This works well but this presents two drawbacks:

  • impossibility for the user to use fraction/decimal probability results in arithmetic expressions unless they have a result in [0,1]. This is inconvenient and also inconsistent with default floating-point probabilities;
  • impossibility to return mean, variance, … indicators as ProbFraction or ProbDecimal instances, since they can be outside [0,1]; these are now displayed as usual Fraction/Decimal instances with weird output in interactive mode (__repr__ method).

It is proposed to change this design to enforce range checking ONLY at ProbFraction or ProbDecimal creation. When these instances are used in expressions, the results shall be up casted to new classes (e.g. ExtFraction, ExtDecimal) that makes no such check. The user is supposed to be knowledgeable on the good usage of the probability results she gets. It is proposed also to change implementations of mean, var, … methods to return instances of these new classes.

Comments (3)

  1. Pierre Denis reporter

    Rename ProbNumber as Number, refactor ProbDecimal/ProbFraction; define new classes ExtDecimal/ExtFraction, update mean, var methods, ... (refs #56)

    → <<cset 34bb243b5e33>>

  2. Log in to comment