function test(NeuralNetwork $neuralNetwork, $withError = true) { $accuracy = []; $errors = []; foreach ($this->allTestData as $testData) { $result = $neuralNetwork->calculate($testData->getData()); $resultBool = 0; if ($result[0] < 0 && $result[1] > 0 && $testData->getExpectedResult() == [-1, 1]) { $resultBool = 1; } if ($result[0] > 0 && $result[1] < 0 && $testData->getExpectedResult() == [1, -1]) { $resultBool = 1; } $accuracy[] = $resultBool; $errors[] = $neuralNetwork->getError($result, $testData->getExpectedResult()); } echo '<div>Skuteczność <b>' . avg($accuracy) . '</b></div>'; echo '<div>Błąd <b>' . avg($errors) . '</b></div>'; // echo '<pre>'.print_r($neuralNetwork->toArray(), true).'</pre>'; ?> <div class="graphs"> <?php if ($withError) { ?> <div class="graphError" data-data="<?php echo htmlspecialchars(json_encode($neuralNetwork->getHistoricErrors())); ?> "></div> <?php } ?> <div class="graphNetwork" data-data="<?php echo htmlspecialchars(json_encode($neuralNetwork->toArray()), ENT_QUOTES, 'UTF-8'); ?> "></div> </div> <script>draw()</script> <?php flush(); ob_flush(); }
function test(NeuralNetwork $neuralNetwork) { $trainingDatas = prepareTrainingDatas(); foreach (NUMBERS as $number) { ?> <div class="displays"><?php ?> <div class="display"><?php foreach ($number as $v) { ?> <div class="display-pixel" style="opacity: <?php echo ($v + 1) / 2; ?> "></div><?php } ?> </div><?php ?> <div class="display"><?php foreach ($neuralNetwork->calculate($number) as $v) { ?> <div class="display-pixel" style="opacity: <?php echo ($v + 1) / 2; ?> "></div><?php } ?> </div><?php ?> </div><?php } ?> <div class="graphs"> <div class="graphNetwork" data-data="<?php echo htmlspecialchars(json_encode($neuralNetwork->toArray()), ENT_QUOTES, 'UTF-8'); ?> "></div> </div> <script>draw()</script> <?php }
function test(NeuralNetwork $neuralNetwork) { $correctResult = []; for ($x = MIN; $x <= MAX; $x += STEP) { for ($y = MIN; $y <= MAX; $y += STEP) { $result = func($x, $y); if (is_infinite($result)) { continue; } $correctResult[] = [$x, $y, func($x, $y)]; } } $networkResult = []; for ($x = MIN; $x <= MAX; $x += STEP) { for ($y = MIN; $y <= MAX; $y += STEP) { $networkResult[] = [$x, $y, $neuralNetwork->calculate([$x, $y])[0]]; } } // echo '<pre>'.print_r($neuralNetwork->toArray(), true).'</pre>'; ?> <div class="graphs"> <div class="graph3d" data-data="<?php echo json_encode($correctResult); ?> "></div> <div class="graph3d" data-data="<?php echo json_encode($networkResult); ?> "></div> <div class="graphNetwork" data-data="<?php echo htmlspecialchars(json_encode($neuralNetwork->toArray()), ENT_QUOTES, 'UTF-8'); ?> "></div> </div> <script>draw()</script> <?php flush(); ob_flush(); }