Sunday, October 26, 2014

Matlab Code for FOAGRNN in the past




Generalized Regression Networks

A generalized regression neural network (GRNN) is often used for function approximation. It has a radial basis layer and a special linear layer.

Network Architecture

The architecture for the GRNN is shown below. It is similar to the radial basis network, but has a slightly different second layer. Here the nprod box shown above (code function normprod) produces S2 elements in vector n2. Each element is the dot product of a row of LW2,1 and the input vector a1, all normalized by the sum of the elements of a1. For instance, suppose that

   
      LW{2,1}= [1 -2;3 4;5 6];

      a{1} = [0.7;0.3];

Then

          aout = normprod(LW{2,1},a{1})

  aout =

          0.1000
          3.3000
          5.3000

The first layer is just like that for newrbe networks. It has as many neurons as there are input/ target vectors in P. Specifically, the first-layer weights are set to P'. The bias b1 is set to a column vector of 0.8326/SPREAD. The user chooses SPREAD, the distance an input vector must be from a neuron's weight vector to be 0.5.

Again, the first layer operates just like the newbe radial basis layer described previously. Each neuron's weighted input is the distance between the input vector and its weight vector, calculated with dist. Each neuron's net input is the product of its weighted input with its bias, calculated with netprod. Each neuron's output is its net input passed through radbas. If a neuron's weight vector is equal to the input vector (transposed), its weighted input will be 0, its net input will be 0, and its output will be 1. If a neuron's weight vector is a distance of spread from the input vector, its weighted input will be spread, and its net input will be sqrt(-log(.5)) (or 0.8326). Therefore its output will be 0.5.
The second layer also has as many neurons as input/target vectors, but here LW{2,1} is set to T.
Suppose you have an input vector p close to pi, one of the input vectors among the input vector/target pairs used in designing layer 1 weights. This input p produces a layer 1 ai output close to 1. This leads to a layer 2 output close to ti, one of the targets used to form layer 2 weights.

A larger spread leads to a large area around the input vector where layer 1 neurons will respond with significant outputs. Therefore if spread is small the radial basis function is very steep, so that the neuron with the weight vector closest to the input will have a much larger output than other neurons. The network tends to respond with the target vector associated with the nearest design input vector.
As spread becomes larger the radial basis function's slope becomes smoother and several neurons can respond to an input vector. The network then acts as if it is taking a weighted average between target vectors whose design input vectors are closest to the new input vector. As spread becomes larger more and more neurons contribute to the average, with the result that the network function becomes smoother.

Design (newgrnn)

You can use the function newgrnn to create a GRNN. For instance, suppose that three input and three target vectors are defined as
   
      P = [4 5 6];
      T = [1.5 3.6 6.7];

You can now obtain a GRNN with
   
      net = newgrnn(P,T);

and simulate it with
   
      P = 4.5;
      v = sim(net,P);

You might want to try demogrn1. It shows how to approximate a function with a GRNN.

(Reference: From the Matlab Help file)

%%***********************************************

FOGGRNN Program: FOA+GRNN

 
%%************************************************
%% EMA Economic Department, Soochow University, Taipei, Taiwan
%% 
%% Pan's Original 2D-FOAGRNN
%% Use the FOA to adjust the spread of GRNN
%%
% % Copyright by W-T Pan (2011)
% % Revised by W-Y Lin (2011)

%*************************************
% Begin of Program
% Set parameters
% Clear the operating environment
clc;
clear all;
load TXY.txt;

% for testing length of TXY

LengthofInputdata=length(TXY);

% TXY;
% Input No. of Normalized Data
%  Or use mapminmax;

TrainOb=228  % No. of Traning data

% LenghtofTrain=length(OP)

P = TXY(1:TrainOb,1:7);
LenghtofTrain=length(P)

 P=P'

%  Normalized the Data

 for i9=1:length(P(:,1))

    P(i9,:)=(P(i9,:)-min(P(i9,:)))/(max(P(i9,:))-min(P(i9,:)));

 end

NP=P

LtofTrNormal=length(NP);

Ltr=length(NP);

[row,col]=size(TXY);

set=row/5;
row=row-set;
row1=row/2;

%***************************
Lth=length(TXY)
OP = TXY(1:TrainOb,1:7);
LenghtofTrain=length(OP)
NP=NP'

% for testing length of traindata1
traindata1=NP(1:row1,1:col-1);

% length(traindata1);
% for testing length of traindata2

traindata2=NP(row1+1:row,1:col-1);

%length(traindata2);
% target of traindata1

t1=NP(1:row1,col);

% target of traindata2

t2=NP(row1+1:row,col);
t1=t1'
t2=t2'
tr1=traindata1'
tr2=traindata2'

la=1;
X_axis=rand();
Y_axis=rand();
maxgen=100; 
% maxgen=50; 
sizepop=10; 
%*********
for i=1:sizepop

X(i)=X_axis+20*rand()-10;
Y(i)=Y_axis+20*rand()-10;
D(i)=(X(i)^2+Y(i)^2)^0.5;
S(i)=1/D(i);

%***

g=0;
p=S(i); % Learning spread of GRNN

if 0.001>p
  p=1;
end

% Cross validation

if la == 1

  net=newgrnn(tr1,t1,p);
  yc=sim(net,tr2);

  y=yc-t2;%

  for ii=1:row1
    g=g+y(ii)^2;
  end
 
Smell(i)=(g/row1)^0.5; % RMSE

la=2;

 else

  net=newgrnn(tr2,t2,p);
  yc=sim(net,tr1);

  y=yc-t1;%

  for ii=1:row1
    g=g+y(ii)^2;
  end

  Smell(i)=(g/row1)^0.5; % RMSE
 
la=1;

 end

end

%***

[bestSmell bestindex]=min(Smell);

%%
X_axis=X(bestindex);
Y_axis=Y(bestindex);
bestS=S(bestindex);
Smellbest=bestSmell;
%

for gen=1:maxgen

gen

bestS

  for i=1:sizepop

 %

  g=0;

  X(i)=X_axis+20*rand()-10;
  Y(i)=Y_axis+20*rand()-10;

  %

  D(i)=(X(i)^2+Y(i)^2)^0.5;

  %

  S(i)=1/D(i);

  %
  p=S(i); % Learning the spread of GRNN

  if 0.001>p
  p=1;
  end

% Cross validation

if la == 1
  net=newgrnn(tr1,t1,p);
  yc=sim(net,tr2);

  y=yc-t2;%

  for ii=1:row1
    g=g+y(ii)^2;
  end

  Smell(i)=(g/row1)^0.5;  % RMSE
 
la=2;

 else

  net=newgrnn(tr2,t2,p);
  yc=sim(net,tr1);

  y=yc-t1;

  for ii=1:row1
    g=g+y(ii)^2;
  end

  Smell(i)=(g/row1)^0.5; 

  la=1;

 end

end
   
  %***

  [bestSmell bestindex]=min(Smell); % find the min of RMSE

  %***
   if bestSmell<Smellbest

         X_axis=X(bestindex);
         Y_axis=Y(bestindex);
         bestS=S(bestindex);
         Smellbest=bestSmell;
   end

   %

   yy(gen)=Smellbest;
   Xbest(gen)=X_axis;
   Ybest(gen)=Y_axis;
end

%

figure(1)

plot(yy)

title('Optimization process','fontsize',12)
xlabel('Iteration Number','fontsize',12);ylabel('RMSE','fontsize',12);

bestS
Xbest
Ybest

figure(2)

plot(Xbest,Ybest,'b.');
title('Fruit fly flying route','fontsize',14)
xlabel('X-axis','fontsize',12);ylabel('Y-axis','fontsize',12);
%*******Begin to Predict

% TestData

LengthofInputdata=length(TXY)

% Input No. of Normalized Testing Data
% LenghtofAll=length(OP)

P = TXY(1:LengthofInputdata,1:7);

% LenghtofTallData=length(P);
% Length of testing data (All Data Normalized)
% Changed Non-normalized Data into Normalized Data

P=P';

for i9=1:length(P(:,1))
  P(i9,:)=(P(i9,:)-min(P(i9,:)))/(max(P(i9,:))-min(P(i9,:)));
end

Nt=P';

% Training Data

TrainData=Nt(1:row,1:col-1);
tr=TrainData';

% tr=[tr1 tr2]
% LTr=length(tr)
% Testing Data

TestData=Nt(row+1:LengthofInputdata,1:col-1);

% predict value of testdata
% No target Y

test3=TestData';
LengthofTestData=length(TestData)
t3=TXY(row+1:LengthofInputdata,col);

% length_tr3=length(tr3);
% tt=Nt(1:row,col);

tt=[t1 t2];

% Ltt=length(tt)
% bestS for parameter p;

p=bestS;

% TrainData put inot grnn

net=newgrnn(tr,tt,p);

%% predict value of testdata

ytest=sim(net,test3);
Y_hat=ytest'

% length_Y_hat=length(Y_hat)
% Predicted output Y_hat normalized
Lny=length(Y_hat);
P = Y_hat(1:Lny,1);
P=P';
LenghtofTrain=length(P)

% Changed Non-normalized Data into Normalized Data

for i9=1:length(P(:,1))

  P(i9,:)=(P(i9,:)-min(P(i9,:)))/(max(P(i9,:))-min(P(i9,:)));

end

 NPP=P';

% target of testdata
Target3=t3;

save Y_hat

% End of Program

Test it!

Good Luck!

References:

1. Pan, W.-T. (2011). Fruit Fly Optimization Algorithm. Taiwan: Tsang Hai Book  Publishing Co.,   ISBN 978-986-6184-70-3. (in chinese).
2. Nien Benjamin (2011) Application of Data Mining and Fruit Fly Optimization Algorithm to Construct  Financial Crisis Early Warning Model – A Case Study of Listed Companies in Taiwan, Master Thesis, Department of Economics, Soochow University, Taiwan (in chinese), Adviser: Wei-Yuan Lin. 
3. Wei-Yuan (2012) "A Hybrid Approach of 3D Fruit Fly Optimization Algorithm and General  Regression Neural Network for Financial Distress Forecasting ", Jan. 2012, Working paper, Soochow University, Taiwan.
 

Jing Si Aphorism:
The greater our generosity
the greater our blessings



Soochow University EMA

Friday, October 24, 2014

How to improve the Pan's FOA program

 

 

 

Question from Universiti Malaysia  below: 

Dear Dr Wei-Yuan Lin

 My name is kamal from Universiti Malaysia Pahang. I am trying to
understand your Fruit fly Optimization Algorithm  and implement it to
solve the t-way testing problem.

I would really appreciate  if you could send in sample source code
especially in Java if you have one. FYI, I have downloaded all your
papers.  But still having hard time to understand especially on how to
out in the objective function based on the smell.

I have got this simple quadratic problem and intend to find the x that
gives minimum .. still unable to solve it using FOA

f(x) = (x-10)(x-2)


Ans: you are going to find the min  instead of  the max.

The program are modified as follow:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Pan's Original 2D-FOA
%% EMA Economic Department, Soochow University, Taipei,Taiwan
%
% Copyright by W-T Pan (2011)
% Revised by W-Y Lin (2011)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%***Topic: How to find  the Min. value of a quadratic function

% Clear the operating environment.
tic
clc
clear

% Randomize the initial Drosophila population positions.
X_axis=10*rand();
Y_axis=10*rand();

% Set parameters
maxgen=500;  % No.of iterations
sizepop=100;  % Population size

% Start the FOA: Flies use the sense of smell to find food

for i=1:sizepop

% The Drosophila uses its olfactory to search the food
% by random direction and distance

X(i)=X_axis+2*rand()-1;
Y(i)=Y_axis+2*rand()-1;

% Due to the fly cannot find the exact location of the prey, so we first estimate the distance from the origin (Dist).
% And then calculate the flavor concentration determination value (S), it is the inverse of the distance.

D(i)=(X(i)^2+Y(i)^2)^0.5;
S(i)=1/D(i);

% Concentration determination value (S) is substituted into the fitness function, i.e. the concentration of the flavor (Smelli) of the flies.

% Smell(i)=7-S(i)^2;
Smell(i)= (S(i)-10)*(S(i)-2);

end

% Identify the highest concentration values of this fruit fly Drosophila groups (find the maximum value).

[bestSmell bestindex]=min(Smell); % modified

% Retain the best  Concentration values and best x, y coordinates of the flies

X_axis=X(bestindex);
Y_axis=Y(bestindex);
Smellbest=bestSmell;

% Start the Drosophila iterative optimization

for g=1:maxgen   

 for i=1:sizepop

X(i)=X_axis+2*rand()-1;
Y(i)=Y_axis+2*rand()-1;
D(i)=(X(i)^2+Y(i)^2)^0.5;
S(i)=1/D(i);
Smell(i)= (S(i)-10)*(S(i)-2);


end

[bestSmell bestindex]=min(Smell); % modified

% Determine whether the  concentration value is greater than the previous one.
% If so, the best value and its location of the fly is retained.
% Then all flies utilize their visual to find this best position.

if bestSmell<Smellbest  % modified
X_axis=X(bestindex);
Y_axis=Y(bestindex);
Smellbest=bestSmell;
S_best=S(bestindex);

end

% Record  the optimal Smell value of each generation to yy array.
% Record the coordinates of the optimal iterations

yy(g)=Smellbest;
Xbest(g)=X_axis;
Ybest(g)=Y_axis;
end

% *** Draw the optimal concentration values and flight path for every iteration

figure(1)
plot(yy)
grid  on;
title('Optimization process 7-X^2','fontsize',14)
xlabel('Iteration Number','fontsize',12);ylabel('Smell','fontsize',14);

figure(2)
plot(Xbest,Ybest,'b.');
grid on;
title('Fruit fly flying route 7-X^2','fontsize',14)
xlabel('X-axis','fontsize',12);ylabel('Y-axis','fontsize',12);

% pause(0.5)

S_best

% yy
Smellbest
toc
%%******************************************

Simulated Outputs:

S_best =     5.9991

Smellbest =   -16.0000

Elapsed time is 0.441575 seconds.

%%*********************************

 More than one variable case:

Dear kamal :

You cannot find the minimum value of f(x)=(x1-10)(x2-2) by any method, including FOA. It does not exit. You can try the other function.

First, I will give you the modified Pan's Matlab FOA program below, please find the defect of it. Then Email to me. I will offer you a right program to solve it.
 
Pan's 3D-FOA Porgram:

%*****************************************************************
% Pan's  3D-FOA
% EMA Economic Department, Soochow University, Taipei,Taiwan
% Copyright by W-T Pan (2011)
% Revised by W-Y Lin (2011)
%******************************************************************
%  A Defect QP for Two Variables
 % Finding Min  Smell(i)=f(x1,x2)=(x1(i)-10)^2+(x2(i)-10)^2;
 % Optimal solution is x1*=10, x2*=10, f*(x1,x2)=0

%***
tic
clc
clear

pp=20;
X_axis=pp*rand();
Y_axis=pp*rand();
Z_axis=pp*rand();

%
maxgen=500;
sizepop=100; 

%***
for i=1:sizepop

%%***
X(i)=X_axis+2*rand()-1;
Y(i)=Y_axis+2*rand()-1;
Z(i)=Z_axis+2*rand()-1;

%***
D(i,1)=(X(i)^2+Y(i)^2+Z(i)^2)^0.5;
D(i,2)=(X(i)^2+Y(i)^2+Z(i)^2)^0.5;
x1(i)=1/D(i,1);
x2(i)=1/D(i,2);

%***
%
% f(x)=(x*x)-(12*x)+20) = (x-10)(x-2)
% unbounded solution
 % Smell(i)=(x1(i)-10)^2+(x2(i)-2)^2;

 Smell(i)=(x1(i)-10)^2+(x2(i)-10)^2;
end
%***
[bestSmell bestindex]=min(Smell);

%***
X_axis=X(bestindex);
Y_axis=Y(bestindex);
Z_axis=Z(bestindex);
Smellbest=bestSmell;

% add xValueBest,yValueBest
xValueBest=x1(bestindex);
yValueBest=x2(bestindex);

%***
for g=1:maxgen   
%***
  for i=1:sizepop
 
  X(i)=X_axis+2*rand()-1;
  Y(i)=Y_axis+2*rand()-1;
  Z(i)=Z_axis+2*rand()-1;
 
  
  D(i,1)=(X(i)^2+Y(i)^2+Z(i)^2)^0.5;
  D(i,2)=(X(i)^2+Y(i)^2+Z(i)^2)^0.5;

%***
  
   x1(i)=1/D(i,1);
   x2(i)=1/D(i,2);
  
   Smell(i)=(x1(i)-10)^2+(x2(i)-10)^2;
  
  end
 
  %***
  [bestSmell bestindex]=min(Smell);
  %***
 
if bestSmell<Smellbest
    X_axis=X(bestindex);
    Y_axis=Y(bestindex);
    Z_axis=Z(bestindex);
    Smellbest=bestSmell;

% add xValueBest,yValueBest
    xValueBest=x1(bestindex);
    yValueBest=x2(bestindex);
  
   end

%***
    optimalobj(g)=Smellbest;
    Xbest(g)=X_axis;
    Ybest(g)=Y_axis;
    Zbest(g)=Z_axis;
   
    xVBest(g)=xValueBest;
    yVBest(g)=yValueBest;
  
end

%***
figure(1)

subplot(2,2,1)
plot(optimalobj);
grid on;
title(' QP function ','fontsize',14)
xlabel('Evolution','fontsize',12);ylabel('Objective Function','fontsize',12);

subplot(2,2,2)
plot3(Xbest,Ybest,Zbest,'b.');
grid on;
title('Fruit fly flying route','fontsize',14)
xlabel('X-axis','fontsize',12);ylabel('Y-axis','fontsize',12);zlabel('Z-axis','fontsize',12);

subplot(2,2,3)
plot(xVBest,'b.')
grid on;
title('x1','fontsize',14)
xlabel('Evolution','fontsize',12);ylabel('Value','fontsize',12);

subplot(2,2,4)
plot(yVBest,'b.')
grid on;
title('x2','fontsize',14)
xlabel('Evolution','fontsize',12);ylabel('Value','fontsize',12);

yValueBest
xValueBest
optimalobj
toc

%%**********************************************************************

Reference: Nien Benjamin (2011) Application of Data Mining and Fruit Fly Optimization Algorithm to Construct  Financial Crisis Early Warning Model – A Case Study of Listed Companies in Taiwan, Master Thesis, Department of Economics, Soochow University, Taiwan (in chinese), Adviser: Wei-Yuan Lin.


Jing Si Aphorism:

To give with joy is to help others with a happy mood

Soochow University EMA
 

Wednesday, October 22, 2014

FOA for constrained evolutionary optimization


 

Solving PrG6f(x)

%%*********************************
 % Matlab Code by A. Hedar (Nov. 23, 2005).
 % Min y = (x(1)-10)^3+(x(2)-20)^3;

  % Constraints

% y(1) = -(x(1)-5)^2-(x(2)-5)^2+100

%y(2) = (x(1)-6)^2+(x(2)-5)^2-82.81;

 % Variable lower bounds
% y(3) = -x(1)+13;

% y(4) = -x(2);

 % Variable upper bounds

% y(5) = x(1)-100;

% y(6) = x(2)-100;
 

Optimal value x*=(14.095,0.84296) f*=-6961.81



 %%*********************************

Case 1:

 
 
 
 

Clever 3D-FOA (More efficient):



Output:
 
  

 

 

Optimal value x* = (13.1708, 0.0017), f* = -7966.1
%%************************************************

Original 3D-FOA:  


 
 

Output:

Optimal value x*= (13.0467, 0.7330), f*= -7123.9

 %%**************************************************************
 

Case 2:

 
% Min y = (x(1)-10)^3+(x(2)-20)^3;

 % Constraints

%  -(x(1)-5)^2-(x(2)-5)^2 + 100 <=0
%  (x(1)-6)^2+(x(2)-5)^2-82.81 <=0;

 % Variable lower bounds
%  -x(1)+13 <=0 ;
%  -x(2) <=0 ;  ;

% Variable upper bounds
%  x(1)-100 <=0 ;
%  x(2)-100 <=0 ;
%%********************
 Output:
 


 

 

 

 

 
  
Optimal value x*= (14.0989, 0.8514), f*= -6952.3

Smellbest1 =   1.0e+03 * -6.9523
 
x1Best =  14.0989
x2Best =  0.8514
g1 =     -1.7997
g2 =     -0.0140
>> 
%%*********************************

 PS:  After my paper was published, and I will put these programs into my blogger.

 
Jing Si Aphorism:
 
 
Willing to think,
cultivate ourselves,
and take mindful action,  
there is nothing
we cannot achieve.
 
 
 
 
 Soochow University EMA
 

Friday, September 26, 2014

FOA Source Codes of MATLAB



From now on, I am going to share the FOA source codes of MATLAB to all of you.

There are two topics:

One is optimization with/without constraints and the other one is (stochastic) optimal control with/without constraints.


1. Optimization without constraints.
2. Optimization with constraints.
3. Deterministic optimal control with/without constraints.
4. Stochastic optimal control with/without constraints.


1.    Optimization without constraints: QP

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Pan's Original 2D-FOA
%% EMA Economic Department, Soochow University, Taipei,Taiwan
%
% Copyright by W-T Pan (2011)
% Revised by W-Y Lin (2011)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Topic: How to find  the max value of a quadratic function

% Clear the operating environment.
tic
clc
clear

% Randomize the initial Drosophila population positions.
X_axis=10*rand();
Y_axis=10*rand();

% Set parameters
maxgen=100;  % No.of iterations
sizepop=20;  % Population size

% Start the FOA: Flies use the sense of smell to find food

for i=1:sizepop

% The Drosophila uses its olfactory to search the food
% by random direction and distance

X(i)=X_axis+2*rand()-1;
Y(i)=Y_axis+2*rand()-1;

% Due to the fly cannot find the exact location of the prey, so we first estimate the distance from the origin (Dist).
% And then calculate the flavor concentration determination value (S), it is the inverse of the distance.

D(i)=(X(i)^2+Y(i)^2)^0.5;
S(i)=1/D(i);

% Concentration determination value (S) is substituted into the fitness function, i.e. the concentration of the flavor (Smelli) of the flies.

Smell(i)=7-S(i)^2;

end

% Identify the highest concentration values of this fruit fly Drosophila groups (find the maximum value).

[bestSmell bestindex]=max(Smell);

% Retain the best  Concentration values and best x, y coordinates of the flies

X_axis=X(bestindex);
Y_axis=Y(bestindex);
Smellbest=bestSmell;

% Start the Drosophila iterative optimization

for g=1:maxgen   

 for i=1:sizepop

X(i)=X_axis+2*rand()-1;
Y(i)=Y_axis+2*rand()-1;
D(i)=(X(i)^2+Y(i)^2)^0.5;
S(i)=1/D(i);
Smell(i)=7-S(i)^2;

end

[bestSmell bestindex]=max(Smell);

% Determine whether the  concentration value is greater than the previous one.
% If so, the best value and its location of the fly is retained.
% Then all flies utilize their visual to find this best position.

if bestSmell>Smellbest
X_axis=X(bestindex);
Y_axis=Y(bestindex);
Smellbest=bestSmell;

end

% Record  the optimal Smell value of each generation to yy array.
% Record the coordinates of the optimal iterations

yy(g)=Smellbest;
Xbest(g)=X_axis;
Ybest(g)=Y_axis;

% *** Draw the optimal concentration values and flight path for every iteration

figure(1)
plot(yy)
grid  on;
title('Optimization process 7-X^2','fontsize',14)
xlabel('Iteration Number','fontsize',12);ylabel('Smell','fontsize',14);

figure(2)
plot(Xbest,Ybest,'b.');
grid on;
title('Fruit fly flying route 7-X^2','fontsize',14)
xlabel('X-axis','fontsize',12);ylabel('Y-axis','fontsize',12);
pause(0.5)
end
toc

Simulated results:

Here X>=0 (constraint), Optimal value (Smell) = 7.

Reference:

1. Pan, W.-T. (2011). Fruit Fly Optimization Algorithm. Taiwan: Tsang Hai Book  Publishing Co., ISBN 978-986-6184-70-3. (in chinese).

2. Nien Benjamin (2011) Application of Data Mining and Fruit Fly Optimization Algorithm to Construct  Financial Crisis Early Warning Model – A Case Study of Listed Companies in Taiwan, Master Thesis, Department of Economics, Soochow University, Taiwan (in chinese), Adviser: Wei-Yuan Lin.




Jing Si Aphorism:

Be honest and truthful in everything you do.
Be gentle and forgiving in your relationships with others

 
 


 Soochow University EMA
 

Wednesday, September 10, 2014

Who is the Winner? 3D-FOA or PSO?









Answer: 3D-FOA


Average Efficiency Comparisons of 3D-FOA and PSO for 32 Nonlinear Functions


Although PSO can solve most of these optimization problems, it costs much time compared to 3D-FOA. In our extensive experiments, we find that FOA is more accurate than PSO, the average time it takes is only half of that of PSO. It is interesting to discover five functions (Schwefel, Goldstein, Shubert, Polynomial, and Sum of Sin functions) are deceptive in PSO technique. In other words, PSO is potentially prone to convergence in the wrong direction.

We used five different notebooks to run 20 trails for these functions. The RMSE of simulated function values and average time spent are shown in the table  below. It is obviously found that 3D-FOA can solve all these optimization problems and costs less time compared to the PSO. The average RMSE of all functions by 3D-FOA and PSO are 0.65, 30.5, respectively. And averaged time spent over 20 trials for these two algorithms are 0.61 second and 1.25 seconds respectively.





 

Merry Mid-Autumn Festival!
メリー中秋節!
敬祝中秋節快樂!

Give you a cake
あなたのケーキを与える
送你一個蛋糕

 
 
 



Jing Si Aphorism:
 
There is no need to learn many teachings.
If we can put one simple verse into practice,
we can awaken our ture nature of goodness.
 


Monday, September 8, 2014

Two Famous Economic Models Solved by 3D-FOA



3D-FOA が解決しようと二つの有名な経済モデル


In addition, we also use two popular economic examples to find the optimal solutions based on the 3D-FOA as follows:

Let us first postulate a two-product firm under circumstances of monopoly.

1. Problem of a Multiproduct Firm

Suppose that the demands facing the monopolist firm are as follows:

  Q_1= 40 - 2 P_1  + P_2                    (17)
  Q_2= 15  +  P_1   - P_2                    (18)

The firm total revenue function can be written as

R=P_1 Q_1+P_2 Q_2                         (19)

And the total cost function is

C=Q_1^2+Q_1 Q_2+ Q_2^2              (20)

Then the profit function will be:


Π = R-C= 55Q_1+ 70 Q_2 - 3Q_1 Q_2  - 2 Q_1^2 - 3 Q_2^2       (21)

which is the objective function with two choice variables (Q_1, Q_2). Thus the optimal solution of output levels and profit can be found by Calculus as following:

(Q_1 *, Q_2 *, Π*) = (8, 7 2/3, 488 1/3))

And our computer simulation result is shown in Figure 14:

We find the solution of Q_1 * = x1 = 7.91, Q_2 * =  x2  =7.75, and profit  Π* = 488.32 by 3D-FOA. It takes 0.129 second.

 
 


  Fig. 14 Find the maximal value of monopolistic profit
 

2. Input Decisions of a Firm

Next, consider a competitive firm with the following profit function: 


R-C=PQ-(wL+rK)                   (22)
 

where P=price, Q=output, K=capital, L=labor; w and r denote input price for L and K, respectively, Π= profit.

Since the firm operates in a competitive market, the exogenous variables are P, w, and r, There are three endogenous (decision) variables, K, L, and Q in this example. Output Q is in turn a function of K and L via the Cobb-Douglas production function

Q = f (K,L) = AL^α K^β          (23)

For simplicity, we shall consider the symmetric case where α=β <1/2, Therefore, the cost function and profit function are defined as:

C = w L+r K                               (24)
 Π = P Q- C                                (25)

Traditional Calculus gives us an expression (closed solution) for the optimal inputs and output as a function of the exogenous variables P, w, r respectively, i.e.

L* = (( P α w^ ( α-1) r ^ (-α))) ^ ( 1/(1-2α))           (26)
K* = (( P α r^ (α-1) w ^ (-α))) ^ (1/(1-2α))             (27)
Q* = (( α^2 P ^2 / w r)) ^ (α/(1-2α))                       (28)

Assume that the competitive price is $100 (P=100), wage rate $10 (w=10), Interest rate 10% (r=0.1), α=β=0.4. Then the optimal solutions are L*= 1024, K*=1024, Q*= 256, C*= 2048, and  Π*=512.





Fig. 15 Find the maximal value of competitive firm’s profit


Similarly, from 3D-FOA, It is easier to find the optimal solution of  L*=1026,  K*=1026 and profit Π*= 512 only 0.486 second, which is shown in Figure 15.

These two firm’s profits and their contours are also shown in Figure 16:


Fig. 16 Two firm’s optimal profits and their contours

From the simulation results of these two economic examples, we could easily find the optimal solutions by 3D-FOA compare to traditional calculus. Therefore, our method can be further applied in other economic applications in the future.

References:

  1. Wei-Yuan Lin (2013), “3D-Novel fruit fly optimization algorithm and its applications in economics,” Working paper, Department of Economics, Soochow University, Taiwan.
  2. Chiang AC, Wainwright K (2005) Fundamental methods of mathematical economics, 4th edn. McGraw Hill.
  3. Nien Benjamin (2011) Application of data mining and fruit fly optimization algorithm to construct financial crisis early warning model – A case study of listed companies in Taiwan, Master Thesis, Department of Economics, Soochow University, Taiwan (in chinese).
  4. Wei-Yuan Lin (2012),“A Hybrid Approach of 3D Fruit Fly Optimization Algorithm and General Regression Neural Network for Financial Distress  Forecasting,” Working Paper, Jan. 2012, Soochow University, Taiwan.
Jing Si Aphorism:

While working, learn;
While learning, awaken to many truths of life.
 
  Soochow University EMA
 

Sunday, September 7, 2014

Why should I build FFOA blog here?

 

なぜ私はここFFOAのブログを構築する必要がありますか?

 

Motivation:

More than there-year ago, our FOAA group had sent a lot of papers of these topics to the famous (SCI,TSSCI) Journals. Unfortunately, most of these articles are all being delayed and rejected. Our NSC (Ministry of Science and Technology in Taiwan) plans to apply for grants are also not being considered. So in the future we are going to use this blog to share our past achievements, and will also present our current plans to this field, just hoping to be helpful for the academic research around the world.

Let me first introduce the book, “Fruit Fly Optimization Algorithm (FFOA),” written by Taiwan's scholar Dr. Pan. Up to now, most of the swarm intelligence algorithms are invented by foreigners. However, he is one of the scarce scholars who wrote this book not for making money, but hoping to share the new ideas around the world.

Perhaps some readers may ask why the author can propose this optimization algorithm.

Here is the answer:

One day, the author eats the watermelon in his room, not so long attracting a few fruit flies. At that time, the doors and windows are closed and the air conditioner is in operation, fruit flies can still detect where the food is. For the curiosity, the author tried to find the answer through the internet, and finally realized the sensory characteristics of the fruit flies. He discovered that Drosophila fruit flies use their senses of smell to find food around the location, and then visually determine the correct position. Therefore, the author follows these two steps to develop this algorithm.

References:

1. Pan, W.-T. (2011). Fruit Fly Optimization Algorithm. Taiwan: Tsang Hai Book Publishing Co., ISBN 978-986-6184-70-3. (in chinese).

2. Nien Benjamin (2011) Application of Data Mining and Fruit Fly Optimization Algorithm to Construct  Financial Crisis Early Warning Model – A Case Study of Listed Companies in Taiwan, Master Thesis, Department of Economics, Soochow University, Taiwan (in chinese), Adviser: Wei-Yuan Lin.

3. Wei-Yuan Lin (2012),“A Hybrid Approach of 3D Fruit Fly Optimization Algorithm and General Regression Neural Network for Financial Distress  Forecasting,” Working Paper, Jan. 2012, Soochow University, Taiwan.

4. 林維垣(2011),「應用資料採礦與果蠅演算法建構財務危機預警模型-以台灣上市櫃公司為例」,東吳大學經濟系,2011年8月。


Jing Si Aphorism:

Each time we forgive others, we are, in fact, sowing blessings.
The more magnanimity we show, the more blessings we enjoy. 
 
 
 
 Soochow University EMA
 
 

Tuesday, September 2, 2014

3D-Novel fruit fly optimization algorithm and its applications in economics



3D-目新しいミバエ最適化アルゴリズムと経済学への応用


For those academic users (not for business) who interest in the following topic, I would like to share the source codes to you. Please send me your email to k8888@scu.edu.tw.

ps: Sorry, I will select the suitable users in advance. 

Topic:“ 3D-Novel fruit fly optimization algorithm and its applications in economics”

 
This week, the Computational, Cognitive, Behavioral Social Science Research Group (CCB) hold its fifth symposium on August 22nd, 2014. Prof. Lin inaugurated a speech which was titled "3D-Novel fruit fly optimization algorithm and its applications in economics". Prof. Lin's vivid speech reveals the most advanced algorithm which can be used in both engineering and economics. Warm discussion including issues from inter-disciplines followed the speech. The Group decided to incorporate these issues into next meeting agendas for further research and discussion.
 





















































































 

This paper will be published in the "3D-Novel Fruit Fly Optimization Algorithm and its Applications in Economics", Neural Computing & Application (NCA), pp 1-20, 2015. (SCI).

After the publication of this paper, I will publish the source code (MATLAB).
   .

Jing Si Aphorism:
 
Good actions require everyone's cooperation.
So let's not cling to personal biases.
 
 
良い事はみんなで力を合わせで成就しなければならない。
よつで、それぞれの先入觀は禁物である
 
 Soochow University EMA