new things

This commit is contained in:
Dan Chadwick
2024-04-14 21:54:51 -07:00
parent 4eb7bf6220
commit 6ad2ed7b29
5 changed files with 39 additions and 16 deletions

View File

@@ -184,23 +184,47 @@ class FightTrainingController extends ControllerBase {
* This needs to be between 0-1
*/
private function normalizeData(array $data): array {
// @todo - this creates an issue where duration of fight is the largest number which isnt really correct
// and smaller duration would be better
//
$min = min(array_values($data));
$max = max(array_values($data));
$normalized = [];
foreach ($data as $key => $value) {
$norm_val = 0;
if ($max - $min == 0) {
$normalized[$key] = $norm_val;
}
else {
$norm_val = ($value - $min) / ($max - $min);
$normalized[$key] = $norm_val;
}
$value = (float) $value;
$normalized[$key] = $this->convertToDecimal($value);
/* $norm_val = 0; */
/* if ($max - $min == 0) { */
/* $normalized[$key] = $norm_val; */
/* } */
/* else { */
/* $norm_val = ($value - $min) / ($max - $min); */
/* $normalized[$key] = $norm_val; */
/* } */
}
return $normalized;
}
public function convertToDecimal(float $input) {
$output = 0;
if ($input > 0 && $input <= 1) {
$output = $input / 100;
}
elseif ($input > 1 && $input < 10) {
$output = $input / 100;
}
elseif ($input > 10 && $input < 100) {
$output = $input / 1000;
}
elseif ($input > 100 && $input < 1000) {
$output = $input / 10000;
}
return $output;
}
/**
* Gets the trained neural network.
*/