function learn(NeuronSigmoidal $neuron, array $trainingDatas) { /* @var $trainingDatas TrainingData[] */ test($neuron); $i = 0; while (true) { $errors = []; foreach ($trainingDatas as $trainingData) { $result = $neuron->calculate($trainingData->getData()); $error = $neuron->getError($result, $trainingData->getExpectedResult()); $errors[] = abs($error); $neuron->correctWeights($result, $trainingData->getExpectedResult()); } // echo avg($errors).'<br>'; if (avg($errors) < 0.05) { break; } // if ($i % 10 == 0) // test($neuron); $i++; if ($i == 100) { break; } } // echo '<pre>'.print_r($neuron->getWeights(), true).'</pre>'; // echo '<pre>'.print_r($neuron->getBetaWeight(), true).'</pre>'; echo avg($errors) . '<br>'; echo $i . '<br>'; }
function hideMovingObjects($imageFiles) { $xMax = 0; $yMax = 0; $images = array(); foreach ($imageFiles as $fn) { $images[] = imagecreatefromjpeg($fn); $info = getimagesize($fn); $infoX = $info[0]; $infoY = $info[1]; $infoBits = $info['bits']; $infoChannels = $info['channels']; $xMax = max($xMax, $infoX); $yMax = max($yMax, $infoY); } $colorGd = imagecreatetruecolor($xMax, $yMax); $imagesnumber = sizeof($images); $trimRounds = ceil(log($imagesnumber) * log($imagesnumber) / 2); $trimStop = $imagesnumber - $trimRounds - $trimRounds; //for all images and all pixel //calculate the Trimmed mean of color for ($x = 0; $x < $xMax; $x++) { for ($y = 0; $y < $yMax; $y++) { $colorR = array(); $colorG = array(); $colorB = array(); foreach ($images as $img) { $colorRgb = imagecolorat($img, $x, $y); $colorR[] = RGB::getRed($colorRgb); $colorG[] = RGB::getGreen($colorRgb); $colorB[] = RGB::getBlue($colorRgb); } sort($colorR); sort($colorG); sort($colorB); $colorRed = avg(array_slice($colorR, $trimRounds, $trimStop)); $colorGreen = avg(array_slice($colorG, $trimRounds, $trimStop)); $colorBlue = avg(array_slice($colorB, $trimRounds, $trimStop)); imagesetpixel($colorGd, $x, $y, RGB::colorSet($colorRed, $colorGreen, $colorBlue)); } } //done return the merged image! //imagepng($colorGd, "last.jpg" ); return $colorGd; }
/* Upload */ $i = 0; do { $uploadNow = $datas['upload'][count($datas['upload']) - 1 - $i]->value; $i++; } while ($uploadNow == null); $uploadNow = avg(array_reverse(array_slice($datas['upload'], -12 - $i, 12))); $uploadLast = avg(array_reverse(array_splice($datas['upload'], 0, 12))); /* Download */ $i = 0; do { $downloadNow = $datas['download'][count($datas['download']) - 1 - $i]->value; $i++; } while ($downloadNow == null); $downloadNow = avg(array_reverse(array_slice($datas['download'], -12 - $i, 12))); $downloadLast = avg(array_splice($datas['download'], 0, 12)); if ($ping && $uploadLast && $uploadNow && $downloadNow && $downloadLast) { $insertStat->execute(); } echo $service . " : {$ping} : {$uploadNow} : {$uploadLast} : {$downloadNow} : {$downloadLast}<br/>"; /* Détection des erreurs */ $errors = array(); /* Ping */ if ($ping > $config['pingDanger']) { $errors[] = '<span class="text-danger">Ping ' . round($ping, 2) . '</span>'; } elseif ($ping > $config['pingWarn']) { $errors[] = '<span class="text-warning">Ping ' . round($ping, 2) . '</span>'; } /* Upload */ if (!$uploadNow) { $uploadPercent = 100;
function learn(NeuralNetwork $neuralNetwork, array $trainingDatas) { /* @var $trainingDatas TrainingData[] */ test($neuralNetwork); $historicErrors = []; $i = 0; while (true) { $errors = []; /*?> <table style=""><tr> <th>dane</th> <th>wynik</th> <th>spodziewany</th> <th>błąd</th> </tr><?php*/ foreach ($trainingDatas as $trainingData) { /*?><tr><?php*/ $result = $neuralNetwork->calculate($trainingData->getData()); $error = $neuralNetwork->getError($result, $trainingData->getExpectedResult()); $errors[] = $error; /*?><td><?php foreach($trainingData->getData() as $v) { echo round($v, 2).' '; } ?></td><?php ?><td><?= round($result[0], 2) ?></td><?php ?><td><?= round($trainingData->getExpectedResult()[0], 2) ?></td><?php ?><td><?= round($error, 2) ?></td><?php ?><td><?php*/ $neuralNetwork->correctWeights($result, $trainingData->getExpectedResult()); /*?></td><?php ?></tr><?php*/ } // if ($i % 5000 == 0) { // test($neuralNetwork); // } /*?></table><?php*/ // test($neuralNetwork); // echo '<div style="width: '.(avg($errors) * 1000).'px; height: 1px; background: #666;"></div>'; // echo '<b>'.round(avg($errors), 3).'</b><br>'; if (avg($errors) < 0.01) { return; } $i++; if ($i > 1) { $lastHistoricErrors = array_slice($historicErrors, -50); if (avg($lastHistoricErrors) > avg($historicErrors)) { $historicErrors = []; $i = 0; test($neuralNetwork); $neuralNetwork->rerandomizeWeights(); //test($neuralNetwork); } } $historicErrors[] = avg($errors); if ($i == 100000) { echo 'break'; break; } shuffle($trainingDatas); } }
} fclose($file_count); @(list($today, $yesterday, $total, $date, $days) = split("%", $data)); echo ceil($total / $days); } ?> Đang online: <?php echo online(); ?> <br> Truy cập hôm nay: <?php echo today(); ?> <br> Truy cập hôm qua: <?php echo yesterday(); ?> <br> Tổng số truy cập: <?php total(); ?> <br> Truy cập trung bình: <?php avg(); ?> <br> </td> </tr> </table>
$sum += $r; } // echo "min=".$min."*"; return $sum -= $min; } function sev($n) { $sum = 0; $min = 20; for ($i = 0; $i < $n; $i++) { $t = roll(4); if ($min > $t) { $min = $t; } $sum += $t; } return ($sum - $min) / ($n - 1); } function avg($n) { $sum = 0; for ($i = 0; $i < $n; $i++) { $sum += sev(7); } echo $sum / $n . "<br />"; } avg(1000); ?> </html>
function learn(NeuralNetwork $neuralNetwork, array $trainingDatas) { /* @var $trainingDatas TrainingData[] */ test($neuralNetwork); $historicErrors = []; $i = 0; while (true) { $errors = []; /*?> <table style="left: <?= $i * 400 ?>px; top: 0px; position: absolute; display: none;"><tr> <th>dane</th> <th>wynik</th> <th>spodziewany</th> <th>błąd</th> <th>poprawa</th> </tr><?php*/ foreach ($trainingDatas as $trainingData) { /*?><tr><?php*/ $result = $neuralNetwork->calculate($trainingData->getData()); $error = $neuralNetwork->getError($result, $trainingData->getExpectedResult()); $errors[] = $error; /*?><td><?= round($trainingData->getData()[0], 2) ?></td><?php ?><td><?= round($result[0], 2) ?></td><?php ?><td><?= round($trainingData->getExpectedResult()[0], 2) ?></td><?php ?><td><?= round($error, 2) ?></td><?php*/ /*?><td><?php*/ $neuralNetwork->correctWeights($result, $trainingData->getExpectedResult()); /*?></td><?php ?></tr><?php*/ if ($i % 100 == 0) { // test($neuralNetwork); } } /*?></table><?php*/ echo '<div style="width: ' . avg($errors) * 1000 . 'px; height: 1px; background: #666;"></div>'; //echo '<b>'.round(avg($errors), 3).'</b><br>'; if (avg($errors) < 0.05) { return; } $i++; if ($i > 1) { $lastHistoricErrors = array_slice($historicErrors, -50); if (avg($lastHistoricErrors) > avg($historicErrors)) { $historicErrors = []; $i = 0; test($neuralNetwork); $neuralNetwork->rerandomizeWeights(); test($neuralNetwork); } } $historicErrors[] = avg($errors); if ($i == 5000) { break; } shuffle($trainingDatas); } }
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(); }
$table["classes (ignored)"] = count($classes); $table["Objects"] = $resourceobjects; $table["Triples"] = $triples; $table["Triples_with_Object_ratio"] = pretty($resourceobjects, $triples); $table["unique_subjects"] = count($uniquesubjects); $table["subsAreObjects"] = count($subsAreObjects); $table["subsAreObjectsRatio"] = pretty(count($subsAreObjects), count($uniquesubjects)); $table["avg_indegree_subjects"] = avg($subsAreObjects); $table["avg_outdegree_subjects"] = avg($uniquesubjects); $table["unique_predicates"] = count($uniquepredicates); $table["avg_usage_predicates"] = avg($uniquepredicates); $table["unique_objects"] = count($uniqueobjects); $table["objsAreSubjects"] = count($objsAreSubjects); $table["objsAreSubjectsRatio"] = pretty(count($objsAreSubjects), count($uniqueobjects)); $table["avg_indegree_objects"] = avg($uniqueobjects); $table["avg_outdegree_objects"] = avg($objsAreSubjects); p($table); if ($detailed) { echo "classes\n"; detailed($classes); echo "predicates\n"; detailed($uniquepredicates); } } //foreach function detailed($arr) { foreach ($arr as $key => $value) { echo "{$key}\t{$value}\n"; } echo "\n\n";
} } ?> <form method="post" action="#"> <p><input type="submit" name="save" value="GUARDAR CAMBIOS"></p> <table> <tr> <th>Alumno</th> <th>1ªev</th> <th>2ªev</th> <th>3ªev</th> <th>Final</th> <th>x</th> </tr> <?php // var_dump($_SESSION["alumnos"]); for ($i = 0; $i < count($_SESSION["alumnos"]); $i++) { $_SESSION["alumnos"][$i]["nom"]; $alumno = $_SESSION["alumnos"][$i]; echo "<tr>"; echo "<td><input type='text'class='nom' name='name-" . $i . "' value='" . $alumno["nom"] . "'/></td>"; echo "<td class='nota'><input type='number' name='ev1-" . $i . "' value='" . $alumno["ev1"] . "'/></td>"; echo "<td class='nota'><input type='number' name='ev2-" . $i . "' value='" . $alumno["ev2"] . "'/></td>"; echo "<td class='nota'><input type='number' name='ev3-" . $i . "' value='" . $alumno["ev3"] . "'/></td>"; echo "<td class='nota'>" . avg($alumno) . "</td>"; echo "<td style='width:1px'><input type='submit' name='del-" . $i . "' class='submit-img img-del' value=''/></td>"; echo "</tr>"; } ?> </table> </form>