NeuralMesh
  • Class
  • Tree

Classes

  • AbstractNetwork
  • Controller
  • layer
  • ManagedNetwork
  • Model
  • mysql
  • Navigation
  • network
  • NeuralMesh
  • neuron
  • nmesh
  • synapse
  • train
  • UnmanagedNetwork
  • users
  • validation
 1 <?php
 2 class Model {
 3 
 4     public static $OUTPUT = 0;
 5     public static $LAYER = 1;
 6     public static $INPUT = 2;
 7     public static $NEURON = 3;
 8     public static $NETWORK = 4;
 9     public static $SET = 5;
10     public static $PATTERN = 6;
11 
12     function __construct() {
13         // Plugins should be imported here:
14         require_once(Controller::$root."proxy/mysqli.class.php");
15         require_once(Controller::$root."proxy/navigation.class.php");
16         require_once(Controller::$root."proxy/network.class.php");
17         require_once(Controller::$root."proxy/train.class.php");
18         require_once(Controller::$root."proxy/validation.class.php");
19         require_once(Controller::$root."proxy/users.class.php");
20         // But not past here :)
21         mysql::init(); //specify XML files
22         $this->nav = new Navigation;
23         $this->assets = array("global.css");
24         $this->network = new network;
25         $this->train = new train;
26         $this->val = new validation;
27         $this->users = new users;
28         $this->year = date("Y");
29         if(isset($_SESSION['name'])) $this->user = $_SESSION['name'];
30     }
31     
32     static function direct($url=NULL) {
33         if(is_null($url)) $url = $_SERVER['HTTP_REFERER'];
34         header("Location: ".$url);
35     }
36     
37     function encode($nn) {
38         return gzcompress(serialize($nn));
39     }
40     
41     function decode($nn) {
42         return unserialize(gzuncompress($nn));
43     }
44     
45     function loadAssets() {
46         $output = "";
47         foreach($this->assets as $file) {
48             $ext = substr($file, strrpos($file, '.') + 1);
49             if($ext == "js") {
50                 $output .= "<script type='text/javascript' src='assets/$file'></script>\n";
51             } else if($ext == "css") {
52                 $output .= "<link href='assets/$file' type='text/css' rel='stylesheet' />\n";
53             }
54         }
55         return $output;
56     }
57     
58     function getCache($id) {
59         $q = mysql::query("cache.get",array("id"=>$id));
60         if($q->num_rows) {
61             $data = $q->fetch_array();
62             return $data[0];
63         }
64         return null;
65     }
66     
67     function saveCache($hash,$id,$data) {
68         mysql::query("cache.save",array("id"=>$hash,"network"=>$id,"data"=>$data));
69     }
70     
71     /**
72      * Update the cache with the new outputs
73      * @param $id ID of the network
74      * @param $data Training data
75      */
76     function update_cache($id,$data,$nn) {
77         foreach($data as $set) {
78             $inputs = str_split(trim($set['pattern']));
79             $outputs = $nn->run($inputs);
80             mysql::query("cache.save",array("id"=>$id.trim($set['pattern']),"network"=>$id,"data"=>implode("|",$outputs)));
81         }
82     }
83     
84     function clearCache() {
85         mysql::query("cache.clear",array("n"=>CACHE_LIFE),true);
86         mysql::query("networks.clear",array("n"=>UNMANAGED_LIFE),true);
87     }
88     
89     /**
90      * Quickly caches one pattern and output from the nmesh cache
91      * @param $id Network ID
92      * @param $input Input string
93      * @param $data Output array
94      */
95     function quick_cache($id,$input,$data) {
96         mysql::query("cache.save",array("id"=>$id.trim($input),"network"=>$id,"data"=>implode("|",$data)));
97     }
98 }
99 ?>
NeuralMesh API documentation generated by ApiGen