How to create Fuzzy Cognitive Map from the Adjacency Matrix
9 views (last 30 days)
Show older comments
Hi everyone,
I have developed an unsupervised neural model and declared it has Fuzzy Cognitive Map. It could forecast the corrupted value to the nearest value after trained using Differential Hebbian Learning Rule. I have a doubt can you show me which part of the source code shows the Fuzzy?
Thank you.
1 Comment
Answers (1)
Sam Chak
on 18 Apr 2025
Hi @Alagesan
At the time your question was posted, it was challenging for @Arkadiy Turevskiy and others to assist you because the function to create the Fuzzy Cognitive Map (FCMap) had not yet been included in MATLAB. Your original code, 'coding.m,' successfully created the adjacency matrix W using Differential Hebbian Learning. However, it is incorrect to display the FCMap as a surface diagram as it is more accurately described as a conceptual network that illustrates causal relationships between concepts.
With the introduction of the digraph() function in R2015b release, the FCMap can now be represented as a directed graph-based structure, where the nodes represent concepts and the edges (arrows) between nodes represent causal relationships, with weights that describe the strength and type of influence. The fuzzy weight values should be between
and 1 to represent degrees of causality. Thus, it is necessary to rescale the weights in the adjacency matrix, W.
% type coding.m
clc
clear all
'====================Training The Dataset============================='
% DATASET STRUCTURE
DataSet = [ % this is a raw dataset of 5 variables and 48 samples
% var1: temp in var2:humidity in var3:cfm of ceiling fan var4:temp out var5:humidity out ...
0.2900 0.5900 0.1725 0.3500 0.5500 %0.54
0.2900 0.5900 0.2535 0.3500 0.5500 %0.54
0.2900 0.5800 0.3600 0.3500 0.5500 %0.55
0.3000 0.5100 0.1725 0.3600 0.5700 %0.47
0.3000 0.4900 0.2535 0.3600 0.5700 %0.47
0.3000 0.4900 0.3600 0.3600 0.5700 %0.48
0.3600 0.4200 0.1725 0.3400 0.5200 %0.59
0.3600 0.4200 0.2535 0.3400 0.5200 %0.59
0.3400 0.4300 0.3600 0.3400 0.5200 %0.57
0.3600 0.4400 0.1725 0.3500 0.5400 %0.58
0.3600 0.4400 0.2535 0.3500 0.5400 %0.59
0.3500 0.4400 0.3600 0.3500 0.5400 %0.58
0.3500 0.4200 0.1725 0.3500 0.5700 %0.54
0.3500 0.4400 0.2535 0.3500 0.5700 %0.57
0.3300 0.4500 0.3600 0.3500 0.5700 %0.54
0.3200 0.4800 0.1725 0.2600 0.7100 %0.69
0.3200 0.4800 0.2535 0.2600 0.7100 %0.71
0.3000 0.4900 0.3600 0.2600 0.7100 %0.67
0.3000 0.5700 0.1725 0.2500 0.7800
0.3000 0.5700 0.2535 0.2500 0.7800
0.3000 0.7900 0.3600 0.2500 0.7800
0.3100 0.5900 0.1725 0.2200 0.8400
0.3100 0.5900 0.2535 0.2200 0.8400
0.3000 0.5900 0.3600 0.2200 0.8400
0.2900 0.7200 0.1725 0.2900 0.7500
0.2900 0.7200 0.2535 0.2900 0.7500
0.2900 0.7200 0.3600 0.2900 0.7500
0.2900 0.6800 0.1725 0.2900 0.7700
0.3000 0.6900 0.2535 0.2900 0.7700 %s
0.3100 0.6500 0.3600 0.2900 0.7900
0.3200 0.5200 0.1725 0.3000 0.6500
0.3200 0.4200 0.2535 0.3000 0.6600
0.3300 0.4300 0.3600 0.3000 0.6600
0.3000 0.6000 0.1725 0.3000 0.6000
0.2900 0.7600 0.2535 0.3100 0.6000
0.2900 0.7600 0.3600 0.3100 0.6400
0.2900 0.7600 0.1725 0.3000 0.6700
0.2900 0.7500 0.2535 0.3000 0.6700
0.2900 0.7500 0.3600 0.2900 0.6900
0.2900 0.7500 0.1725 0.2800 0.7100
0.2900 0.7000 0.2535 0.2800 0.7500
0.2900 0.7000 0.3600 0.2800 0.7500
0.2800 0.6700 0.1725 0.2700 0.7800
0.2800 0.6700 0.2535 0.2700 0.7800
0.2900 0.7400 0.3600 0.2700 0.7800
0.2700 0.6700 0.1725 0.2500 0.8400
0.2700 0.7500 0.2535 0.2500 0.9400
0.2600 0.7500 0.3600 0.2400 0.9700];
% surf (DataSet)
% IMPORTANT: the data must be within a same range. for example, if you
% notice the middle column I divided by 100 so it became almost same range
% as the others.
% also to avoid overflow error, I devided all figures by 100 so they become
% within the standard range (0,1). I used matlab command>> DataSet=DataSet/100
'-------------------------TRAINING INITIALIZATION------------------------'
Rec = size(DataSet,1); % returns Rec=48
Var = size(DataSet,2); % returns Var=5
alpha = 0.1; % alpha: learning rate
W = repmat(0,Var,Var); % W is adjacency weights matrix
% TRAINING
start = clock; % read system time
'------------------Differential Hebbian Learning Rule--------------------'
for Epoch = 1:10000 % for 10000 times we repeat training for all samples
for sample = 1:Rec % starting loop for learning all samples
X = DataSet(sample,:); % pick a sample
Y = X*W; % Y= DataSet(sample,:) * Adjacency Weights Matrix
for j = 1:Var
for i = 1:Var
if i ~= j % i is not equal to j
delta = alpha*(X(j) - Y(j))*X(i); % δ = α * (X(j) - Y(j)) * X(i)
W(i,j) = W(i,j) + delta; % W(i,j) = W(i,j)+ δ
end
end
end
end
end
stop = clock; % read system time (STOP time)
Run_Time= 60*(stop(5) - start(5)) + stop(6) - start(6) % computational cost
surf(W) % W is the knowledge base (adjacency model)
%% ----- Extra code by Sam Chak ----- Start here -----
% Define concept labels
concepts= {'Temperature In', 'Humidity In', 'CFM of Ceiling Fan', 'Temperature Out', 'Humidity Out'};
% Rescale the adjacency matrix W with fuzzy weights
disp(W)
maxW = max(W(:)) % max value in W
minW = min(W(:)) % min value in W
if abs(maxW) >= abs(minW)
bound = abs(maxW);
else
bound = abs(minW);
end
lowerB = -1; % lower bound for scaling purposes
upperB = 1; % upper bound for scaling purposes
FCMap = rescale(W, lowerB, upperB, "InputMin", -bound, "InputMax", bound)
% Create directed graph
G = digraph(FCMap, concepts);
% Plot the FCM
figure;
plot(G, 'Layout', 'force', 'EdgeLabel', G.Edges.Weight, 'LineWidth', 1.5, 'ArrowSize', 12);
title('Fuzzy Cognitive Map - HVAC System Model');
%% ----- Extra code by Sam Chak ----- End here -----
Memory = DataSet*W;
MAPE = 100*sum(abs((Memory - DataSet)./DataSet))/Rec % MAPE error in percentage
%--------------------------------------------------------------------------
'--------------------Testing for column 5---------------------'
% include the sample that want to test:
test = [0.3000 0.4900 0.3600 0.2600 0.7100]
% assume the fifth column is corrupted or missing:
corrupted_test = [0.3000 0.4900 0.3600 0.2600 0.00]
% Here, the coding wiil try to fix it back:
test_fixed = corrupted_test*W;
fifth_column = test_fixed(5)
% now compare against the original values
MAPE = abs(test(5) - test_fixed(5))/test(5) % Mean Absolute Percentage Error
0 Comments
See Also
Categories
Find more on Fuzzy Logic Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
