Created
September 20, 2016 09:49
-
-
Save LewisGet/ab5d7efad1509b23dde34013c8bce54e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fact = array(10, -1); | |
$taringData = array(); | |
for ($i = 0; $i < 50000; $i++) | |
{ | |
$x = rand(1, 10); | |
$y = rand(1, 100); | |
$source = ($x * $fact[0] + $y * $fact[1]) > 0 ? 1 : -1; | |
$taringData[] = (object) array('data' => array($x, $y), 'return' => $source); | |
} | |
$weight = array(0, 0); | |
$update = 0; | |
t: | |
foreach ($taringData as $historyData) | |
{ | |
$historySource = $historyData->return; | |
$historyTest = $historyData->data; | |
$getSource = 0; | |
// 測試 | |
foreach ($historyTest as $testId => $test) { | |
$getSource += $weight[$testId] * $test; | |
} | |
$getSource = $getSource > 0 ? 1 : -1; | |
// 答錯 | |
if ($getSource != $historySource) | |
{ | |
// 修正 | |
foreach ($historyTest as $testId => $test) { | |
$weight[$testId] = $weight[$testId] + $test * $historySource; | |
} | |
$update++; | |
// 重新考試 | |
goto t; | |
} | |
} | |
print_r($update); | |
print_r($weight); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
預到了個問題,如果我只有知道 x 跟 y ,接著用一條線畫分他們。
我算出的值,可能會是實質的值得倍率。