<?php namespace MachineLearning; include 'Util/Input.php'; include 'Util/Output.php'; $numLayers = 3; $numInput = Util\Input::NUM_INPUT; $numNeuronsHidden = 9; $numOutput = Util\Output::NUM_OUTPUT; $maxEpochs = 500000; $epochsBetweenReports = 1000; $desiredError = 0.001; $ann = fann_create_standard($numLayers, $numInput, $numNeuronsHidden, $numOutput); if ($ann) { fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC); if (fann_train_on_file($ann, 'Data/training', $maxEpochs, $epochsBetweenReports, $desiredError)) { fann_save($ann, 'Data/training_result'); } fann_destroy($ann); }
/** * Save ANN to file * @param string filename with absolute path * @return bool true on success, false on error */ public function save($filename) { $this->checkIfAnnIsAssigned(); return fann_save($this->annId, $filename); }
<?php $num_input = 2; $num_output = 1; $num_layers = 3; $num_neurons_hidden = 3; $desired_error = 0.001; $max_epochs = 500000; $epochs_between_reports = 1000; $ann = fann_create_standard($num_layers, $num_input, $num_neurons_hidden, $num_output); if ($ann) { fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC); $filename = dirname(__FILE__) . "/xor.data"; if (fann_train_on_file($ann, $filename, $max_epochs, $epochs_between_reports, $desired_error)) { fann_save($ann, dirname(__FILE__) . "/xor_float.net"); } fann_destroy($ann); }
/** * Save. * * @return bool */ public function save() { $result = fann_save($this->ann, $this->configurationFile); return $result; }
* * If you have any questions or comments, please e-mail Evan Nemerson * <*****@*****.**> */ /* If you don't want to compile FANN into PHP... */ if (!extension_loaded('fann')) { if (!dl('fann.so')) { exit("You must install the FANN extension. You can get it from http://fann.sf.net/\n"); } } /* Create an artificial neural network */ $ann = fann_create(array(2, 4, 1), 1.0, 0.7); /* To load from a file, you can use. If your version of PHP includes the streams API (4.3.0+ ?), * this can be anything accessible through streams (http, ftp, https, etc) */ // $ann = fann_create("http://example.com/xor_float.net"); /* Train the network using the same data as is in the xor.data file */ fann_train($ann, array(array(array(0, 0), array(0)), array(array(0, 1), array(1)), array(array(1, 0), array(1)), array(array(1, 1), array(0))), 100000, 1.0E-5, 1000); /* To achieve the same effect as the above with the data stored in an external file... Also works * with the streams API, when available. */ // fann_train($ann, '/home/tadpole/local/src/fann/examples/xor.data', 100000, 0.00001, 1000); print_r(fann_run($ann, array(0, 0))); // Should be ~ 0 print_r(fann_run($ann, array(0, 1))); // Should be ~ 1 print_r(fann_run($ann, array(1, 0))); // Should be ~ 1 print_r(fann_run($ann, array(1, 1))); // Should be ~ 0 /* This function is pretty simple. It will use the streams API if available. */ fann_save($ann, 'xor_float.net');
public function save() { fann_save($this->ann, $this->file); }