neuralnet.php/build/neuralnetwork/core/NeuralNetwork.php

61 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace neuralnetwork\core;
use neuralnetwork\core\NeuralNetworkCore;
use filemanager\core\FileManager;
/************************************************
**** Neural Network's Facade ****
************************************************/
class NeuralNetwork{
/* CREATES A NEW NEURAL NETWORK
*
* @generations<int> Maximum number of generations to process
* @genomes<int> Number of genomes per generation
*
* @return nn<NeuralNetwork> New NeuralNetwork
*
*/
public static function create($generations=null, $genomes=null){
/* Propagate instance creation */
return new NeuralNetworkCore($generations, $genomes);
}
/* LOADS A NEURAL NETWORK FROM STORAGE
*
* @storage<String> Path to storage
*
* @return nn<NeuralNetwork> Loaded NeuralNetwork
*
*/
public static function load($storage=null){
/* (1) Checks argument */
if( is_null($storage=NeuralNetworkCore::getStorage($storage)) )
throw new \Exception('Wrong NeuralNetwork loader\'s argument.');
/* (2) If files doesn't exist, raise error */
if( !$storage['nn']['exists'] )
throw new \Exception('Loaded storage have file(s) missing.');
/* (3) Unserialize last NeuralNetwork */
$last_network = FileManager::read($storage['nn']['filename']);
/* (4) Creates and fill instance */
$instance = new NeuralNetworkCore(0, 0);
$instance->unserialize($last_network);
/* (5) Returns instance */
return $instance;
}
}
?>