You are on page 1of 35

目次

はじめに 1

第 1 章 遺伝的アルゴリズム 2
第 1 節  遺伝的アルゴリズムとは . . . . . . . . . . . . . . . . . . . . . . . 2
第 2 節  アルゴリズム . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
第 3 節  金融政策シミュレーションへの応用 . . . . . . . . . . . . . . . . . 3
第 4 節  遺伝的アルゴリズムへのあてはめ . . . . . . . . . . . . . . . . . . 3
第 4 節  シミュレーション方法 . . . . . . . . . . . . . . . . . . . . . . . . 4

第 2 章 New Keynesian モデル 5


第 1 節  New IS-LM モデル . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
第 2 節  Hybrid 型 New IS-LM モデル . . . . . . . . . . . . . . . . . . . . . 5

第 3 章 特殊なモデル 7
3.1 モデルのセットアップ . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

第 4 章 結果 8
4.1 New Keynesian モデル . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2 特殊なモデル . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

第 5 章 考察 9
5.1 New Keynesian モデル . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.2 特殊なモデル . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

第 6 章 まとめ 10

あとがき 11

1
参考文献 13
付録 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
はじめに

ケインズの登場以降、マクロ経済政策は経済学の扱う問題とされてきた。経済政策
は経済学が発展した現代においてもメインストリームで扱われる問題である。経済政
策の中でも、金融政策は経済が発展して経済情勢の変化が高速化してきた昨今、施行
ラグが少ない反面、効果ラグの大きいためにフォアードルッキングな政策運営が必要
とされ、難しい舵取りを迫られている。
現在、マクロ経済の研究はミクロ的基礎付けを持った New Keynesian モデル等の動
学的確率的一般均衡モデル1 を用いた研究が盛んである。しかし DSGE モデルを用い
て金融政策のシミュレーションを行う場合、政策ルールを設定する必要がある。この
政策ルールは経済システムを制御するときのフィードバックの法則と考えられる。現
在、テイラールール等の政策ルールが尊重される場合も有るが、依然として人間が経
験から裁量的に決定している。
本論文では、実例を反映して現実に人間が政策立案することを模倣したシミュレー
ションを扱う。これは、一定の政策方針は取らず、柔軟な金融施策を実行することを
意味する。
また、特殊なモデルであっても同様の方法で最適な金融政策経路を導けることを示す。

1
Dynamic Stocastic General Equiblium Model の日本語訳であり、本論文では以降 DSGE モデル
と表記する。

1
第1章 遺伝的アルゴリズム

第 1 節  遺伝的アルゴリズムとは
遺伝的アルゴリズムとは、近似解を求めるアルゴリズムの一つで、ダーウィンの進
化論に基づく生物界の遺伝の法則を模倣したアルゴリズムである。主に解空間が広く、
全探索が通用しない場合に用いる。生物が交叉,突然変異,淘汰を行いながら環境に
より適応した遺伝子を残すことで環境により適応した個体を残す事を利用している。

第 2 節  アルゴリズム
アルゴリズムを以下に示す。
1. [初期集団の生成] ランダムに遺伝子を生成する。
2. [適合度計算] 個体群内のすべての遺伝子 x を適合度 f(x) で評価する
3. [新しい個体群] 新しい遺伝子群が完成するまで、次のステップを繰り返すことによ
り新しい遺伝子群を創り出す
   1. [淘汰] 適合度により個体群の中から両親となる2つの遺伝子を抽出する
   2. [交叉] 新しい子孫を作り出す親を交叉させる
   3. [突然変異] 突然変異確率に従い、新しい遺伝子の一部に対して突然変異を行う
   4. [受け入れ] 新しい子孫を新しい個体群にいれる
4. [置き換え] アルゴリズムの次の実行のために、新しく生成された遺伝子群に全て置
き換える
5. [テスト] 終了条件を満たした場合、終了する。そして現在の遺伝子群の中から最良
の解を得る
6. [ループ] 2 へ戻る

2
第 3 節  金融政策シミュレーションへの応用
一般に金融政策と言った場合、”金利政策 ”、”公開市場操作 ”、”支払準備率操作 ”
の 3 つを指すが、本論文では最も重要視されている金利政策のみを扱う。
 日銀法によると、”日本銀行は物価の安定を通じて経済の安定的な発展に資する”と
ある。そのため、本論文ではインフレ目標からの乖離の分散、GDP ギャップの分散を
最小化することを考える。これを式で表すと


a
Et 2
[yt+j + θ(πt+j − π ∗ )2 ] (1.1)
j=0

となる。ここで、yt は GDP ギャップ、πt はインフレ率、π ∗ は期待インフレ率、a はシ


ミュレーションを行う期間、θ はインフレ率と GDP ギャップのどちらを優先して安定
させるかを表すパラメータである。

遺伝的アルゴリズムへのあてはめ

遺伝子は金利の経路を表す数列 xt とする xt のとる範囲は 0 ≤ xt ≤ 1 とする。金利


水準のとり得る範囲にあわせて拡大し、金利 it 水準とする。これを上述のアルゴリズ
ムに当てはめ、プログラムを書いた。今回使用したアルゴリズムを以下に示す。
1. [初期集団の生成] 遺伝子 xt をランダム関数で生成する
2. [コーティング] 遺伝子 xt にを拡大し、金利 it とする
3. [適応度計算] 金利の経路をマクロモデルにあてはめ、(1.1) 式の値を計算し、適応度
とする
4. [新しい個体群] 新しい遺伝子群が完成するまで、次のステップを繰り返すことによ
り新しい遺伝子群を創り出す
   1. [淘汰] 適合度の良い個体から両親となる2つの遺伝子を抽出する
   2. [交叉] 新しい子孫を作り出す親を交叉させる
   3. [突然変異] 突然変異確率に従い、遺伝子の一部をランダムな値に変更する
   4. [受け入れ] 新しい子孫を新しい個体群にいれる
5. [置き換え] 新しく生成された遺伝子群に全て置き換える
6. [テスト] 終了条件を満たした場合、終了する。そして現在の個体群の最良の解を得

3
7. [ループ] 2 へ戻る

第 4 節  シミュレーション方法
政策シミュレーションに当たって、経済の変動を追う動学的な経済モデルが必要と
なる。今回は政策シミュレーションに利用される機会の多い New Keynesian モデルと、
独自に作成した特殊なモデルを採用した。これは、一般的な政策シミュレーションで
あっても、特殊なモデルであっても遺伝的アルゴリズムによる最適化の有効性を示す
ためである。今回、シミュレーションを行うにあたって、プログラミング言語に JAVA
を利用し、GUI 環境1 のプログラムを開発し、パラメータを変えた場合のシミュレー
ションを容易にした。

1
GUI:Graphical User Interface の略。GUI では、コンピュータの画面上に、ウィンドウ、アイコン、
ボタンといったグラフィックが表示され、ユーザはそれらの中から目的の動作を表すグラフィックスを
マウスなどのポインティングデバイスで選択する。

4
第 2 章 New Keynesian モデル

第 1 節  New IS-LM モデル


New Keynsian のモデルの一つである New IS-LM モデルでの金融政策の最適化を考
える。以下に本研究で使用した New IS-LM モデルモデルを示す。モデルの詳細、導出
過程は加藤 (2006)[1] や矢野 (2008)[5] を参照し、本論文では既にあるものとして扱う。

yt = Et yt+1 − σ(it − Et πt+1 ) (2.1)

πt = βEt πt+1 + αyt (2.2)

y は GDP ギャップ,i は名目金利,Et πt+1 が期待インフレ率,σ ,α は正のパラメータ


である。このモデルは、New Keynesian の最も単純なモデルである。(2.1)、(2.2) を書
き換えれば
α+β σ
Et yt+1 = yt − πt + σit (2.3)
β β
α 1
Et πt+1 = − yt + πt (2.4)
β β
となる。
パラメータ σ 、α、β は加藤 (2006)[1] で用いている値を借用し、σ = 1.5、α = 0.1、
β = 0.45 とする。このモデルにおいて、名目金利 it を操作し、(1.1) 式を最小化する。
これをシミュレーションするプログラムを作成した。プログラムコードを付録に添付
する。

第 2 節  Hybrid 型 New IS-LM モデル


第 1 節で紹介したモデルにインフレ率の粘着性と成長率の粘着性を付加したモデル
である Hybrid 型 New IS-LM モデルについても金融政策の最適化を考える。以下に本

5
研究で使用した Hybrid 型 New IS-LM モデルモデルを示す。第 1 節と同様に、モデル
の詳細、導出過程は加藤 (2006)[1] や矢野 (2008)[5] を参照し、本論文では既にあるも
のとして扱う。
yt = ρEt yt+1 + (1 − ρ)yt−1 − σ(it − Et πt+1 ) (2.5)

πt = βEt πt+1 + (1 − β)πt−1 + αyt (2.6)

y は GDP ギャップ、i は名目金利、Et πt+1 が期待インフレ率、σ 、α、ρ、β は正のパラ


メータである。(2.5)、(2.6) を書き換えれば、
       
 ρ σ −1 0   Et yt+1   0 0 ρ−1 0   yt   σ 
       
       
 0 β α −1   Et πt+1   0 0 0 β−1   πt   0 
  =  +  it (2.7)
       
 0 0 1 0   yt   1 0 0 0   yt−1   0 
       
       
0 0 0 1 πt 0 1 0 0 πt−1 0

となる。さらにバックワードの形に変えて、
   −1      

 

 Et yt+1   ρ σ −1 0    0 0 ρ−1 0   yt   σ   
     
      
       
 Et πt+1   0 β α −1   0 0 0 β−1   
  πt 

 0  

 =    +  it
        
   0 
0      yt−1   0   
 yt   0 1  1 0 0 0      
     
      


 

πt 0 0 0 1 0 1 0 0 πt−1 0
(2.8)
を得る。パラメータ σ 、α、β 、ρ は加藤 (2006)[1] で用いている値を借用し、σ = 1.5、
α = 0.1、β = 0.45,ρ = 0.7 とする。このパラメータを用いて (2.8) 式は
      
 Et yt+1   −1.905 −4.762 −0.429 2.619   yt   2.143 
      
  
 Et πt+1   −0.222 2.222 0 −1.222  
  πt
 
  0  
 =  +  it (2.9)
      
 yt   1 0 0 0   yt−1   0 
      
      
πt 0 1 0 0 πt−1 0

となる1 。
このモデルにおいて、名目金利 it を操作し、(1.1) 式を最小化する。これをシミュレー
ションするプログラムを作成した。プログラムコードを付録に添付する。

1
小数点以下第 4 位を四捨五入

6
第3章 特殊なモデル

3.1 モデルのセットアップ
今回、特殊なモデルとして RBC モデルを独自に改変したモデルを用いる。以下にモ
デルの詳細を示す。

モデルの仮定

以下にモデルの仮定を示す。
1. 労働市場は完全競争
2. 家計, 企業は代表的な 1 つのみを考える
3. 政府は存在しない
4. 家計、企業は予測可能な期間のみで投資計画を立てる
5. 家計は動的な予算制約から各期の予算配分のみを決め、各期の予算は使い切る
6. 家計は計画の末期で予測可能期間中の総収入のうち一定率を残す
7. 家計において、余暇の効用は無い
8. 財市場には消費財と投資財の 2 財が存在する
9. 企業は利潤のみを最大化する

家計の効用最大化

仮定より、家計は可視期間の所得制約の下で効用を最大化する。
家計の効用関数 u(c) を CRRA 効用関数

c1−θ
u(c) = (3.1)
1−θ

とする。
c は消費量、θ は CRRA 効用関数のパラメータである。

7
第4章 結果

New Keynesian モデル、特殊なモデルについてそれぞれのシミュレーション結果を


示す。

4.1 New Keynesian モデル


デフレからのインフレターゲット

初期条件でインフレ率がマイナスの場合のシミュレーション結果を図 に示す。

超過インフレからのインフレターゲット
GDP ギャップショック
GDP ギャップショック

4.2 特殊なモデル
デフレからのインフレターゲット
インフレからのインフレターゲット
成長率の最大化

物価の安定という

家計の効用最大化
不確実性拡大ショック

8
第5章 考察

5.1 New Keynesian モデル


金利ルールとの比較

代表的な金融政策ルールであるテイラールールと比較する。テイラールールのパラ
メータは

5.2 特殊なモデル

9
第6章 まとめ

10
あとがき

本論文では扱わなかったが、金融政策の設計方法として筆者が研究中に考案したア
プローチを挙げる。
今回、政策ルールを設定しない場合を扱ったが、遺伝的アルゴリズムを金融政策に
応用する方法として政策ルールの最適なパラメータを決定する方法もある。今回これ
を利用しなかったのは、評価関数を定めることで最適なパラメータが一意に設定可能
であり、近似解しか求められない遺伝的アルゴリズムを利用するメリットが無いため
である。制御工学では、最適なパラメータを導くのに、LQR 法1 という手法が存在し、
Matlab を用いれば簡単に導出できる。他に、将来の予測から毎期最適なパラメータを
計算する”モデル予測制御”の手法を導入すれば、より柔軟な政策設計が可能となる。
実際の経済政策を考える場合に、モデル予測制御の概念はフォアードルッキングな政
策運営をより明示的に取り入れることとなる。
本論文では全て離散時間モデルを扱った。しかし、実際には経済システムは連続的に
動いており、その中で月次や四半期ごとに得られる経済変数を元に政策を決定してい
る。より忠実に現実に沿った議論をするためには、連続時間の経済モデルを離散時間
データを元にで制御することを考えなければならない。連続時間システムを離散時間で
制御する手法はデジタル制御として制御工学の分野で発展しており、Matlab/Simulink
を用いれば導入は容易である。もし、以上に書いたアプローチに興味を持たれた方が
いらっしゃれば是非試してほしい。
また、今回の研究において [1] 加藤 (2006) を参照する機会が多かったが、この本で
は Matlab を使った政策シミュレーションを多く扱っている。しかし、数値シミュレー
ションをする場合、Matlab に付属している Simulink の利用を推奨したい。Matlab で
はプログラム開発環境が貧弱であり、プログラム開発が難しい。さらに、Matlab 言語
自体は手続き指向言語のため、数値シミュレーションには若干不向きな面がある。これ

1
但し、LQR 法で求めたパラメータではシミュレーション結果が発散する場合も有る

11
を補うのが Simulink パッケージである。Simulink では、直感的にグラフィカルなプロ
グラミングが可能であり、Matlab コードのみを利用するより Simulink と併せて利用す
る事でより簡単かつ効率的にシミュレーションが可能である。また、[5] 矢野 (2008) に
はカリブレーションから全て一括してを行う DYNER という DSGE モデル専用のパッ
ケージが紹介されている。
余談になるが、本論文で扱った New Keynesian モデルとそのパラメータを用いた場
合、政策ルールを設定しなければ状態変数2 が発散する3 。モデルが正しいのであれば、
これまでの金融政策は長期間大きく間違ったことは無いと言えるかもしれない。ハイ
パーインフレのように実際に発散した事例から、モデルとそのパラメータの妥当性を
検証するアプローチも面白いのではなかろうか。
最後に、今回シミュレーションを行うに当たって JAVA を利用した理由を述べる。第
一にオブジェクト指向言語という JAVA の性質から、遺伝的アルゴリズムをプログラ
ムに起こすことが容易である点。第二に、今回は利用しなかったが、プログラミング
言語として人気があるために、行列計算、確率分布など、数値計算用のライブラリが
豊富である点。第三に、Eclipse という高機能なオープンソースの統合開発環境4 があ
り、プログラム開発の負担が少ないという点が挙げられる。

謝辞

本研究の遂行にあたり、ご指導、ご助言を頂きました神戸大学大学経済学部地主敏
樹教授、各研究室員に心より感謝いたします。また、今回の研究で用いた独自のアイ
デアは大学の講義中に得たアイデアが殆どです。入学後、講義をして下さった全ての
教員に厚く感謝いたします。

2
GDP ギャップとインフレ率
3
固有方程式 (特性方程式) の根が 1 より大きい
4
コンパイラ、デバッガなどをひとつの対話型操作環境から利用できるようにしたもの。

12
参考文献

[1] 加藤涼 (2007)『現代マクロ経済学講義』東洋経済新報社,13-127 貢,157-212 貢

[2] David Romer(2005)Advanced Macroeconomics,McGraw-Hill/Irwin:New


York,pp310-315

[3] 高橋麻奈 (2002)『やさしい Java』ソフトバンクパブリッシング株式会社,428-


506 貢

[4] 相良節夫,和田清,中野和司 (2005)『ディジタル制御の基礎』コロナ社

[5] DYNARE による動学的確率的一般均衡シミュレーション


∼新ケインズ派マクロ経済モデルへの応用∼
http://www.esri.go.jp/jp/archive/e_dis/e_dis210/e_dis203a.pdf
(2008 年 12 月 10 日閲覧)

13
付録
本研究で使用したプログラムを以下に添付する。
New Keysian モデルのシミュレーションプログラム

・Main クラス
package policy;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
public class Main extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Main thisClass = new Main();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public Main() {
super();
initialize();
}
private void initialize() {
this.setSize(749, 406);
Graph1 panel = new Graph1();
getContentPane().add(panel);
pack();
this.setTitle("JFrame");
this.setContentPane(panel);

14
}
} // @jve:decl-index=0:visual-constraint="10,10"

・Graph1  クラス

package policy;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Graph1 extends JPanel implements Runnable{
//-------------------field--------------------------
private static final long serialVersionUID = 1L;
//最適化問題に必要な変数
//------------------最適化問題に必要な変数-----------
//----------------経済変数---------------------
public static double[] yeild; //期待所得
public static double[] pi; //インフレ率
public static double[] I; //利子率
public static double bo; //初期の GDP ギャップ
public static double r; //インフレ目標
public static double beta; //初期のインフレ率
public static double oi; //利子率の上限
public static double ui; //利子率の下限
public static double wi; //インフレ目標の重要度
public static double io; //初期の利子率
//--------遺伝的プログラミングに関係する変数---------
public static int sample;//遺伝子集団の数

15
public static int rep; //繰り返し回数
public static double prob;//突然変異の確率
private static Simu1 ga; // // @jve:decl-index=0:
private Thread anime1;
private JButton jButton = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
static JTextField jTextField = null;
static JTextField jTextField1 = null;
private JLabel jLabel2 = null;
static JTextField jTextField2 = null;
private JLabel jLabel3 = null;
static JTextField jTextField3 = null;
private JLabel jLabel4 = null;
static JTextField jTextField4 = null;
private JLabel jLabel5 = null;
static JTextField jTextField5 = null;
private JTextField jTextField6 = null;
public static final int WIDTH = 800;
public static final int HEIGHT = 500;
private JLabel jLabel6 = null;
private static JTextField jTextField7 = null;
private static JTextField jTextField8 = null;
private static JTextField jTextField9 = null;
private JLabel jLabel7 = null;
private JLabel jLabel8 = null;
private static JTextField jTextField10 = null;
//----------------constructor-------------------------
public Graph1() {
super();

16
initialize();
anime1 = new Thread(this);
setPreferredSize(new Dimension(WIDTH, HEIGHT));
}
private void initialize() {
jLabel8 = new JLabel();
jLabel8.setBounds(new Rectangle(540, 11, 84, 24));
jLabel8.setText("初期の利子率");
jLabel7 = new JLabel();
jLabel7.setBounds(new Rectangle(333, 44, 131, 22));
jLabel7.setText("インフレ目標の重要度");
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(13, 46, 150, 20));
jLabel6.setText("利子率(上限)(下限)");
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(275, 70, 85, 30));
jLabel5.setText("突然変異確率");
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(136, 71, 91, 27));
jLabel4.setText("繰り返し回数");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(30, 69, 68, 28));
jLabel3.setText("サンプル数");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(371, 7, 118, 25));
jLabel2.setText("初期のインフレ率");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(204, 7, 126, 23));
jLabel1.setText("初期の GDP ギャップ");
jLabel = new JLabel();

17
jLabel.setBounds(new Rectangle(66, 9, 90, 24));
jLabel.setText("インフレ目標");
this.setSize(730, 315);
this.setLayout(null);
this.add(getJButton(), null);
this.add(jLabel, null);
this.add(jLabel1, null);
this.add(getJTextField(), null);
this.add(jLabel2, null);
this.add(getJTextField2(), null);
this.add(jLabel3, null);
this.add(getJTextField3(), null);
this.add(jLabel4, null);
this.add(getJTextField4(), null);
this.add(jLabel5, null);
this.add(getJTextField5(), null);
this.add(getJTextField6(), null);
this.add(getJTextField1(), null);
this.add(jLabel6, null);
this.add(getJTextField7(), null);
this.add(getJTextField8(), null);
this.add(getJTextField9(), null);
this.add(jLabel7, null);
this.add(jLabel8, null);
this.add(getJTextField10(), null);
this.add(jButton, null);
}
//-----------------method--------------------
public void run() {
ga=new Simu1(); //GAmain オブジェクトの生成、初期化

18
ga.Init();
for(int i=0;i<rep;i++){
Gene[] A=ga.Optimal(); //シミュレーション実行
yeild=ga.keep[0].y;
I=ga.keep[0].I;
pi=ga.keep[0].pi;
try{
Thread.sleep(1);
repaint();
double adapt=100+A[0].Adaptation();
jTextField6.setText(i+"世代で適応度は"+adapt);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("実行");
jButton.setBounds(new Rectangle(-1, 9, 64, 25));
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPer
Getdata();
//anime1.start();
Thread ani =new Thread(anime1);
ani.start();
ani=null;
}

19
});
}
return jButton;
}
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(158, 9, 41, 23));
jTextField.setText("0.05");
}
return jTextField;
}
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setText("0.05");
jTextField1.setBounds(new Rectangle(335, 9, 34, 20));
}
return jTextField1;
}
private JTextField getJTextField2() {
if (jTextField2 == null) {
jTextField2 = new JTextField();
jTextField2.setBounds(new Rectangle(494, 11, 36, 22));
jTextField2.setText("0.05");
}
return jTextField2;
}
private JTextField getJTextField3() {
if (jTextField3 == null) {

20
jTextField3 = new JTextField();
jTextField3.setBounds(new Rectangle(100, 74, 35, 23));
jTextField3.setText("60");
}
return jTextField3;
}
private JTextField getJTextField4() {
if (jTextField4 == null) {
jTextField4 = new JTextField();
jTextField4.setBounds(new Rectangle(232, 76, 40, 21));
jTextField4.setText("1000");
}
return jTextField4;
}
private JTextField getJTextField5() {
if (jTextField5 == null) {
jTextField5 = new JTextField();
jTextField5.setBounds(new Rectangle(362, 77, 46, 21));
jTextField5.setText("0.25");
}
return jTextField5;
}
private JTextField getJTextField6() {
if (jTextField6 == null) {
jTextField6 = new JTextField();
jTextField6.setBounds(new Rectangle(11, 100, 672, 19));
}
return jTextField6;
}
public void paintComponent(Graphics g) {

21
super.paintComponent(g);
g.setColor(Color.black);
//消費の流列のグラフ
g.drawLine(50, 150, 50,400);
g.drawLine(51, 150, 51, 400);
g.drawLine(50, 400, 370,400);
g.drawLine(50, 401, 370, 401);
if(ga!=null){
int gh=700;
for(int i=0;i<yeild.length-1;i++){
g.setColor(Color.blue);
g.drawLine(50+i*30, 400-(int)(yeild[i]*gh), 50+(i+1)*30, 400-(int)(yeild[i+1]*gh));
g.setColor(Color.green);
g.drawLine(50+i*30, 400-(int)(pi[i]*gh), 50+(i+1)*30, 400-(int)(pi[i+1]*gh));
g.setColor(Color.black);
g.drawLine(50+i*30, 400-(int)(I[i]*gh), 50+(i+1)*30, 400-(int)(I[i+1]*gh));
}
}
}
public void Getdata(){
r=Double.parseDouble(Graph1.jTextField.getText());
bo=Double.parseDouble(Graph1.jTextField1.getText());
beta=Double.parseDouble(Graph1.jTextField2.getText());
sample=Integer.parseInt(Graph1.jTextField3.getText());
rep=Integer.parseInt(Graph1.jTextField4.getText());
prob=Double.parseDouble(Graph1.jTextField5.getText());
oi=Double.parseDouble(Graph1.jTextField7.getText());
ui=Double.parseDouble(Graph1.jTextField8.getText());
wi=Double.parseDouble(Graph1.jTextField9.getText());
io=Double.parseDouble(Graph1.jTextField10.getText());

22
yeild=new double[15];
I=new double[15];
pi=new double[15];
}
private JTextField getJTextField7() {
if (jTextField7 == null) {
jTextField7 = new JTextField();
jTextField7.setBounds(new Rectangle(168, 46, 68, 21));
jTextField7.setText("0.2");
}
return jTextField7;
}
private JTextField getJTextField8() {
if (jTextField8 == null) {
jTextField8 = new JTextField();
jTextField8.setBounds(new Rectangle(249, 47, 66, 18));
jTextField8.setText("0.00");
}
return jTextField8;
}
private JTextField getJTextField9() {
if (jTextField9 == null) {
jTextField9 = new JTextField();
jTextField9.setBounds(new Rectangle(474, 44, 53, 21));
jTextField9.setText("0.5");
}
return jTextField9;
}
private JTextField getJTextField10() {
if (jTextField10 == null) {

23
jTextField10 = new JTextField();
jTextField10.setBounds(new Rectangle(636, 12, 79, 26));
jTextField10.setText("0.05");
}
return jTextField10;
}
} // @jve:decl-index=0:visual-constraint="8,6"
\\

・Simu1  クラス

package policy;
public class Simu1 {
//---------------経済変数---------------------
public static int sita; //可視期間
public static double ganma; //資本分配率
public static double pa; //期待物価成長率
public int sample;//遺伝子集団の数
public int rep;
public double prob;//突然変異の確率
public int untrans; //突然変異しない数
public Gene[] keep;//次期に残す遺伝子の配列
Gene[] gen=null;//遺伝子の入った配列
public static double[] y; //GDP ギャップ
//---------コンストラクタ-----------------------
public Simu1(){
//変数の初期化(メモリを確保
sample=Graph1.sample;
prob=Graph1.prob;
keep =new Gene[sample];
gen =new Gene[sample];

24
untrans=sample-(int)(sample*prob);
y=new double[Graph1.yeild.length];
//変数へ初期値を代入
}
// ------------全体の制御------------------------
public Gene[] Optimal(){
for(int i=0;i<keep.length;i++){
for(int j=0;j<y.length;j++){
double temp=keep[i].I[j];
gen[i].I[j]=temp;
temp=keep[i].It[j];
gen[i].It[j]=temp;
}
}
Serection(); //淘汰
hybrid(); //交叉
variation(); //突然変異
variation2();
for(int s=0;s<gen.length-1;s++){
for(int t=s+1;t<gen.length;t++){
if(keep[s].Adaptation() < keep[t].Adaptation()){
Gene temp= keep[t];
keep[t]=keep[s];
keep[s]=temp;
}
}
}
// System.out.println(keep[0].adapt+","+keep[4].adapt+","+keep[sample-1].adapt);
return keep;
}

25
// ----------------初期集団の作成---------------------
public void Init(){
for(int i=0;i<sample;i++){ //sample 個の初期集団を配列に入れる
Gene z =new Gene(); //オブジェクト遺伝子生成
z.makeform();
z.zoom();
for(int j=0; j<y.length;j++){
}
gen[i]=z; //作成した遺伝子を配列に保存
}
for(int i=0;i<sample;i++){ //sample 個の初期集団を配列に入れる
Gene v =new Gene(); //オブジェクト遺伝子生成
v.makeform();
v.zoom();
keep[i]=v; //作成した遺伝子を配列に保存
}
// --------ソート--------------
for(int s=0;s<gen.length-1;s++){
for(int t=s+1;t<gen.length;t++){
if(gen[s].Adaptation() < gen[t].Adaptation()){
Gene temp= gen[t];
gen[t]=gen[s];
gen[s]=temp;
}
}
}
// --------ソート--------------
for(int s=0;s<gen.length-1;s++){
for(int t=s+1;t<gen.length;t++){

26
if(keep[s].Adaptation() < keep[t].Adaptation()){
Gene temp= keep[t];
keep[t]=keep[s];
keep[s]=temp;
}
}
}
}
// ---------------淘汰--------------------------------
private void Serection(){
//残り sample3/4 個からランダムで sample/4 選択し、次世代に残す (ルーレット選
択)
for(int i=(sample/10);i<(sample/5);i++){
int q = (int)(Math.random()*sample/4);
keep[i]=keep[(sample/2)+q];
}

}
// --------------交配 (2 点交叉)-----------------------------
private void hybrid(){
Gene t=new Gene();
for(int i=sample/5;i<sample*2/3;i=i+2){ //2/3-1/5 交配する
int rand = (int)(Math.random()*sample/4); //交配する遺伝子 1(上位 1/4 のみ)

int rand2= (int)(Math.random()*sample); //交配する遺伝子 2(全体)


int rand3= (int)(Math.random()*y.length); //交配する場所 1
int rand4= (int)(Math.random()*y.length); //交配する場所 2
for(int j=0;j<rand3;j++){ //最初から rand3 まで交叉
t.It[j]=gen[rand].It[j];
gen[rand].It[j] =gen[rand2].It[j];

27
gen[rand2].It[j]=t.It[j];
}
for(int j=rand4;j<y.length;j++){ //rand4 から最後まで交叉
t.It[j]=gen[rand].It[j];
gen[rand].It[j] =gen[rand2].It[j];
gen[rand2].It[j]=t.It[j];
}
gen[rand].zoom();
gen[rand2].zoom();

keep[i]=gen[rand];
keep[i+1]=gen[rand2];

}
}
// ---------------一部突然変異-------------------------------
private void variation(){
int rand= (int)(Math.random()*sample/4); //突然変異する遺伝子(上位 1/4 の
み)
int rand2= (int)(Math.random()*y.length); //突然変異する場所
double rand3= Math.random(); //突然変異する値

for(int i=sample*2/3;i<sample*3/4;i++){
gen[rand].It[rand2]=rand3;
gen[rand].zoom();
keep[i]=gen[rand];
}
}
// --------------完全突然変異------------------------
private void variation2(){

28
for(int i=untrans;i<sample;i++){
Gene l =new Gene(); //オブジェクト遺伝子生成
l.makeform();
l.zoom();
keep[i]=l; //作成した遺伝子を配列に保存
}
}
}
\\

・Gene クラス

package policy;
class Gene {
//--------フィールド-------------
public double[] I; //利子率
public double kakudai; //拡大率
public double[] It=null; //遺伝子
public static double[] y; //GDP ギャップ
public static double[] pi; //インフレ率
public static double tpi; //インフレ目標
public static double[] c; //期待消費
public static double[] rc; //実際の消費額
public double adapt; //適応度
private double beta;
private double alpha;
private double sigma;
private double A;
private double B;
private double C;
private double D;

29
//--------コンストラクタ----------------
public Gene(){
y=new double[Graph1.yeild.length];
pi=new double[Graph1.yeild.length];
I=new double[Graph1.yeild.length];
It=new double[I.length];
beta=0.99;
alpha=0.1;
sigma=1.5;
A=(alpha+beta)/beta;
B=sigma/beta;
C=alpha/beta;
D=1/beta;
y[0]=Graph1.bo;
pi[0]=Graph1.beta;
tpi=Graph1.r;
I[0]=Graph1.io;
}
//---------メソッド---------------------------
public double Adaptation(){
for(int i=0;i<y.length-1;i++){
y[i+1]=A*y[i]-B*pi[i]+sigma*I[i];
pi[i+1]=C*y[i]+D*pi[i];
}
double vy=0;
double vpi=0;
for(int i=0;i<y.length;i++){
vy=Math.abs(y[i])+vy;
vpi=Math.abs((tpi-pi[i]))+vpi;
}

30
adapt=0; //初期化
for(int i=0;i<I.length-1;i++){
adapt=(1-Graph1.wi)*vy+Graph1.wi*vpi;
//adapt=vy+vpi;
}
adapt=-adapt;
return adapt;
}
//----------------遺伝子----------------------------
public void makeform(){
for(int i=0;i<Graph1.yeild.length-1;i++){
It[i]=Math.random();
}
}
public void zoom(){
for(int i=0;i<Graph1.yeild.length;i++){
I[i]=It[i]*(Graph1.oi-Graph1.ui);
//I[i]=It[i]-Graph1.ui;
}
}
}

31
1
2
3
4
5
6
7
8
9
10
12345678901234567890123456789012345678
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10

32
1
2
3
4
5
6
7
8
9
10

33

You might also like