function main() { $ret = new TomoeReturn(); //返回客户端的信息 $type = isset($_POST['type']) ? $_POST['type'] : null; //$type = TYPE_RECOGNIZE; //debug if (!isset($type)) { $ret->msgno = MSG_ERR; //提示没有输入 $ret->msg = MSG_ERR_NOINPUT; } else { switch ($type) { case TYPE_RECOGNIZE: //识别 $writing = isset($_POST['c']) ? json_decode($_POST['c']) : null; //获取客户端传过来的笔画 $rank = isset($_POST['rank']) ? $_POST['rank'] : 100; //$rank = 10; //debug //$writing = debug_getInput(); //debug recognize($ret, $writing, $rank); break; case TYPE_GET_CHARS: //获取汉字(用于学习) $trainType = isset($_POST['trainType']) ? $_POST['trainType'] : null; $char = isset($_POST['c']) ? $_POST['c'] : null; $unicodeFrom = isset($_POST['unicodeFrom']) ? $_POST['unicodeFrom'] : null; $unicodeTo = isset($_POST['unicodeTo']) ? $_POST['unicodeTo'] : null; get_chars($ret, $trainType, $char, $unicodeFrom, $unicodeTo); break; case TYPE_LEARN: //学习 $writing = isset($_POST['c']) ? json_decode($_POST['c']) : null; //获取客户端传过来的笔画 $id = isset($_POST['id']) ? $_POST['id'] : null; $user_id = isset($_POST['user_id']) ? $_POST['user_id'] : null; //$id = 1; //debug; //$writing = debug_getInput();//debug; learn($ret, $writing, $id, $user_id); //debug_train($writing, $ret); break; case TYPE_GET_WRITINGS: //获取笔迹(用于管理) $char = isset($_POST['c']) ? $_POST['c'] : null; getWritings($ret, $char); break; case TYPE_DEL_WRITING: //删除某笔画 //delWriting($writing, $ret); break; case TYPE_UNKNOWN: //未知请求 //未知请求 default: $ret->msgno = MSG_ERR; $ret->msg = MSG_ERR_UNKNOWN_REQUEST; break; } } echo json_encode($ret); }
function start() { $neuralNetwork = new NeuralNetwork(12, [25, 12]); $trainingDatas = prepareTrainingDatas(); learn($neuralNetwork, $trainingDatas); test($neuralNetwork); //echo $neuralNetwork->calculate([1]); //echo '<pre>'.print_r($neuralNetwork, true).'</pre>'; }
function start() { $neuron = new NeuronHebb(12); $trainingDatas = [new TrainingData([-1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1], -1), new TrainingData([1, -1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1], 1)]; learn($neuron, $trainingDatas); echo $neuron->calculate([-1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1]) . '<br>'; echo $neuron->calculate([1, -1, 1, 1, 1, 1, 1, -1 - 1, 1, -1, -1, 1]) . '<br>'; echo $neuron->calculate([1, 1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1]) . '<br>'; }
function start() { $neuron = new NeuronSigmoidal(2); $trainingDatas = prepareTrainingDatas(); learn($neuron, $trainingDatas); test($neuron); //echo $neuralNetwork->calculate([1]); //echo '<pre>'.print_r($neuralNetwork, true).'</pre>'; }
<?php require '../lib/libsql.php'; require '../lib/libbayes.php'; $text = $_REQUEST['text']; $spam = $_REQUEST['spam']; learn($text, $spam);
/** * Parses startup.xml * * Loads the startup.xml in the botloading process. * XML parses the startup.xml file. * * @todo Seperate the XML reading from the processing code. Perhaps making a seperate class for this. * * @see botloader.php * @see botloaderinc.php * @uses learn() * @uses startS() * @uses endS() * @uses handlemeS() * * @global string the rootdirectory * @global array Files to be learned * @global array All the different bots in the startup.xml file * @global integer ID of the selected bot * @global boolean ???? * * @return void prints HTML */ function loadstartup() { global $rootdir, $learnfiles, $allbots, $selectbot, $areinc; $areinc = 1; print "<font size='3'>Loading startup.xml<br /></font>\n"; $learnfiles = array(); // This array will hold the files to LEARN $file = $rootdir . "startup.xml"; $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($xml_parser, "startS", "endS"); xml_set_character_data_handler($xml_parser, "handlemeS"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); # For each of the bots learn all of the files foreach ($allbots as $bot) { print "<font size='3' color='BLUE'><b>Loaded bot: {$bot}<br /></b></font>\n"; $single_learnfiles = $learnfiles[$bot]; $single_learnfiles = array_unique($single_learnfiles); foreach ($single_learnfiles as $file) { $selectbot = $bot; learn($file); } } }
function learn($letters, Perceptron $perceptron) { $learnFor = 11; $iterations = 100; display($perceptron->weights); for ($i = 0; $i <= $iterations; $i++) { foreach ($letters as $letterNumber => $fonts) { $isCorrect = $letterNumber == $learnFor; foreach ($fonts as $letter) { //if ($i % 250 == 0) // display($letter, '#999'); $perceptronResponse = $perceptron->calculate($letter); if ($perceptronResponse == $isCorrect) { //if ($i % 250 == 0) // display($perceptron->weights, 'green'); continue; } //if ($i % 250 == 0) //display($perceptron->weights, 'red'); $perceptron->correctWeights($letter, (int) $isCorrect, (int) $perceptronResponse); } } //if ($i % 250 == 0) // display($perceptron->weights); } display($perceptron->weights); } learn($letters, $perceptron); foreach ($lettersTest as $letterTest) { display($letterTest[0], $perceptron->calculate($letterTest[0]) ? 'green' : '#666'); }
<?php set_time_limit(86400); require '../lib/libsql.php'; require '../lib/libbayes.php'; $files = glob('data/bbc/*/*.txt'); foreach ($files as $file) { echo "{$file}: "; $text = file_get_contents($file); if (!$text) { continue; } learn($text, 0); } $files = glob('data/spam_out*.txt'); foreach ($files as $file) { echo "{$file}: "; $text = file_get_contents($file); if (!$text) { continue; } learn($text, 1); } echo "Mission complete";
if (!password_verify($pass, $hash)) { echo "sorry.\n"; exit(0); } $user = sql_single_query("select * from users where nick='" . mysql_real_escape_string($nick) . "'"); if ($user == NULL) { echo "sorry.\n"; exit(0); } echo "Welcome to your lesson {$nick}\n"; $courses_available = sql_resultset("select course_id,description,tag from user_courses,courses where user_id='{$user['id']}' and course_id=courses.id"); echo "Available courses:\n"; $i = 0; foreach ($courses_available as $course) { echo "{$i}: {$course['description']}\n"; $i++; } do { $course = termline("Which course would you like to study?"); if ($course == NULL) { exit(0); } } while ($course >= count($courses_available)); // what the user is learning should come from the 'courses' table $learning = substr($courses_available[$course]['tag'], 1, strlen($courses_available[$course]['tag']) - 2); echo "learning {$learning}"; // track performance during this session $user['ngood'] = 0; $user['nfalse'] = 0; while (learn($user, $learning)) { }