First, optimization function

The mathematical model of FCM algorithm is actually a conditional extremum problem:

To convert the above conditional extremum problem into an unconditional extremum problem, one of the methods that is often used in mathematical analysis is the Lagrange multiplier method to convert conditional extremum into an unconditional extremum problem,

N Lagrange factors need to be introduced, as follows:

 

Then take the derivative of each variable, so as to get the extreme point of each variable.

Second, take the derivative of the cluster centroid Ck

Among them,

So,

Among them, the selected distance DIj has no influence on the solution of centroid.

 

 

 

Third, take the derivative of membership function Uij

The Lagrange function is divided into two parts, and we need to take the derivative of them respectively. The first one is simple, and the second one is derivative:

1) The second half

2) The first half

Taking the derivative of the first part is more complicated and difficult:

 

3) Put the two pieces together

 

 

 

clear; clc; Data = randn (310, 2); [center,U,obj_fcn] = fcm(data,2); plot(data(:,1), data(:,2),'o'); hold on; maxU = max(U); % Find the data points with highest grade of membership in cluster 1 index1 = find(U(1,:) == maxU); % Find the data points with highest grade of membership in cluster 2 index2 = find(U(2,:) == maxU); % line (data (index1, 1), data (index1, 2), 'marker', '*', 'color', 'g'); % line (data (index2, 1), data (index2, 2), 'marker', '*', 'color', 'r'); % Plot the cluster centers plot([center([1 2],1)],[center([1 2],2)],'*','color','k'); hold off; % I = imread('lena.jpg'); %I = imread('eight.tif'); % I = imread('romantic.jpg'); I = imread('bacteria.jpg'); I=rgb2gray(I); figure,imshow(I,[]); The title (' artwork '); G = imnoise (I, 'salt & pepper, 0.02); % Add Gaussian noise figure,imshow(g,[]); Title (' Image with Gaussian noise added '); g = double(g); [m,n] = size(g); k=2; % ---------fcm---------------- fcm_label=zeros(m*n,1); [O,U,obj_fcn1] =fcm(g(:), k); maxU = max(U); for j=1:k index = find(U(j, :) == maxU); fcm_label(index) = j; end fcm_result=reshape(fcm_label,[m n]); figure, imshow(fcm_result,[]); Title (' FCM split result ');Copy the code

The complete code to download www.cnblogs.com/ttmatlab/p/…