ほぼファイナル VfuncとEqSys
Vfuncもほぼ実装終了
- 方程式func(x,p)=0の求解、関数y=func(x,p)の極点(func'(x,p)=0)探索、残差平方和関数の極点探索(すなわち最小二乗法)の為に、各々に対する方程式系(EqSys)の具象モデルを実装している。(EqSysの実装例にもなる)
VFunc:パラメータ付きベクトル関数のモデル
/*[class] Vfunc 5/20/2008 by Classiclll求解、求極点、パラメタ推定が出来るパラメータ付きのベクトル関数 F : R^n・R^m -> R の抽象モデル
利用するには、VFuncから継承して、抽象メソッド
valueAt(x, p) :ベクトルxにおける関数の値を評価する
gradAt(x, p):ベクトルxによる関数のグラディエントを評価する(pは所与)
gradParamAt(x, p):ベクトルpによる関数のグラディエントを評価する(xは所与)
の実装が必要。
陽にグラディエントを評価できない(=微分不可能な)関数の場合、
gradAt(x, p):diffAt(x,d,p) を返す
diffAt(x, p, d):必要なら、オーバーライドして、[{F(xi+di:p)-F(xi:p)}/di]を評価する
gradParamAt(x, p):diffParamAt(x, d, p)を返す
diffParamAt(x, d, p):必要なら、オーバーライドして、[{F(xi+di:p)-F(xi:p)}/di]を評価する
ように実装する。
*現在のところは、
func(x;p)=0 のニュートン法/シンプレックス法による求解
func(x;p) のシンプレックス法による極点探索
残差平方和 ssr(obs,samples)のシンプレックス法によるパラメータ極点探索(最小二乗法)
のみ
抽象クラス
abstract class Vfunc { Vfunc(int domX, int domP) // construct & setup the internal implemented EqSys's int domDim() {return domX;} // dimension of the domain (n) int paramDim() {return domP;}// dimension of the params (m) Vec diffAt(Vec x, Vec d, Vec p)// gradient estimator at x+d using valueAt() Vec diffParamAt(Vec x, Vec d, Vec p)//param grad estimator at p+d using valueAt() abstract double valueAt(Vec x, Vec p)//this parameterized function (R^n,R^m -> R) abstract Vec gradAt(Vec x, Vec p)//this gradient arround x, given p abstract Vec gradParamAt(Vec x, Vec p)//this gradient arround p, given x // for solving the equation of this function. private thisEqSys self private class thisEqSys extends EqSys Vec solveByNewton(Vec x0, Vec p) //find the solution by newton, start at x0 Vec solveBySimplex(Vec x0, Vec p, int lim) //find the solution by Simplex, start at x0 // for finding of the extreme point of this function private gradEqSys grad private class gradEqSys extends EqSys Vec findeExtremeBySimplex(Vec x0, Vec p) //find one extreme point, start at x0 //least sqare equation system, gradient by params private paramEqSys gradParam private class paramEqSys extends EqSys double ssr(Vec p, Vec obs, Mat samples) //calcurate the Square Sum of Residuals at "p". Vec residual(Vec p, Vec obs, Mat samples) //calculate the each residual at "p" Vec ssrGradAt(Vec p, Vec obs, Mat samples) //gradient of ssr based gradParamAt() Vec bestParams(Vec p, Vec obs, Mat samples) //estimate the params by Least Square Sum. }【6月8日更新】
EqSys:方程式系のモデル
/*[class] EqSys 5/20/2008 by Classiclll多価関数 func:R^n -> R^m で構成される方程式系 F(x) = 0 の抽象モデル
利用するには、EqSysから継承して、抽象メソッド
valueAt(x) :ベクトルxにおける関数の値を評価する
jacobAt(x) :ベクトルxにおける関数のグラディエント(Jacobian)を評価する
の実装が必要。
陽にグラディエント(Jacobian)を評価できない(=微分不可能な)関数の場合、
jacobAt(x): diffAt(x, d)を返す。
diffAt(i, x, d):必要なら、オーバーライドして、[{Fi(x+d)-Fi(x)}/dj]を定義する
ように実装する。
(現在のところ実装予定の求解法はニュートン法,Simplex法のみ)
抽象クラス
abstract class EqSys { EqSys(int dom, int rng) // construct and setup this Equation System int domDim() // dimension of the domain (n) int rngDim() // dimension of the range (m) abstract Vec valueAt(Vec x) // value of the equation (R^n -> R^m) system. abstract Mat jacobAt(Vec x) // gradient Jacobian of the EqSys. // if not continuouse, you can return diffAt(x,d) Vec diffAt(Vec x, Vec d) // overwride if needed Vec solveByNewton(Vec x0) // find the solution by the newton, start at x0 Vec solveBySimplex(Vec x0, int lim)// find the solution by the simplex, start at x0 }【6月8日】EqSys更新