Back to Work
ANFIS - Adaptive Neuro Fuzzy Inference System
Program ini mengimplementasikan Adaptive Neuro Fuzzy Inference System (ANFIS) dengan fungsi keanggotaan generalized bell-shaped dan aturan Sugeno untuk prediksi berdasarkan input x dan y.
Parameters
Code & Execution
Output
Click "Run Code" to see output...
📄 View Source Code
import numpy as np
# -----------------------------------------------------------
# 1. Fungsi keanggotaan bell-shaped sesuai file (generalized bell)
# μ(x) = 1 / (1 + |(x - c) / a|^(2 * b))
# -----------------------------------------------------------
def gbell_mf(x, a, b, c):
return 1 / (1 + abs((x - c) / a) ** (2 * b))
# -----------------------------------------------------------
# 2. Aturan Sugeno :
# Rule 1: f1 = 0.1x + 0.1y + 0.1
# Rule 2: f2 = 10x + 10y + 10
# -----------------------------------------------------------
def f1(x, y):
return 0.1 * x + 0.1 * y + 0.1
def f2(x, y):
return 10 * x + 10 * y + 10
# -----------------------------------------------------------
# 3. Hitung ANFIS untuk input (x, y)
# -----------------------------------------------------------
def anfis(x, y):
# Fungsi keanggotaan dari file (nilai dibaca dari contoh):
# A1(x=3) = 0.5, B1(y=4) = 0.1
# A2(x=3) = 0.25, B2(y=4) = 0.039
A1 = 0.5
B1 = 0.1
A2 = 0.25
B2 = 0.039
# Layer 2 - firing strength
w1 = A1 * B1
w2 = A2 * B2
# Normalisasi firing strength
w_sum = w1 + w2
W1 = w1 / w_sum
W2 = w2 / w_sum
# Layer 4 - weighted output
out1 = W1 * f1(x, y)
out2 = W2 * f2(x, y)
# Layer 5 - output total
output = out1 + out2
return {
"A1": A1, "B1": B1, "A2": A2, "B2": B2,
"w1": w1, "w2": w2,
"W1": W1, "W2": W2,
"out1": out1, "out2": out2,
"final_output": output
}
# -----------------------------------------------------------
# 4. Contoh penggunaan: x = 3, y = 4
# -----------------------------------------------------------
result = anfis(3, 4)
# Cetak hasil secara rapi
for k, v in result.items():
print(f"{k:12s} = {v}")