• 検索結果がありません。

最適化問題

N/A
N/A
Protected

Academic year: 2021

シェア "最適化問題"

Copied!
11
0
0

読み込み中.... (全文を見る)

全文

(1)

DirectSearch パッケージを用いた最適化問題

サイバネットシステム株式会社

背 景

Maple 本体には O p t i m i z a t i o n パッケージと S t a t i s t i c s パッケージが標準で提供さ れています。 O p t i m i z a t i o n パッケージの M i n i m i z e コマンドを用いて、二乗誤差式の最小値を 計算することで、フィッティングを行うことが可能です。 また、S t a t i s t i c s パッケージの N o n l i n e a r F i t コマンドは Michaelis-Menton モデ ル( ) 等へのフィッティングも即時に行うことができます。 さらに、Maple 言語を用いてユーザによるカスタマイズパッケージ D i r e c t S e a r c h も 開発されていて、Maplesoft 社の Application Center よりダウンロードの上でご利用いた だけます。 このパッケージは非線形フィッティングの問題を処理する機能が強力です。詳細につい ては、該当セクションで説明しています。 この資料では、モデルフィッティングを行うことを目的として、これらのパッケージ・ 機能について紹介します。

DirectSearch パッケージのセットアップ方法

D i r e c t S e a r c hパッケージを Maplesoft Application Center の以下のページからダウンロ ードします。

(2)

上記ページの [Toolkit]欄にある「Download attached file」をクリックして必要なファイル (DirectSearch2.zip)をダウンロードします。

Table 2: Download attached file をクリックして必要なファイルをダウンロード

ダウンロードした DirectSearch2.zip ファイルは適当なフォルダ(例:C:\temp 等)に保存 し、展開します。

展開したフォルダの "EnglishVersion" フォルダに格納されている以下の2つのファイル を Maple 本体のインストールフォルダ内にある「lib」フォルダへコピーします。

コピーするファイル:DirectSearch.mdb, DirectSearch.hdb コピーするフォルダ:C:\Program Files\Maple 15\lib

注:上記は Maple 本体を Windows 版の標準フォルダへインストールした場合です。適宜 インストールフォルダは確認下さい。 2つのファイルのコピーが完了したら Maple 本体を再起動し、ワークシート上で「? DirectSearch」とタイプするか、またはヘルプナビゲータを起動して「DirectSearch」と タイプし検索してください。DirectSearch パッケージのヘルプドキュメントが表示され れば、正しくインストールされています。 Table 3: DirectSearch パッケージのヘルプ画面 なお、展開したフォルダには、例題用のワークシート example.mw 及び D i r e c t S e a r c h パッケージで用いられている手法に関する参考論文の PDF が用意されています。必要 に応じて参照して下さい。 注:なお、D i r e c t S e a r c h パッケージは Maplesoft の公認ではなく、あくまでユーザ によって開発されたパッケージです。ご利用にあたってはユーザ様独自の判断に基 づいてご利用下さい。本パッケージのご利用法にあたっての技術サポートは当社ではお

(3)

> > > > > > (3) (3) > > (1) (1) > > (2) (2) 受け出来ませんのであらかじめご了承下さい。

Michaelis-Menton モデルへのフィッティング

r e s t a r t ; 下記のような floating タイプの測定データが取得されているとして、それらのデータを Michaelis-Menton モデル式へフィッティングを行います。 まず、測定データを外部から Maple に取り込みます。 このデータは 46 x 2 の行列データです。 d a t a : = I m p o r t M a t r i x ( " b i o m e d d a t a . c s v " , d e l i m i t e r = " , " ) ; 上記 data の 1 列目を取り出して、変数 S に割り当てておきます。 S : = d a t a [ 1 . . - 1 , 1 ] ; data の 2 列目を取り出して、変数 V に割り当てておきます。 V : = d a t a [ 1 . . - 1 , 2 ] ; データのプロットを描画し、確認します。 p l o t ( S , V , s t y l e = p o i n t , s y m b o l = s o l i d c i r c l e , s y m b o l s i z e = 1 0 , l a b e l s = [ s , v ] ) ;

(4)

> > > > (4) (4) s 2 4 6 8 10 12 14 16 v 1 2 次に、上記 data を Michaelis-Menton モデル へフィッティングを行うことを 考えます。 ここで、Maple の O p t i m i z a t i o n パッケージによる方法と S t a t i s t i c s パッケージ による方法をそれぞれ紹介します。 まず、モデル式を定義します。 f : = s - > a * s / ( b + s ) ;

1 . O p t i m i z a t i o n パッケージによる方法

最初に、二乗誤差式 SS を作成します。 最小二乗法により、誤差式の f(x) の引数 x に S のデータ、y に V のデータをそれぞれ 代入し、計算結果の総和を求めます。 S S : = a d d ( ( f ( S [ k ] ) - V [ k ] ) ^ 2 , k = 1 . . 4 6 ) : SS の計算でパラメータ a、b で構成されている式が得られ、以下のプロットにより二 乗誤差の最小値を確認してみます。最小値はこの曲面の底部に存在していること がわかりますが、非常に狭い領域にあることもわかります。

(5)

> > > > > > (6) (6) > > (5) (5) > > p l o t 3 d ( S S , a = 0 . . 5 , b = 0 . . 8 , a x e s = b o x e d , s t y l e = p a t c h c o n t o u r , v i e w = [ d e f a u l t , d e f a u l t , 0 . . 1 0 ] ) ; O p t i m i z a t i o n パッケージの M i n i m i z e コマンドを用いて、二乗誤差 SS の最小 値およびそのときのパラメータ a、b を計算してみます。 w i t h ( O p t i m i z a t i o n ) : M i n i m i z e ( S S ) ; ここで得られた最小値は、実は正確ではありません。さらなる改良 は、O p t i m i z a t i o n パッケージの N L P S o l v e コマンドを用いることで得られま す。 二乗誤差式 SS に NLPSolve コマンドを適用させて、再度、最小誤差およびパラメー タ a、b の値を計算してみます。 なお、ここでは、非線形シンプレックス法を指定しており、許容誤差を 0.1e-14 に設 定しています。 N L P S o l v e ( S S , m e t h o d =n o n l i n e a r s i m p l e x, e v a l u a t i o n l i m i t = 2 0 0 , o p t i m a l i t y t o l e r a n c e = 0 . 1 e - 1 4 ) ;

2 . S t a t i s t i c s パッケージによる方法

w i t h ( S t a t i s t i c s ) :

(6)

> > (7) (7) > > S t a t i s t i c s パッケージの N o n l i n e a r F i t コマンドにより、非線形フィッティン グを行います。 これにより、フィッティング後のモデル式が即時に得られます。 N o n l i n e a r F i t ( f ( s ) , S , V , s ) ;

D i r e c t S e a r c h カスタマイズパッケージによるフィッ

ティング

概 要

Maple は数式処理のソフトウェアではありますが、数値数式処理のみならず、ユーザ 独自の関数・パッケージを開発する環境も提供しております。 この最適化パッケージは、Maple の数式処理機能を用いて、Maple 言語により開発さ れた(サードパーティの)カスタマイズパッケージです。 Maple 本体に実装されている O p t i m i z a t i o n パッケージの NLPSolve コマンドは、 Nelder- Mead による逐次シンプレックス法をサポートしております。

一方、D i r e c t S e a r c h パッケージには derivative-free direct search(微分情報を 用いない直接探索) 法をサポートしております。この方法は微分不可能な関数や不 連続な関数の場合でも、最適化問題を解決することができます。 さらに、多目的最適化問題には、7つほどのコマンドが用意されております。 また、複素方程式モデルや連立方程式モデルによる最適化問題に対処するためのコ マンド S o l v e E q u a t i o n s も開発されております。 ポイントデータにフィッティングするためには D a t a F i t コマンドが用意されてお り、このコマンドでは、9つのフィッティング方法をサポートしております。 その9つのフィッティング方法は、下記表にまとめてあります。 method オプシ ョ ン 手法の概要 目的関数

lms Least mean squares method. This method is effective but not robust to outliers.

lad Least absolute deviations method. This method is more robust to outliers than LMS method.

lts Least trimmed squares method. Robustness of this method depends on upper percentile

value p ( by default). where TrimmedMean is trimmed mean lws Least Winsorized squares

method. Robustness of this method depends on upper

(7)

(9) (9) > > > > (8) (8) > > default).

minimax Minimax method. This method is very sensitive to outliers. median Least median squares method.

This method is most robust to

outliers. where is sample median quantile Least quantile squares method.

Robustness of this method depends on quantile order p (

by default).

where is sample quantile of order p

trimean Trimean method. This method is robust to outliers.

where is sample median and quantile of order p

lfad Least function of absolute deviations method. Robustness of this method depends on the function specified (by default,

). Table 1 D i r e c t S e a r c h パッケージの D a t a F i t コマンドで利用可能な手法とそ の概要 以下は、 D i r e c t S e a r c h パッケージを用いたアプリケーション事例となります。

事 例1

事例 1 では、上記「Michaelis-Menton モデルへのフィッティング」セクションで用い られたデータおよび Michaelis-Menton モデル を使い、D i r e c t S e a r c h パッケージの D a t a F i t コマンドでフィッティングします。 D i r e c t S e a r c h パッケージに最小二乗法が実装されており、ここで、最小二乗法を 指定してフィッティングを行います。 そのためには、f i t m e t h o d オプションに l m s を指定しています。 w i t h ( D i r e c t S e a r c h ) ; D a t a F i t ( f ( s ) , S , V , s , f i t m e t h o d = l m s ) ; 上記結果の1つ目の値 0.0352734480736973 は、Table1 の 1 行目 l m s アルゴリズムの

(8)

> > (12) (12) (11) (11) > > (13) (13) > > > > > > > > (10) (10) 関数 で計算された最小値です。 この関数 F(a) は、セクション1 で使われた SS の関数と比較して、係数 1/k がある 違いにご注意ください。 この事例の場合は、k が 46 になっているので、下記処理で O p t i m i z a t i o n パッケー ジによる計算と同様の結果を確認することができます。 (9)[1] は式(9) の1番目の要素を取り出すことになります。その要素は値 4 6 *(9)[ 1 ] ; 1.62257861139008

事 例2

ここでは、次の3つの式からなる連立方程式系の解を求める問題を考えます。 r e s t a r t ; 各 g[i] は以下の非線型な連立方程式で表されるとします: g [ 1 ] : = s q r t ( a ^ 2 + ( 1 - b ) ^ 2 ) * ( a r c s i n ( ( b e t a - a ) / s q r t ( a ^ 2 + ( 1 - b ) ^ 2 ) ) + a r c s i n ( a / s q r t ( a ^ 2 + ( 1 - b ) ^ 2 ) ) ) - 3 / 2 = 0 ; g [ 2 ] : = b e t a ^ 4 - b e t a ^ 2 * b + b e t a ^ 2 - 2 * b e t a * a - 2 * a * b e t a ^ 3 + 2 * a * b e t a * b - b e t a ^ 3 + b e t a * b - 1 + 2 * b - b ^ 2 = 0 ; g [ 3 ] : = ( b e t a - a ) ^ 2 + ( b e t a ^ 2 - b ) ^ 2 - a ^ 2 - ( 1 - b ) ^ 2 = 0 ; ただし、 はいずれも非負であるとします。 上記 3つの連立方程式を f s o l v e コマンドにより、適当な初期値を与えて数値解 を求めてみます。 f s o l v e ( { g [ 1 ] , g [ 2 ] , g [ 3 ] } , { a = 0 . 3 , b = 2 , b e t a = 1 . 2 } ) ; しかし、2番目以降の解は fsolve では見つけ出すことが出来ません。ここ で、f s o l v e の a v o i d オプションは以前に見つかった解以外の解を求めるためのオ プションです。 f s o l v e ( { g [ 1 ] , g [ 2 ] , g [ 3 ] } , { a = 0 . 3 , b = 2 , b e t a = 1 . 2 } , a v o i d = (12)) ;

(9)

> > (14) (14) (13) (13) > > > > (15) (15) > > > > > > > > 異なる初期値を与えても、やはり2番目以降の解は見つけられません。 f s o l v e ( { g [ 1 ] , g [ 2 ] , g [ 3 ] } , { a = 0 . 7 , b = 1 . 2 , b e t a = 2 . 2 } , a v o i d = (12)) ; そこで、より詳しく解の存在をグラフで確認するために、下記の処理を行います。 1.g[2] は変数 a に関して1次であることから、g[2]式を変数 {b, } で表せるよう式を 変形します。 i s o l a t e ( g [ 2 ] , a ) ; 2.(15)式を g[1] に代入します。 g 2 : = e v a l ( g [ 1 ] ,(15)) : 同様に、g[3] にも代入します。 g 3 : = e v a l ( g [ 3 ] ,(15)) : 3.上記処理により、変数 b と のみの2つの方程式 {g2, g3} が用意できました。 そこで、陰関数描画の i m p l i c i t p l o t コマンドを用いて、2つの方程式のグラフを 描画し、交点を確認してみます。 w i t h ( p l o t s ) : i m p l i c i t p l o t ( [ g 2 , g 3 ] , b = 0 . . 5 , b e t a = 0 . . 2 , c o l o r = [ b l u e , r e d ] , g r i d r e f i n e = 5 ,c r o s s i n g r e f i n e = 2) ;

(10)

> > (16) (16) (13) (13) (17) (17) > > > > > > b 0 1 2 3 4 5 b ここで、(12) の結果を改めて確認してみます: (12); すなわち、f s o l v e による (12) の値は、グラフ中の真ん中に位置している交点のみを 探しだしていることがわかります。 一方、D i r e c t S e a r c h パッケージの S o l v e E q u a t i o n s コマンドを用いて、この系 の解を計算してみます。 w i t h ( D i r e c t S e a r c h ) : M : = S o l v e E q u a t i o n s ( [ g [ 1 ] , g [ 2 ] , g [ 3 ] ] , A l l S o l u t i o n s , e v a l u a t i o n l i m i t = 1 0 0 0 0 0 ) ; S o l v e E q u a t i o n s コマンドは の残差式の極小値を計算し、戻り値として m 行列データの 各行は求まった極値及び関連するデータが格納されています。各列 は、1列目:残差 R、2列目:各式の残差(ここでは g[i], i=1..3の残差)、3列目:

(11)

(18) (18) (13) (13) > > (19) (19) > > (20) (20) > > > > 求まったパラメータ値、4列目:反復回数、の各データが格納されています。 今回の例において、3行目までの結果は以下のようになっています: M [ 1 , 1 . . - 1 ] ; M [ 2 , 1 . . - 1 ] ; M [ 3 , 1 . . - 1 ] ; デフォルトで、ここでの極値計算は絶対許容誤差が であり、3行目以降の極値 は になっているため、誤差の有意性から判断して実際の結果は1行目と 2行目のみになります。 微分不可能な関数モデルや連立方程式系モデル、複素方程式モデルによる最適化問 題の場合は、カスタマイズされた D i r e c t S e a r c h パッケージを利用することで最適 値を求められる可能性があります。 D i r e c t S e a r c h パッケージには、本資料で紹介した D a t a F i t , S o l v e E q u a t i o n s コマンド以外にも、いくつかの最適化手法が用意されていますので、最適化問題に 対する別のアプローチを利用することが可能です。

Table 1: http://www.maplesoft.com/applications/view.aspx?SID=101333
Table 2: Download attached file をクリックして必要なファイルをダウンロード

参照

関連したドキュメント

It was shown in [ALM] that the parameter space of general analytic families of unimodal maps (with negative Schwarzian derivative) can be related to the parameter space of

Finally, we give an example to show how the generalized zeta function can be applied to graphs to distinguish non-isomorphic graphs with the same Ihara-Selberg zeta

As with subword order, the M¨obius function for compositions is given by a signed sum over normal embeddings, although here the sign of a normal embedding depends on the

Recently, Velin [44, 45], employing the fibering method, proved the existence of multiple positive solutions for a class of (p, q)-gradient elliptic systems including systems

By using the Fourier transform, Green’s function and the weighted energy method, the authors in [24, 25] showed the global stability of critical traveling waves, which depends on

Furthermore, we also consider the viscosity shrinking projection method for finding a common element of the set of solutions of the generalized equilibrium problem and the set of

A mathematical formulation of well-posed initial boundary value problems for viscous incompressible fluid flow-through-bounded domain is described for the case where the values

To derive a weak formulation of (1.1)–(1.8), we first assume that the functions v, p, θ and c are a classical solution of our problem. 33]) and substitute the Neumann boundary