Пример #1
0
def GeneralizedSugenoLambda(F1, F2, x, mu, l=None, verbose=False):
    """Generalized Sugeno Lambda integral

    :param x: values
    :param mu: fuzzy measure
    :param l: value of lambda, if None (Default) it's get calculated
    :param verbose: If true prints data to the console

    :rtype: Generalized Sugeno lambda-Integral with lambda computed based on :math:`\\mu`

    :math:`SFI(x)_{\\mu} = F2_{i=1}^{n}F1(f(x_{\\sigma_i}),g(A_j))`.

    """

    x = np.array(x)
    mu = np.array(mu)

    sortedindex = np.argsort(x)
    xsorted = np.take(x, sortedindex)
    musorted = np.take(mu, sortedindex)

    if l is None:
        l = bisectionLien(FLambda, mu)
    nmu = generateGMeasure(musorted, l)

    gsugeno = F2([F1(a, b) for a, b in zip(xsorted, nmu)])

    if verbose:
        print("X:", x, "X sorted:", xsorted)
        print("mu", mu, "Mu sorted:", musorted)
        print("Lambda:", l)
        print("Generated measures:", nmu)
        print("Sugeno:", gsugeno)

    return gsugeno
Пример #2
0
 def test_GenerateMuLambda1(self):
     # C.G. Magadun an M.S. Bapat
     # http://www.researchmathsci.org/IJFMAart/IJFMA-v15n2-1.pdf
     mu = [0.4, 0.5, 0.5, 0.7, 0.8, 0.8]
     l = -0.9981565
     expected = [1.0, 0.9987725, 0.9957093, 0.9895943, 0.9611798, 0.8]
     out = list(utils.generateGMeasure(mu, l))
     for e, o in zip(expected, out):
         self.assertAlmostEqual(o, e, places=3)
Пример #3
0
 def test_GenerateMuLambda3(self):
     # C.G. Magadun an M.S. Bapat
     # http://www.researchmathsci.org/IJFMAart/IJFMA-v15n2-1.pdf
     # FChoquet fails with this data. An error in the paper?
     mu = [0.7, 0.5, 0.5, 0.8, 0.8, 0.4]
     l = -0.9981565
     expected = [1.0, 0.9957168, 0.9896093, 0.9774167, 0.8805899, 0.4]
     out = list(utils.generateGMeasure(mu, l))
     for e, o in zip(expected, out):
         self.assertAlmostEqual(o, e, places=3)
Пример #4
0
 def test_GenerateMuLambda2(self):
     # C.G. Magadun an M.S. Bapat
     # http://www.researchmathsci.org/IJFMAart/IJFMA-v15n2-1.pdf
     mu = [0.8, 0.8, 0.5, 0.7, 0.5, 0.4]
     l = -0.9981565
     expected = [
         1.0, 0.992679806032971, 0.9563469279183847, 0.911014400788915,
         0.7003687, 0.4
     ]
     out = list(utils.generateGMeasure(mu, l))
     for e, o in zip(expected, out):
         self.assertAlmostEqual(o, e, places=3)
Пример #5
0
def ChoquetLambda(x, mu, l=None, verbose=False):
    """Choquet Lambda integral

    :param x: values
    :param mu: fuzzy measure
    :param l: value of lambda, if None (Default) it's get calculated
    :param verbose: If true prints data to the console

    :rtype: Choquet lambda-Integral with lambda computed based on :math:`\\mu`


    :math:`CFI(x)_{\\mu} = \\displaystyle\\sum_{i=1}^{n}(f(x_{\\sigma_i})-f(x_{\\sigma_{(i-1)}}))* g(A_j)`.

    """

    x = np.array(x)
    mu = np.array(mu)

    # sortedindex = np.argsort(x)
    # xsorted = np.take(x, sortedindex)
    # musorted = np.take(mu, sortedindex)

    sortedindex = list(zip(x, mu))
    sortedindex.sort()  # key=lambda x: x[0]
    xsorted, musorted = zip(*sortedindex)
    xsorted, musorted = np.array(xsorted), np.array(musorted)

    if l is None:
        l = bisectionLien(FLambda, mu)

    nmu = generateGMeasure(musorted, l)

    # choquet = sum(np.diff(np.append([0], xsorted)) * nmu) # Twice as slow
    choquet = np.dot((np.append(xsorted[0], xsorted[1:] - xsorted[0:-1])), nmu)

    if verbose:
        print("X:", x, "X sorted:", xsorted)
        print("mu", mu, "Mu sorted:", musorted)
        print("Lambda:", l)
        print("Generated measures:", nmu)
        print("Choquet:", choquet)

    return choquet
Пример #6
0
def GeneralizedChoquetLambda(F1, F2, x, mu, l=None, verbose=False):
    """Choquet Lambda integral

    :param x: values
    :param mu: fuzzy measure
    :param F1: Function1
    :param F2: Function2
    :param l: value of lambda, if None (Default) it's get calculated
    :param verbose: If true prints data to the console

    :rtype: Generalized Choquet lambda-Integral with lambda computed based on :math:`\\mu`

    :math:`CFI(x)_{\\mu} = F2_{i=1}^{n}F1(f(x_{\\sigma_i})-f(x_{\\sigma_{(i-1)}})),g(A_j))`.

    """

    x = np.array(x)
    mu = np.array(mu)

    sortedindex = np.argsort(x)
    xsorted = np.take(x, sortedindex)
    musorted = np.take(mu, sortedindex)

    if l is None:
        l = bisectionLien(FLambda, mu)
    nmu = generateGMeasure(musorted, l)

    gchoquet = F2(F1(np.diff(np.append([0], xsorted)), nmu))
    # For numpy >= 1.16
    # gchoquet = F2(F1(np.diff(xsorted,prepend=[0]),nmu))

    if verbose:
        print("X:", x, "X sorted:", xsorted)
        print("mu", mu, "Mu sorted:", musorted)
        print("Lambda:", l)
        print("Generated measures:", nmu)
        print("Choquet:", gchoquet)

    return gchoquet