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
def test_bisectionLien3(self): # C.G. Magadun an M.S. Bapat # SCILAB resolving 6th grade equation # http://www.researchmathsci.org/IJFMAart/IJFMA-v15n2-1.pdf mu = [0.8, 0.8, 0.5, 0.7, 0.5, 0.4] ll = utils.bisectionLien(utils.F, mu) espl = -0.9981565 self.assertAlmostEqual(ll, espl, places=5)
def FFISLP(self, individual): floats = individualtofloat(individual) weights = floats[:-1] cutvalue = floats[-1] CA = 0 # number of correctly classified training patterns E = 0 # square error between the actual and desired outputs of individual training patterns landa = bisectionLien(FI.FLambda, np.array(weights)) for xi, yi in zip(self.x, self.y): CFI = self.FI(xi, weights, landa) y_out = 1 if CFI < cutvalue else 0 if y_out == yi: # if ((CFI < cutvalue) and (yi == 1)) or ((CFI >= cutvalue) and (yi == 0)): CA += 1 # CA(CFISLPik) correctly clasified instances E += (y_out - yi)**2 # E += (CFI-yi)**2 # E = E ** (1 / 2) # the square error between the actual and desired outputs? return self.wca * CA - self.we * E
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
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
def test_bisectionLien1(self): # Chung-Chang Lien & Chie-Bein Chen mu = [0.624801, 0.029406, 0.326642, 0.374676] ll = utils.bisectionLien(utils.F, mu) espl = -0.6592807 self.assertAlmostEqual(ll, espl, places=5)
def test_bisectionLien6(self): mu = [0.2, 0.3] ll = utils.bisectionLien(utils.F, mu) espl = 8.333332 self.assertAlmostEqual(ll, espl, places=5)
def test_bisectionLien5(self): # find esp lambda mu = [0.3, 0.2, 0.25, 0.1] ll = utils.bisectionLien(utils.F, mu) espl = 0.538635 self.assertAlmostEqual(ll, espl, places=5)
def test_bisectionLien4(self): mu = [0.3, 0.2, 0.4, 0.1] ll = utils.bisectionLien(utils.F, mu) espl = 0 self.assertAlmostEqual(ll, espl, places=5)
def test_bisectionLien2(self): # Chung-Chang Lien & Chie-Bein Chen mu = [0.999702, 0.844691, 0.724534, 0.694047] ll = utils.bisectionLien(utils.F, mu) espl = -0.9999956 self.assertAlmostEqual(ll, espl, places=5)