gpt4 book ai didi

python - 模糊关系中的组合 - MATLAB/Python

转载 作者:太空宇宙 更新时间:2023-11-03 16:40:59 25 4
gpt4 key购买 nike

我想在 MATLAB/Python 上计算模糊关系组合,并且想知道 MATLAB 或 Python 中是否有内置函数可以执行此操作...

这是一个例子:

R1 = [{ 3, 4, .7}, {3, 5, 0}, { 4, 4, 1}, { 4, 5, .1}]

R2 = [{ 3,3, 0}, { 3, 5, .1}, { 4, 4, 0}, { 4, 5, .6}]

我正在尝试计算:

R1oR2

我正在寻找“最大-最小”和“最大-乘积”方法...

最佳答案

好吧...由于没有人给出答案,所以我最终自己编写了它...这是Python代码:

import numpy as np

# Max-Min Composition given by Zadeh
def maxMin(x, y):
z = []
for x1 in x:
for y1 in y.T:
z.append(max(np.minimum(x1, y1)))
return np.array(z).reshape((x.shape[0], y.shape[1]))

# Max-Product Composition given by Rosenfeld
def maxProduct(x, y):
z = []
for x1 in x:
for y1 in y.T:
z.append(max(np.multiply(x1, y1)))
return np.array(z).reshape((x.shape[0], y.shape[1]))

# 3 arrays for the example
r1 = np.array([[1, 0, .7], [.3, .2, 0], [0, .5, 1]])
r2 = np.array([[.6, .6, 0], [0, .6, .1], [0, .1, 0]])
r3 = np.array([[1, 0, .7], [0, 1, 0], [.7, 0, 1]])

print "R1oR2 => Max-Min :\n" + str(maxMin(r1, r2)) + "\n"
print "R1oR2 => Max-Product :\n" + str(maxProduct(r1, r2)) + "\n\n"

print "R1oR3 => Max-Min :\n" + str(maxMin(r1, r3)) + "\n"
print "R1oR3 => Max-Product :\n" + str(maxProduct(r1, r3)) + "\n\n"

print "R1oR2oR3 => Max-Min :\n" + str(maxMin(r1, maxMin(r2, r3))) + "\n"
print "R1oR2oR3 => Max-Product :\n" + str(maxProduct(r1, maxProduct(r2, r3))) + "\n\n"

这是它给出的答案:

R1oR2 => Max-Min :
[[ 0.6 0.6 0. ]
[ 0.3 0.3 0.1]
[ 0. 0.5 0.1]]

R1oR2 => Max-Product :
[[ 0.6 0.6 0. ]
[ 0.18 0.18 0.02]
[ 0. 0.3 0.05]]


R1oR3 => Max-Min :
[[ 1. 0. 0.7]
[ 0.3 0.2 0.3]
[ 0.7 0.5 1. ]]

R1oR3 => Max-Product :
[[ 1. 0. 0.7 ]
[ 0.3 0.2 0.21]
[ 0.7 0.5 1. ]]


R1oR2oR3 => Max-Min :
[[ 0.6 0.6 0.6]
[ 0.3 0.3 0.3]
[ 0.1 0.5 0.1]]

R1oR2oR3 => Max-Product :
[[ 0.6 0.6 0.42 ]
[ 0.18 0.18 0.126]
[ 0.035 0.3 0.05 ]]

关于python - 模糊关系中的组合 - MATLAB/Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36790515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com