Optimisation of algorithms. - page 3

 
joo:

The width of the sectors cannot match the values in the array, otherwise the algorithm will not work for all numbers.

What matters is the distance the numbers are apart. The further apart all the numbers are from the first, the less likely they are to fall out. In essence we postpone on a straight line bars proportional to the distance between the numbers, adjusted by a factor of 0.01, so that the last number the probability of falling out was not equal to 0 as the farthest from the first. The higher the coefficient, the more equal the sectors are. The excel file is attached, experiment with it.

1. The calculation of theoretical probabilities is given in the excel. The first number is the highest probability, the last number is the lowest probability but not equal to 0.

2) Negative sizes of sectors never happens for any set of numbers, provided that the set is sorted in descending order - the first number is the biggest (it will work with the biggest in the set but negative number).

I do not understand, but I already like your approach to probability theory, expressed in a key phrase: "It is important the distance at which the numbers are in between. The further apart all the numbers are from the first, the less likely they are to fall out..." and take two (check shot): "Are you suggesting to just pick an element of the array at random? - It doesn't take into account distances between array numbers, so your way is useless". Legitimate question: Is brain washing a compulsory exercise in honing program writing logic? I'd better stay a dilettante coder, it's better for my health.

And if you're good with probability theory, then the logic of roulette - a random number generator in the range from 0 to 36 (if roulette is conventional, European, without the American-style double zero, etc...).

 
Wangelys:

I don't get it, but I already like your approach to probability theory, expressed in the key phrase: "The distance between the numbers matters. The further all the numbers are from the first, the less likely they are to fall out..." and take two (check shot): "You propose to just select an element of the array at random? - It doesn't take into account distances between array numbers, so your way is useless". Legitimate question: Is brain washing a compulsory exercise in honing program writing logic? I'd better stay a dilettante coder, it's better for my health.

And if you're good with probability theory, the logic of roulette - a random number generator in a range from 0 to 36 (if regular European roulette, without the American-style double zero, etc. ...).

Actually, casino roulette is nothing more than a metaphor, which at least three people in this thread have already fallen for.

 
joo:

Actually, casino roulette is nothing more than a metaphor that at least three people in this thread have already fallen for.

- Yeah, yeah, I get it! Aesop language!

- I'm sorry, where's that from?

 
Wangelys:

- Yes, yes, I got it! Aesop language!

- I'm sorry, I didn't catch that, where was it from?

Robert Sheckley?
 
joo:

The width of the sectors cannot match the values in the array, otherwise the algorithm will not work for all numbers.

What matters is the distance the numbers are apart. The further apart all the numbers are from the first, the less likely they are to fall out. In essence we postpone on a straight line bars proportional to the distance between the numbers, adjusted by a factor of 0.01, so that the last number the probability of falling out was not equal to 0 as the farthest from the first. The higher the coefficient, the more equal the sectors are. The excel file is attached, experiment with it.

1. The calculation of theoretical probabilities is given in the excel. The first number is the highest probability, the last number is the lowest probability but not equal to 0.

2) Negative sector sizes never happen for any set of numbers, as long as the set is sorted in descending order - the first number is the biggest (will also work with the biggest in the set but a negative number).

This is not a correct statement IMHO.

имеем массив
 double a[10]={1,2,3,4,5,6,7,8,9,10};
какова вероятность выпадения каждого?
 55=1+2+3+4+5+6+7+8+9+10;
 double b[10]={1/55,2/55,3/55,4/55,5/55,6/55,7/55,8/55,9/55,10/55};
те вероятность выпадения [0] в 10 раз меньше чем [9].
теперь разметим массив где эти вероятности будут отображены
 double с[10]={1,3,6,10,15,21,28,36,45,55};
теперь при выпадении чисел от 1 до 55, если ранд55 <= c[x], то имеем нужный индекс.
для того чтоб работало и для отрицательных чисел нужно сдвинуть значения на 1-с[0].

теперь посмотрим изменяться ли вероятности при изменении чисел...
 double a[10]={2,4,6,8,10,12,14,16,18,20};
какова вероятность выпадения каждого?
 110=2+4+6+8+10+12+14+16+18+20;
 2/110==1/55
 double b[10]={1/55,2/55,3/55,4/55,5/55,6/55,7/55,8/55,9/55,10/55};
те вероятность выпадения [0] в 10 раз меньше чем [9], 
вероятность выпадения не изменилась, 
т.к. она измеряется относительно среднего рассчитанного по всему массиву.

 

Second, the calculation of the probability array with[] is needed once per epoch, so we should split the function into RoletteEpoh() and RoletteRand().

Although Joo mentioned it in the beginning.

but you can get the speedup itself just by searching for the dropped value in c[] array.

You can use the standard biblio, namely the quick search methods.

And you'd better take its reworked methods from the article Spreadsheets in MQL5

If you want to make a quick search for sorted arrays with non-decreasing values, use the standard one with ascending values (I may be wrong, it's been a while since I tumbled into standard one).

 
joo:
Robert Shackley?
No, a little simpler - Privoz in Odessa, though I love Shackley (almost spelled shekels) too. But your following metaphor "got" all participants in this branch:
joo:
I suggest we discuss here the problems of optimal algorithm logic construction
-because what's going on here hardly falls under the wording of the problem of "optimal construction of algorithm logic" - it's more like improvement of coding methods and techniques... or am I wrong?
 
Wangelys:
Problems of "optimal construction of algorithm logic" - it's more like improvement of coding methods and techniques... or am I wrong?

A thread of a general nature:

"If anyone doubts that their algorithm has optimal logic in terms of speed (or clarity), they are welcome."

And specifically my task was "...please suggest a faster variant...". Faster! I'm not asking whether my algorithm is right or wrong, in this case I just need faster, that is, if someone suggests another variant of the algorithm, it should produce the same result as mine and no other. And for some reason everyone started thinking about his own thing.


OK, my task of speeding up has been solved. :)

 
Wangelys:

- Yes, yes, I got it! Aesop language!

- I'm sorry, I didn't catch that, where was it from?

It's from genetic algorithms.
Генетические алгоритмы - это просто!
Генетические алгоритмы - это просто!
  • 2010.05.25
  • Andrey Dik
  • www.mql5.com
В статье автор расскажет об эволюционных вычислениях с использованием генетического алгоритма собственной реализации. Будет показано на примерах функционирование алгоритма, даны практические рекомендации по его использованию.
 
Now I have a problem. I need to make effective sorting of arrays with big "cost" of elements copying (i.e. elements of which are bulky, "heavy" structures, class objects, long strings, etc.). Common sense suggests that we should leave them in place, but sort instead by some kind of pointers - indexes of cells of their original location. Here is a quote from here :https://www.mql5.com/ru/forum/6476#comment_178318
Если прямо тут перевести в подобие "техзадания", то нужна функция, на вход берущая массив и возвращающая 
второй массив (int), элементы которого являются индексами элементов входного массива, расположенными 
по убыванию (возрастанию).

В идеальном случае сделать перегрузки для всех стандартных типов + CObject (при обязательном требовании
к реализации функции Compare() у наследников CObject).  Хотелось бы и для структур, но похоже на стороне
разработчика никак не решаемо - виртуальных функций у структур нет (и не надо!), т.е. юзерскую функцию
Compare() не пришить, а "стандартное" отношение порядка для структур, естественно, не определено.  
Let's leave the respected terminal developers with their numerous current tasks for now, and implement it on mql5.