For a neural network, you need to bring the values ​​to a scale from 0 to 1

$arr = [-7, 1, 99, -7.3, -6]; //в реальном десятки тысяч элементов 

It is necessary to build a curve along it, something like this: curve
and find the point on the scale by value. In our case, for -4 should be 0.6

  • AND? Do you have a question with normalization? - Vladimir Martyanov
  • Yes, I wanted this formula (y = (ymax-ymin) * (x-xmin) / (xmax-xmin) + ymin), but the non-uniform distribution is obtained. - flax
  • And why mix x in the y-coordinate? I would increase all the values ​​by the number dy, so that the minimum of the dialing numbers becomes zero, then I would divide everything by the maximum ... - Vladimir Martyanov
  • This approach is of course more beautiful in the range from 0 to 1, but in essence the same view from the side ideone.com/fO3Jez - flax

1 answer 1

 $arr = [-7, 1, 99, -7.3, -6]; //Находим максимальное и минимальное значения в массиве $min = min($arr); $max = max($arr); //Создаем новый массив, где максимальное значение будет соответствовать единице, //а минимальное нулю $new_arr = array_map(function($y){ $y = ($y - $min)/($max - $min); }, $arr); 

an approximate course of further decisions:

  1. look for the average value (this will be the peak of our graph): $average = array_sum($new_arr)/count($new_arr);
  2. we compile a table of probabilities of one or another value, depending on the deviation from the average with the invented step, and save to the array:
  3. We do the inverse transformation to our original data.
  4. We build the schedule.
  • The same as here ( ideone.com/fO3Jez ), only inflated. Not evenly distributed from 0 to 1. - flax
  • I do not understand what is meant by the word "uniform"? Need to sort an array so that you get a graph of a uniform distribution of magnitude? Then this is a purely mathematical problem and is solved by mathematical methods. php has nothing to do with it. - Razzwan