public double[] ComputeMin(OptMultivariateFunction function, OptMultivariateGradient gradient, OptVariable[] variables, double tolerance, double factr, ref int nMax) { double[] minimum; this.Initialize(variables); if (this._NumFreeVariables == 0) return this._ExternalVariables; minimum = this.Compute(function, gradient, tolerance, factr, ref nMax); return minimum; }
public SFUN(OptMultivariateFunction function, OptMultivariateGradient gradient, OptVariable[] variables) { //this.MeNParameters = nParameters; this.MeFunction = function; this.MeGradient = gradient; this.MeOptVariable = variables; this.MeOptBoundVariable = null; this.MeExternalVariables = new double[variables.Length]; this.MeExternalGradientArray = new double[variables.Length]; this.MeExternalVariables = new double[variables.Length]; for (int i = 0; i < variables.Length; i++) { this.MeExternalVariables[i] = variables[i].InitialGuess; } }
private void UpdateInternalGradient(OptVariable[] variables) { int index = 0; for (int i = 0; i < variables.Length; i++) { if (variables[i].Fixed == false) { this._GradientArray[index] = this._ExternalGradientArray[i]; index++; } } }
private void UpdateExternalVariables(OptVariable[] variables) { int index = 0; for (int i = 0; i < variables.Length; i++) { if (variables[i].Fixed == false) { this._ExternalVariables[i] = this._FreeVariables[index]; index++; } } }
private void Initialize(OptVariable[] variables) { this._OptVariable = variables; this._OptBoundVariable = null; this._ExternalVariables = new double[variables.Length]; this._ExternalGradientArray = new double[variables.Length]; int numFreeVariable = 0; for (int i = 0; i < variables.Length; i++) { this._ExternalVariables[i] = variables[i].InitialGuess; if (variables[i].Fixed == false) numFreeVariable++; } this._NumFreeVariables = numFreeVariable; this._FreeVariables = new double[numFreeVariable]; int index = 0; for (int i = 0; i < variables.Length; i++) { if (variables[i].Fixed == false) { this._FreeVariables[index] = variables[i].InitialGuess; index++; } } this._LowerBounds = new double[numFreeVariable]; this._UpperBounds = new double[numFreeVariable]; this._NBD = new int[numFreeVariable]; //nbd(i)=0 if x(i) is unbounded, this._GradientArray = new double[numFreeVariable]; //c nmax is the dimension of the largest problem to be solved. //c mmax is the maximum number of limited memory corrections. int NMAX = this._NumFreeVariables; int MMAX = this.M; // c wa is a double precision working array of length // c (2mmax + 4)nmax + 12mmax^2 + 12mmax int WADimension = (2 * MMAX + 4) * NMAX + 12 * (MMAX * MMAX) + 12 * MMAX; this.WA = new double[WADimension]; this.IWA = new int[3 * NMAX]; }
private void Initialize(OptMultivariateFunction function, OptMultivariateGradient gradient, OptVariable[] variables) { this.internalFunction = new SFUN(function, gradient, variables); this.MeOptVariable = variables; this.MeOptBoundVariable = null; this.MeExternalVariables = new double[variables.Length]; int numFreeVariable = 0; for (int i = 0; i < variables.Length; i++) { this.MeExternalVariables[i] = variables[i].InitialGuess; if (variables[i].Fixed == false) numFreeVariable++; } this.MeF = function(this.MeExternalVariables); this.MeNumFreeVariables = numFreeVariable; this.MeFreeVariables = new double[numFreeVariable]; this.MeGradientArray = new double[numFreeVariable]; int index = 0; for (int i = 0; i < variables.Length; i++) { if (variables[i].Fixed == false) { this.MeFreeVariables[index] = variables[i].InitialGuess; index++; } } //W - (REAL*8)(REAL*8) WORK VECTOR OF LENGTH AT LEAST 14*N //LW - (INTEGER) THE DECLARED DIMENSION OF W this.MeLW = 14 * this.MeNumFreeVariables; this.MeW = new double[this.MeLW]; this.MeMAXIT = this.MeNumFreeVariables / 2; }
public double[] ComputeMin(OptMultivariateFunction function, OptMultivariateGradient gradient, OptVariable[] variables, double tolerance, double ACCRCY, ref int nMax) { if (this.MeLMQN == null) this.MeLMQN = new LMQN(); this.Initialize(function, gradient, variables); if (this.MeNumFreeVariables == 0) return this.MeExternalVariables; int IERROR = 0; this.MeLMQN.Run(ref IERROR, this.MeNumFreeVariables, ref this.MeFreeVariables, 0, ref this.MeF, ref this.MeGradientArray, 0, ref this.MeW, 0, this.MeLW, this.internalFunction, this.MeMSGLVL, this.MeMAXIT, nMax, this.MeETA, this.MeSTEPMX, ACCRCY, tolerance); int index = 0; for (int i = 0; i < variables.Length; i++) { if (variables[i].Fixed == false) { this.MeExternalVariables[i] = this.MeFreeVariables[index]; index++; } } nMax = this.internalFunction.FunEvaluations; return this.MeExternalVariables; }
private void UpdateInternalGradient(OptVariable[] variables, double[] G, int o_g) { int index = 0; for (int i = 0; i < variables.Length; i++) { if (variables[i].Fixed == false) { G[index + o_g] = this.MeExternalGradientArray[i]; index++; } } }
private void UpdateExternalVariables(OptVariable[] variables, double[] X, int o_x) { int index = 0; for (int i = 0; i < variables.Length; i++) { if (variables[i].Fixed == false) { this.MeExternalVariables[i] = X[index + o_x]; index++; } } }