Client-Server model: Difference between revisions
From Artificial Neural Network for PHP
(New page: == Server implementation == <source lang="php"> require_once 'ANN/ANN_Network.php'; require_once 'ANN/ANN_Server.php'; class ANN_MyServer extends ANN_Server { // ***********************...) |
|||
(10 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
<source lang="php"> |
<source lang="php"> |
||
require_once 'ANN/ |
require_once 'ANN/Loader.php'; |
||
require_once 'ANN/ANN_Server.php'; |
|||
use ANN\Server; |
|||
⚫ | |||
{ |
|||
// **************************************************************************** |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
*/ |
|||
⚫ | |||
⚫ | |||
{ |
{ |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
*/ |
|||
⚫ | |||
⚫ | |||
{ |
|||
} |
|||
⚫ | |||
⚫ | |||
// **************************************************************************** |
|||
} |
|||
} |
} |
||
$ |
$objServer = new MyServer; |
||
</source> |
</source> |
||
Line 32: | Line 29: | ||
<source lang="php"> |
<source lang="php"> |
||
require_once 'ANN/ |
require_once 'ANN/Loader.php'; |
||
use ANN\Network; |
|||
use ANN\Values; |
|||
try |
try |
||
{ |
{ |
||
$ |
$objNetwork = new Network; |
||
$objValues = new Values; |
|||
$objValues->train() |
|||
->input(0,0)->output(0) |
|||
->input(0,1)->output(1) |
|||
->input(1,0)->output(1) |
|||
->input(1,1)->output(0); |
|||
} |
} |
||
catch(Exception $e) |
catch(Exception $e) |
||
{ |
{ |
||
die('Network could not be created'); |
|||
exit; |
|||
} |
} |
||
$objNetwork->setValues($objValues); // to be called as of version 2.0.6 |
|||
$inputs = array( |
|||
array(0, 0), |
|||
array(0, 1), |
|||
array(1, 0), |
|||
array(1, 1) |
|||
); |
|||
$outputs = array( |
|||
array(0), |
|||
array(1), |
|||
array(1), |
|||
array(0) |
|||
); |
|||
$network->setInputs($inputs); |
|||
$network->setOutputs($outputs); |
|||
$objNetwork = $objNetwork->trainByHost( |
|||
$network = $network->trainByHost('username', 'password', 'http://example.tld/ANN_Server.php'); |
|||
'username', |
|||
'password', |
|||
'http://example.tld/ANN_Server.php' |
|||
); |
|||
if($ |
if($objNetwork instanceof Network) |
||
$ |
$objNetwork->printNetwork(); |
||
</source> |
</source> |
Latest revision as of 12:17, 1 June 2011
Server implementation
require_once 'ANN/Loader.php';
use ANN\Server;
class MyServer extends Server
{
/**
* @param string $strUsername
* @param string $strPassword
* @return boolean
*/
protected function checkLogin($strUsername, $strPassword)
{
// User-defined authentication by database for example
return ($strUsername == 'username' && $strPassword == 'password');
}
}
$objServer = new MyServer;
Client implementation
require_once 'ANN/Loader.php';
use ANN\Network;
use ANN\Values;
try
{
$objNetwork = new Network;
$objValues = new Values;
$objValues->train()
->input(0,0)->output(0)
->input(0,1)->output(1)
->input(1,0)->output(1)
->input(1,1)->output(0);
}
catch(Exception $e)
{
die('Network could not be created');
}
$objNetwork->setValues($objValues); // to be called as of version 2.0.6
$objNetwork = $objNetwork->trainByHost(
'username',
'password',
'http://example.tld/ANN_Server.php'
);
if($objNetwork instanceof Network)
$objNetwork->printNetwork();