2016-05-31 58 views
0

我想出来的FANN PHP模块和我能够在这里成功运行示例http://php.net/manual/en/fann.examples-1.phpPHP文芳给了,尽管不同的输入

我修改了它能够处理与输出任意函数5个输入相同的结果。我生成了1000个训练数据并运行神经网络的训练。但是,在测试后,输出对于不同的输入具有重复的结果。

这是训练数据的一个片段。该功能是$x = round($a + $b * $c/$d - $e, 2)。所以35 + 33 * 31/25 - 48 = 27.92

1000 5 1 
35 33 31 25 48 
27.92 
74 3 1 26 94 
-19.88 
7 62 86 48 71 
47.08 
31 73 68 94 95 
-11.19 
100 87 44 75 43 
108.04 
72 25 62 39 57 
54.74 
... 

这是我的培训代码。我使用了FANN_LINEAR,因为其他激活函数的输出为0,1或-1。我读到FANN_LINEAR是无限的。所以这应该是适用的,对吧?

<?php 
$num_input = 5; 
$num_output = 1; 
$num_layers = 6; 
$num_neurons_hidden = 4; 
$desired_error = 0.0001; 
$max_epochs = 500000; 
$epochs_between_reports = 1000; 

$ann = fann_create_standard($num_layers, 5, 5, 5, 5, 5, 1); 

if ($ann) { 
    fann_set_activation_function_hidden($ann, FANN_LINEAR); 
    fann_set_activation_function_output($ann, FANN_LINEAR); 

    $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); 
} 

这里是我的测试代码

<?php 
$train_file = (dirname(__FILE__) . "/xor_float.net"); 
if (!is_file($train_file)) 
    die("The file xor_float.net has not been created! Please run simple_train.php to generate it"); 

$ann = fann_create_from_file($train_file); 
if (!$ann) 
    die("ANN could not be created"); 

$a = mt_rand(1, 100); 
$b = mt_rand(1, 100); 
$c = mt_rand(1, 100); 
$d = mt_rand(1, 100); 
$e = mt_rand(1, 100); 

echo "Expecting $a $b $c $d $e => ".round($a + $b * $c/$d - $e, 2)."\n\n"; 

$input = array($a, $b, $c, $d, $e); 
$calc_out = fann_run($ann, $input); 
echo "Result: ".print_r($calc_out, true); 
fann_destroy($ann); 

这是它会很奇怪。我试过多次运行此代码,但结果是一样的

fann$ php test2.php 
Expecting 94 67 95 40 85 => 168.13 

Result: Array 
(
    [0] => 89.329223632812 
) 
fann$ php test2.php 
Expecting 53 43 56 64 64 => 26.63 

Result: Array 
(
    [0] => 89.329223632812 
) 
fann$ php test2.php 
Expecting 18 85 57 94 30 => 39.54 

Result: Array 
(
    [0] => 89.329223632812 
) 

你能给我一些指点,以实现我的目标,那就是,近似使用FANN任意函数。我是否必须增加训练数据?增加图层或每层节点?我是否使用其他激活功能?

回答

1

乍一看,你的网络似乎陷入了一定的重量配置。这意味着权重(通常为initialized to small values around 0)开始改变它们的值以更好地适应所需的输出。由于这些变化很小,有可能在一些训练时期之后,他们要么“移动不够”来找到一个很好的价值组合,要么他们保持在当地的最低水平。有许多可能的原因(或只是事情要考虑)为:

  • 的是,网络和训练算法必须处理输入&输出值比较大(〜范围[-20,100] ),与权重的初始值(范围[-1,1])进行比较。这里的最简单的解决方案是normalize输入&输出是A)小,B)为中心的周围0

  • 活化功能FANN_LINEAR没有上限和下限。这可能是好的,但也可能导致分歧。一种选择是使用FANN_SIGMOID_SYMMETRIC,它具有限制,但也是一个接近线性的过渡区域。它适用于标准化的输入和输出。

  • 有时动量和学习率的值可能会导致糟糕的学习。为了进行一些诊断,您可能需要根据训练时期绘制一个错误learning error curve。当然,这有点费力,因为你需要单独训练每个纪元(fann_train_epoch而不是fann_train_on_file)。

  • 最后。我对大型网络没有经验,但我可以想象,单个隐藏层可以学习像这样的问题。为什么不试一试呢?这已经是够难修复1隐层的数量,只是把公式中越来越多的参数;)

嗯,我希望帮助:) 与你的网乐趣!

相关问题