protected function randomizeWeights() { $min = $this->getNeuralNetworkLayer()->getNeuralNetwork()->getRangeMin(); $max = $this->getNeuralNetworkLayer()->getNeuralNetwork()->getRangeMax(); foreach ($this->weights as $k => $weight) { $this->weights[$k] = randFloat($min, $max); } }
/** @return TrainingData[] */ function prepareTrainingDatas() { $result = []; for ($i = 0; $i <= 200; $i++) { $x = randFloat(0.1, 5); $y = randFloat(0.1, 5); $result[] = new TrainingData([$x, $y], [func($x, $y)]); } return $result; }
private function randomizeRange() { $this->rangeMin = randFloat(-2, -1); $this->rangeMax = randFloat(1, 2); }
private function randomizeRange() { $this->rangeMin = randFloat(-2, -1); $this->rangeMax = randFloat(1, 2); echo '<br>range: ' . $this->rangeMin . ', ' . $this->rangeMax . '<br>'; }
$num = $min + $range * mt_rand(0, 32767) / 32767; $num = round($num, 4); return (double) $num; } $client = new \InfluxDB\Client($host); $database = $client->selectDB('test'); if ($database->exists()) { $database->drop(); } $database->create(new \InfluxDB\Database\RetentionPolicy('test', '12w', 1, true)); $start = microtime(true); $countries = ['nl', 'gb', 'us', 'be', 'th', 'jp', 'nl', 'sa']; $colors = ['orange', 'black', 'yellow', 'white', 'red', 'purple']; $points = []; for ($i = 0; $i < 1000; $i++) { $points[] = new \InfluxDB\Point('flags', randFloat(1, 999), ['country' => $countries[array_rand($countries)]], ['color' => $colors[array_rand($colors)]], (int) shell_exec('date +%s%N') + mt_rand(1, 1000)); } // insert the points $database->writePoints($points); $end = microtime(true); $country = $countries[array_rand($countries)]; $color = $colors[array_rand($colors)]; $results = $database->query("SELECT * FROM flags WHERE country = '{$country}' LIMIT 5")->getPoints(); $results2 = $database->query("SELECT * FROM flags WHERE color = '{$color}' LIMIT 5")->getPoints(); echo "Showing top 5 flags from country {$country}:" . PHP_EOL; print_r($results); echo PHP_EOL; echo "Showing top 5 flags with color {$color}:" . PHP_EOL; print_r($results2); echo PHP_EOL; echo sprintf('Executed 1000 inserts in %.2f seconds', $end - $start);