Classiclll's Blog

an old boy

妄想は続く、VFunc:パタメータ付きベクトル関数・方程式・パラメータ同定のモデル

妄想は続く、VFunc:パタメータ付きベクトル関数・方程式・パラメータ同定のモデル


これで大概の用は事足りるか?

VFunc:パラメータ付きベクトル関数・方程式・関数同定のモデル

 ベクトル関数 F : R^n・R^m -> R 、方程式 F(x:p)=0、および、パラメータ同定 の抽象モデル
 利用するには、VFuncから継承して、抽象メソッド
   valueAt(x, p) :ベクトルxにおける関数の値を評価する
   gradAt(x, p):ベクトルxにおける関数のグラディエントを評価する
 の実装が必要。(domへの正しい値の設定も忘れずに)
 陽にグラディエントを評価できない(=微分不可能な)関数の場合、
   gradAt(x, p):nullを返す
   diffAt(x, p, d):オーバーライドして、[{F(xi+di:p)-F(xi:p)}/di]を評価する
 ように実装する。
 (現在のところ実装予定の解法はニュートン法、推定法は最小二乗法のみ)

抽象クラス

abstract class Vfunc {
    private int dom=0;
    public thisEqSys grad;  	        	//equation system, gradient of this VFunc
    class thisEqSys extends EqSys {
        Vec valueAt(Vec x)          	       	//the equation system (R^n -> R^m)
        Mat nabraAt(Vec x)          	        //if not continuouse, return null
    }
    int domDim() {return dom;}         	//dimension of the domain (n)
    abstract double valueAt(Vec x, Vec p); //the equation system (R^n -> R)
    abstract Vec gradAt(Vec x, Vec p);
    double diffAt(Vec x, Vec d, Vec p) 	  // overwride if needed
    Vec solveByNewton(Vec x0, Vec p)         // find the solution by the newton, start at x0
    Vec paramsByLSQ(Vec obs, Mat sample ) 
      // estimate the parameters based on the set of obs and samples
      //   with the Least SQare criteria.
  }

ついでに、Matがあるんだから、

Vec(任意長の行ベクトルのモデル)も・・・

[class] Vec              5/23/2008 by Classiclll
 * 線形代数(ベクトル演算)のモデル
   添字の基数は0。すなわち
    elem(0)     : 左端のベクトル要素(double)
      elem(idx)   : 左端から(idx+1)番目の要素

Body

 [members]
  no public member.
 
 [constructors]
 Vec()					:construct empty
 Vec(int length)		:construct sized by length having all zero
 Vec(double v, int length)		:construct sized by rows*cols 
 Vec(double[] v)			:construct single raw having v[col] 
 Vec(Loc v)				:construct having(x,y,z)
 

[methods]

<group #0 - Matrix Operation - generator>
 Vec copy()				:return the copy of me.
 Vec add(Vec v)				:return me[i] + v[i]
 Vec add(double d)			:return me[i] + d (scalar)
 Vec sub(Vec v)				:return me[i] - v[i]
 Vec sub(double d)			:return me[i] - d (scalar)
 Vec mul(double d)			:return me[i] * d (scalar)
 Vec div(double d)			:return me[i] / d (scalar)
 Mat preMul(Vec v)			:return having trace [v[i] * me[i]]
 Vec setSub(Vec sub, int idx)		:ret[row+i][col+j] <= subMat[i][j] 
 Vec getSub(int start, int len)		:return me[sRow->eRow][sCol->eCol]
 Vec getSub(int[] sel)		:retturn {{.},..{me[sel]},..}
 
<group #2 - Scalar - information>
 int length()				:return the number of rows
 double dot(Vec v)			:return sum of me[i]*v[i]
 double elem(int idx)	:return the specified element
 double norm()			:return the square norm of me.
 double normInf()		:return the infinit(=maximum) norm of me.
 double dist()			:same as norm().
 double dist2()			:return square of norm().
 boolean equals(Object object)	:return shallow equoality between me and object 
 
 <group #3 - Utilities - generator>
 double[] toArray()		:return 2d array of me
 double[] arrayRef()		:retuen the reference to 2d array of "me"
 				  modification may cause some trouble.
 String toString()             	:get the string expression of me.
 
 <group #4 - High level operator>
 doble solvePoly(doubel b)
     : Returns the solution from x=0, for polynomial equation
            me[0]*x^n + ... + me[n-1] = b.
       when no solution, null reference will be returned.