Libraries: ALGLIB - Numerical Analysis Library - page 2

 

I am trying to use ALGLIB and have managed to simplify a code from TestInterfaces.mqh into the following script given below.

In this case the function is:

f(x0,x1)=100*(x0+3)^4 + (x1-3)^4 

How can I pass parameters (in this case A, B, C, D, E) to a function given by?:

f(x0,x1)=A*(x0+B)^D + (x1-C)^E 

The documentation says to use CObject &obj, but I don't know how.

//+------------------------------------------------------------------+
//| Including the libraries                                          |
//+------------------------------------------------------------------+
#include <Math\Alglib\alglib.mqh>
#include <Arrays\ArrayDouble.mqh>

class CNDimensional_Func1 : public CNDimensional_Func
  {
public:
                     CNDimensional_Func1(void);
                    ~CNDimensional_Func1(void);

   virtual void      Func(double &x[],double &func,CObject &obj);
  };
//+------------------------------------------------------------------+
//| Constructor without parameters                                   |
//+------------------------------------------------------------------+
CNDimensional_Func1::CNDimensional_Func1(void)
  {

  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CNDimensional_Func1::~CNDimensional_Func1(void)
  {

  }
//+------------------------------------------------------------------+
//| This callback calculates f(x0,x1)=100*(x0+3)^4 + (x1-3)^4        |
//+------------------------------------------------------------------+
void CNDimensional_Func1::Func(double &x[],double &func,CObject &obj)
  {
   func=100*MathPow(x[0]+3,4)+MathPow(x[1]-3,4);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   double              x[];
   double              temparray[];
   CObject             obj;

   CNDimensional_Func1 ffunc;
   CNDimensional_Rep   frep;

   CMinLBFGSStateShell state;
   CMinLBFGSReportShell rep;

   ArrayResize(x,2);
   //--- initialization
   x[0]=0;
   x[1]=0;
   double epsg = 1.0e-10;
   double epsf = 0;
   double epsx = 0;
   double diffstep = 1.0e-6;
   int maxits = 0;
   
   CAlglib::MinLBFGSCreateF(1,x,diffstep,state);

   CAlglib::MinLBFGSSetCond(state, epsg, epsf, epsx, maxits);

   CAlglib::MinLBFGSOptimize(state, ffunc, frep, 0, obj);

   CAlglib::MinLBFGSResults(state, x, rep);
   
   Print("x[0] = ", DoubleToString(x[0]));
   Print("x[1] = ", DoubleToString(x[1]));
   
  }

Any help is greatly appreciated

Fred

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
Fuzzy library is missing on this release... there is nothig about it (as far I can see... its supposed to be on a separete directory, behind Math)
Reason: