Dakotaに含まれる関数(rosenblock/textbook etc.)ではなく、自前で多目的関数を実装して、実際に最適化してみる。pyhtonを使用。
問題は、図示しやすいのを適当にネットから探してきて、設計変数2(x1,x2)+目的関数2(f1,f2)の下記の問題としてみた。pythonスクリプトは、単純に2つの設計変数をコマンドライン引数として、2つの関数値を返すもので、これをドライブするシェルスクリプト(のテンプレート)も必要。
minimize: f1=2*sqrt(x1), f2=x1-x1*x2+5
subject to 1<=x1<=4, 1<=x2<=2
<objective.py>・・・入力値の範囲チェックいれてません!
#!/bin/python
from sys import argv
from math import *
import numpy as np
def f1(x1, x2):
return 2.0*sqrt(x1)
def f2(x1, x2):
return x1-x1*x2+5.0
if __name__ == '__main__':
x1 = float(argv[1])
x2 = float(argv[2])
print f1(x1,x2), f2(x1,x2)
<run.sh.templete>
#!/bin/sh
python objective.py {x1} {x2}※ {x1}{x2}はdakotaによって具体的な値に置き換えられる。
設計空間評価(パラメータスタディ)
最適化(パレート解を求める)ではなく、単に設計変数空間での目的関数を求めたい場合
dakota inputファイル(dakota.in)
# Dakota Input File: dakota.in
# Usage:
# dakota -i dakota.in -o dakota.out > dakota.stdout
environment
graphics
tabular_graphics_data
tabular_graphics_file = 'objective.dat'
method
multidim_parameter_study
partitions = 8 8
model
single
variables
continuous_design = 2
lower_bounds 1.0 1.0
upper_bounds 4.0 2.0
descriptors 'x1' "x2"
interface
fork
analysis_driver = 'simulator_script'
parameters_file = 'params.in'
results_file = 'results.out'
work_directory directory_tag
copy_files = 'templatedir/*'
named 'workdir' file_save directory_save
aprepro
responses
response_functions = 2
no_gradients
no_hessians
dakota simulator_scriptファイル
#!/bin/sh
# Sample simulator to Dakota system call script
# See Advanced Simulation Code Interfaces chapter in Users Manual
# $1 is params.in FROM Dakota
# $2 is results.out returned to Dakota
# --------------
# PRE-PROCESSING
# --------------
# Incorporate the parameters from DAKOTA into the template, writing ros.in
# Use the following line if SNL's APREPRO utility is used instead of DPrePro.
# ../aprepro -c '*' -q --nowarning ros.template ros.in
dprepro $1 run.sh.template run.sh
# --------
# ANALYSIS
# --------
sh run.sh
# ---------------
# POST-PROCESSING
# ---------------
# In this example, "results.out" is directry outputted from "run.sh"
掃除用スクリプトファイル
#!/bin/sh
rm dakota.rst > /dev/null 2>&1
rm -r workdir.* > /dev/null 2>&1
rm *.out *.dat > /dev/null 2>&1
フォルダツリー
$ tree -F --charset SJIS
.
|-- dakota.in
|-- dakota_cleanup*
|-- dprepro*
|-- simulator_script*
`-- templatedir/
|-- objective.py
`-- run.sh.template
1 directory, 6 files
※ deprepro は、dakota/binフォルダからコピーしておく。dpreproは、テンプレート中の{x1}{x2}などを置き換える役目を果たす。
実行結果
※ f1, f2の組み合わせで、非凸のパレートフロントが得られている。
methodの変更(パラメータスタディ)
上の例では、設計変数空間をコンスタントに区切り、全ての場合について目的関数を評価した(method multidim_parameter_study)。この他、以下のmethodがある。sub keywordも併記する。
vector_parameter_study
final_point
step_vector
num_steps※ variablesセクションで、initial_point の指定も必要
※ final_pointを指定した場合は、initial_pointからfinal_pointまで,
num_stepsだけ直線的に分割して設計変数生成・目的関数評価が行われる。
※ step_vectorを指定した場合は、num_stepsの回数、step_vector分だけ移動して設計変数生成・目的関数評価が行われる。
list_parameter_study
list_of_points
import_points_file
annotated(or freeform)※ 設計変数のリストを直接指定して実施。 import_points_fileでファイルを指定しても可。その時は、書式もannotated/freeformのどちらかを指定しておく。
centered_parameter_study
step_vector
steps_per_variable
※ inital_pointを中心として、step_vectorをsteps_per_variableの分だけ+-の方向に移動した点を評価点として生成する。step_vectorの成分を0にすれば、特定の設計変数ベクトル座標にのみ分布させることができる。
multidim_parameter_study
partitions