Esempio n. 1
0
def add_approximators(N, C):
    '''
    This function will add all approximators with denominator less than N
    and that are coprime with its numerator 
    '''

    approximators = []

    treshold = mp.log10(mp.mpf(124) / mp.mpf(123))
    for i in range(10, N):
        chute = mp.floor(i * C)

        if mp.absmax(chute / i - C) >= mp.absmax((chute + 1) / i - C):
            chute += 1

        if mcd(chute, i) == 1:
            val = mp.frac(i * C)
            if val < treshold:
                approximators.append((i, val))
            elif val > 1 - treshold:
                approximators.append((i, val - 1))

    return approximators
Esempio n. 2
0
def family_graphical_combination(t, c, angle_alpha_prime):
    """
    Aberdeen family of graphical operators
    """
    if not (isinstance(t, Opinion) and isinstance(c, Opinion) \
            and t.check() and c.check()):
        raise Exception("Two valid Opinions are required!")

    if mpmath.almosteq(angle_alpha_prime, -mpmath.pi / 3, epsilon):
        new_magnitude = c.get_magnitude_ratio() * (
            mpmath.mpf("2") * t.getUncertainty() /
            mpmath.sqrt(mpmath.mpf("3")))
        #new_magnitude = 0
    elif mpmath.almosteq(angle_alpha_prime,
                         mpmath.mpf("2/3") * mpmath.pi, epsilon):
        new_magnitude = c.get_magnitude_ratio() * (
            mpmath.mpf("2") * (mpmath.mpf("1") - t.getUncertainty()) /
            mpmath.sqrt(mpmath.mpf("3")))
        #new_magnitude = 0
    elif mpmath.almosteq(angle_alpha_prime,
                         mpmath.mpf("1/2") * mpmath.pi, epsilon):
        #new_magnitude = 1 - t.getUncertainty()
        new_magnitude = 2 * t.getBelief()
    else:
        new_magnitude = c.get_magnitude_ratio() * (mpmath.mpf("2") * \
                                                (mpmath.sqrt(mpmath.power(mpmath.tan(angle_alpha_prime), mpmath.mpf("2")) +1 ) /
                                                 ( mpmath.absmax(mpmath.tan(angle_alpha_prime) + mpmath.sqrt(mpmath.mpf("3"))) ) ) * \
                                                t.getBelief())

    new_uncertainty = t.getUncertainty(
    ) + mpmath.sin(angle_alpha_prime) * new_magnitude
    new_disbelief = t.getDisbelief() + (
        t.getUncertainty() - new_uncertainty) * mpmath.cos(
            mpmath.pi / 3) + mpmath.cos(angle_alpha_prime) * mpmath.sin(
                mpmath.pi / 3) * new_magnitude

    if mpmath.almosteq(new_uncertainty, 1, epsilon):
        new_uncertainty = mpmath.mpf("1")
    if mpmath.almosteq(new_uncertainty, 0, epsilon):
        new_uncertainty = mpmath.mpf("0")

    if mpmath.almosteq(new_disbelief, 1, epsilon):
        new_disbelief = mpmath.mpf("1")
    if mpmath.almosteq(new_disbelief, 0, epsilon):
        new_disbelief = mpmath.mpf("0")

    return Opinion(1 - new_disbelief - new_uncertainty, new_disbelief,
                   new_uncertainty, "1/2")
Esempio n. 3
0
 def distance_expected_value(self, another):
     """
     This method computes the distance between the two expected values
     """
     return mpmath.absmax(self.expected_value() - another.expected_value())