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