This repository was archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.php
More file actions
37 lines (31 loc) · 1.3 KB
/
utils.php
File metadata and controls
37 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
global $input1;
function debug(Neuron $neuron, $data = null, $target = null, $tree = null, $prefix = '')
{
global $input1;
$type = 'Output';
if ($neuron->branch() instanceof Peripheral) {
$type = 'Input' . ($neuron === $input1 ? '1' : '2');
} elseif ($neuron->branch() instanceof Bias) {
$type = 'Bias';
} elseif (count($neuron->branch()->synapses()) && $prefix !== '') {
$type = 'Hidden';
}
$function = end(explode('\\', get_class($neuron->outputFunction())));
$output = $data ? ': ' . $neuron->output($data) : '';
$error = $derivative = '';
if ($type == 'Hidden' || $type == 'Output') {
$error = $tree ? ' (e: ' . $tree->error($neuron, $data, $target) . ')' : '';
$derivative = $data ? ' (>: ' . $neuron->derivative($data) . ')' : '';
}
echo $prefix, $type, '(', $function, ')', $output, $error, $derivative, "\n";
foreach ($neuron->branch()->synapses() as $i => $synapse) {
$delta = $tree ? ' (d: ' . $tree->delta($synapse, $data, $target) . ')' : '';
echo $prefix, ' Synapse ', $i, ' => ', $synapse->weight(), $delta, "\n";
debug($synapse->neuron(), $data, $target, $tree, $prefix . ' ');
}
}
function rand_range($min, $max)
{
return $min + ((rand() / getrandmax()) * ($max - $min));
}