Algorithm Optimisation Championship. - page 50

 
Andrey Dik:

I seem to have time to show examples today.

We all ask dumb questions (each in our own time) from the perspective of those who know more about the issue. No problem).

Testing test examples, pardon the tautology).

 

An example of a very simple FF, 2 parameters.

You can already test your algorithms on this simple function.

#property library
#property strict

int  countRuns    = 0;

//+------------------------------------------------------------------+
int GetParamCountFF () export
{ 
  return (2);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
double FF (double &array []) export
{ 
  countRuns++;

  int sizeArray = ArraySize (array); 
  if(sizeArray != 2) 
    return (-DBL_MAX); 
  return (-(pow (2.4 + array [0], 2.0) + pow (array [1] - 2.3, 2.0))+3.1415926);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
int GetCountRunsFF () export
{ 
  return (countRuns);
}
//+------------------------------------------------------------------+

Maximum value you can get:3.1415926

Orient yourself to 1000 runs, no more than that.

The championship will be FF with 500 parameters, not more than 1000 runs, the FF will accept parameters in the range from -10.0 to 10.0 with increments of 0.1, above the range the parameters will be cut off to these limits (in the example above there is no cutting off). Dear participants, keep this in mind.

 

Test script on the first version of the algorithm:

#property script_show_inputs
#property strict

//+------------------------------------------------------------------+
// алгоритм оптимизации участника
#import "\\Projects\\OAC\\lib\\ao_v1.ex5"
// инициализация АО
void   InitAO (int paramCount, int maxFFruns); 
// функции алгоритма перед началом оптимизации
void   ServiceFunc1 (); 
// функции алгоритма на каждой "эпохе" (итерации) вначале
void   ServiceFunc2 (); 
// функции алгоритма на каждой "эпохе" (итерации) вконце
void   ServiceFunc3 (); 
// запрос количества пакетной обрабобки (аналог колонии ГА)
int    GetReplaysCount (); 
// получение параметров  
void   GetOptParam (double &param []); 
// отправить в алгоритм значение ФФ соответствующее параметрам 
void   SendFFvolue (double volue); 
// этой функцией алгоритм по может остановить оптимизацию
bool   StopAlgo (); 
// получить максимальное значение ФФ       
double GetMaxFF (); 
#import
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
// тестовая фитнес функция чемпионата, не известна участникам
#import "\\Projects\\OAC\\lib\\ff.ex5"
// запросить количество параметров ФФ 
int    GetParamCountFF (); 
// запуск ФФ, получеие значения соответствующее параметроам ФФ
double FF (double &array []); 
// произведённое количество запусков ФФ
int    GetCountRunsFF (); 
#import
//+------------------------------------------------------------------+

//--- input parameters
input int MaxFFruns_P = 1000; 


//+------------------------------------------------------------------+
void OnStart () 
{ 
  // узнаем, сколько параметров нужно оптимизировать
  int paramCount = GetParamCountFF (); 
  
  bool   stopAlgo = false; 
  int    ffRuns = 0; 
  double param []; 
  ArrayResize (param, paramCount); 
  
  ulong  startTime = GetMicrosecondCount (); 
  
  //------------------------------------------------------------------
  InitAO (paramCount, MaxFFruns_P);
  ServiceFunc1 (); 
  while(!stopAlgo) 
  {
    if(StopAlgo ()) 
      break; 
    
    ServiceFunc2 (); 
    
    for(int i = 0; i < GetReplaysCount (); i++) 
    {
      GetOptParam (param); 
      SendFFvolue (FF (param)); 
      ffRuns++; 
      if(ffRuns == MaxFFruns_P) 
      {
        stopAlgo = true; 
        break;
      }
    }
    
    ServiceFunc3 (); 
    
    if(StopAlgo () || stopAlgo) 
      break;
  }
  //-------------------------------------------------------------------
  
  startTime = GetMicrosecondCount () - startTime; 
  
  Print ("Макс: " + DoubleToString (GetMaxFF (), 8)); 
  Print ("Запусков ФФ: " + (string)GetCountRunsFF ()); 
  Print ("Время: " + (string)startTime + " мкс; " + DoubleToString ((double)startTime/1000000.0, 8) + " c"); 
  Print ("---------------------------------");
}
//+------------------------------------------------------------------+
 

The test script gives me these numbers right now:

2016.06.21 22:36:15.214 OAC variant 1 (GBPUSD,H1) ---------------------------------

2016.06.21 22:36:15.214 OAC variant 1 (GBPUSD,H1) Time: 1119 µs; 0.00111900 c

2016.06.21 22:36:15.214 OAC variant 1 (GBPUSD,H1) FF Runs: 1000

2016.06.21 22:36:15.213 OAC variant 1 (GBPUSD,H1) Max: 3.14159260

I conclude: nothing to complain about so far, everything works correctly.

 

You have to assume that optimization is a tool to investigate a particular filter (the idea it implements), not a search for a global extremum. Otherwise you are fighting on the field, where you are middling compared to even the phd and resources of even an ordinary investment company. Although no one has cancelled software masturbation))

 

ОПТИМИЗАЦИЯ(optimization) Выбор из всех возможных вариантов использования ресурсов тех

whichgivethe bestresults.It isoftendescribedinterms ofmaximisingthe targetfunction.

 
Avals:

You have to assume that optimization is a tool to investigate a particular filter (the idea it implements), not a search for a global extremum. Otherwise you are fighting on the field, where you are middling compared to even the phd and resources of even an ordinary investment company. Although no one has cancelled the software masturbation))

Exactly - a tool. Earlier in the thread it was demonstrated on the example of finding the roots of the equation how you can use the optimization algorithm. You can use it for filters, indicators, neural networks, or anything else.

Some people masturbate, and some work, and some masturbate while working. To each his own. We have a free country.)))

 

Test scriptfor the second version of the algorithm:

#property script_show_inputs
#property strict

//+------------------------------------------------------------------+
// алгоритм оптимизации участника
#import "\\Projects\\OAC\\lib\\ao_v2.ex5"
// инициализация АО
void   InitAO (int paramCount, int maxFFruns); 
void   StartAlgo (); 
// получить максимальное значение ФФ       
double GetMaxFF (); 
#import
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
// тестовая фитнес функция чемпионата, не известна участникам
#import "\\Projects\\OAC\\lib\\ff.ex5"
// запросить количество параметров ФФ 
int    GetParamCountFF (); 
// запуск ФФ, получеие значения соответствующее параметроам ФФ
double FF (double &array []); 
// произведённое количество запусков ФФ
int    GetCountRunsFF (); 
#import
//+------------------------------------------------------------------+

//--- input parameters
input int MaxFFruns_P = 1000; 


//+------------------------------------------------------------------+
void OnStart () 
{ 
  // узнаем, сколько параметров нужно оптимизировать
  int    paramCount = GetParamCountFF (); 

  ulong  startTime = GetMicrosecondCount (); 
  
  //------------------------------------------------------------------
  InitAO (paramCount, MaxFFruns_P);
  StartAlgo ();
  //------------------------------------------------------------------
  
  startTime = GetMicrosecondCount () - startTime; 
  
  Print ("Макс: " + DoubleToString (GetMaxFF (), 8)); 
  Print ("Запусков ФФ: " + (string)GetCountRunsFF ()); 
  Print ("Время: " + (string)startTime + " мкс; " + DoubleToString ((double)startTime / 1000000.0, 8) + " c"); 
  Print ("---------------------------------");
}
//+------------------------------------------------------------------+
 

Checked my algorithm for the second way of starting as well - the results are similar to the first one. That is, I personally don't care how to call the FF, from inside or outside the algorithm - it works the same way.

Please note: these two test scripts will be used in the championship for participants, as they are now. Only the function of saving the optimised parameters to a file will be added, for control, maybe there will be some minor changes, which will be reflected before the championship, for sure.

 
Now I'll add examples of the algorithms themselves for both types of FF calls, on the very, native and beloved HFC. Please love and love them, especially for beginners. They are easy to understand, an example of how you can build an elementary simple and at the same time working optimization algorithm.