Created
September 3, 2021 16:26
-
-
Save Marceeaax/aac67501aee4c9839780b88703f7d0bf to your computer and use it in GitHub Desktop.
In this snippet, I made a function that calculates the max-min and min-max composition of two fuzzy relations. If you use it in a Jupyter Notebook, there's no need to import the numpy and Ipython libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from IPython.display import display, Markdown | |
def maxmincomposition(X,Y): | |
C = np.zeros((X.shape[0],Y.shape[1])) | |
# Iterar a traves de las filas de A | |
for i in range(len(X)): | |
# Iterar a traves de las columnas de B | |
for j in range(len(Y[0])): | |
# Iterar a traves de las filas de B | |
for k in range(len(Y)): | |
if(np.minimum(X[i][k], Y[k][j]) > C[i][j]): | |
C[i][j] = np.minimum(X[i][k], Y[k][j]) | |
return C | |
# Ejemplo del libro de Syropoulos | |
A = np.array([[0.3,0.5,0.8], | |
[0,0.7,1], | |
[0.4,0,0.5]]) | |
B = np.array([[0.9,0,0.7,0.7], | |
[0.3,0.2,0,0.9], | |
[1,0,0.5,0.5]]) | |
# Ejemplo del libro de Bede | |
R = np.array([[0.3,0.7,0.2], | |
[1,0,0.9]]) | |
S = np.array([[0.8,0.3], | |
[0.1,0], | |
[0.5,0.6]]) | |
display(Markdown('**Ejemplo del libro de Syropoulos**')) | |
display(Markdown('Dada una relacion difusa $A$')) | |
print(A) | |
display(Markdown('Y dada una relacion difusa $B$')) | |
print(B) | |
display(Markdown('$A\lhd B = $')) | |
print(maxmincomposition(A,B)) | |
display(Markdown('**Ejemplo del libro de Bede**')) | |
display(Markdown('Dada una relacion difusa $R$')) | |
print(R) | |
display(Markdown('Y dada una relacion difusa $S$')) | |
print(S) | |
display(Markdown('$R\lhd S = $')) | |
print(maxmincomposition(R,S)) | |
def minmaxcomposition(X,Y): | |
C = np.ones((X.shape[0],Y.shape[1])) | |
# Iterar a traves de las filas de A | |
for i in range(len(X)): | |
# Iterar a traves de las columnas de B | |
for j in range(len(Y[0])): | |
# Iterar a traves de las filas de B | |
for k in range(len(Y)): | |
if(np.maximum(X[i][k], Y[k][j]) < C[i][j]): | |
C[i][j] = np.maximum(X[i][k], Y[k][j]) | |
return C | |
display(Markdown('**Ejemplo del libro de Syropoulos**')) | |
display(Markdown('Dada una relacion difusa $A$')) | |
print(A) | |
display(Markdown('Y dada una relacion difusa $B$')) | |
print(B) | |
display(Markdown('$A ⊳ B = $')) | |
print(minmaxcomposition(A,B)) | |
display(Markdown('**Ejemplo del libro de Bede**')) | |
display(Markdown('Dada una relacion difusa $R$')) | |
print(R) | |
display(Markdown('Y dada una relacion difusa $S$')) | |
print(S) | |
display(Markdown('$R\lhd S = $')) | |
print(minmaxcomposition(R,S)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment