2012-03-08 42 views
2

我一直在試驗FANN這個庫,它似乎是一個很好的神經網絡庫,我在使用它的時候遇到了一些問題。使用FANN庫

所以我在這裏要做的是培養一個神經網絡,爲了搞亂圖書館,給它一個輸入並期待輸出。

FANN::neural_net nn; 
const float desired_error = 0.00001; 
const unsigned int max_epochs = 500000; 
const unsigned int epochs_between_reports = 1000; 
const unsigned int layers_count = 3; 
const unsigned int layers[layers_count] = {7, 5, 1}; 
nn.create_standard_array(layers_count, layers); 
nn.train_on_file(TRAINING_DATA, max_epochs, epochs_between_reports, desired_error); 

這裏是我的訓練數據文件(TRAINING_DATA)的第一行:

16969 7 1 
0.0812069 0.0812069 0.381578 0.0812069 5.8931e-05 0.0843302 0.606695 
1 
0.429961 0.0509753 0.381578 0.0266957 0.000117862 0.00707172 0.0221581 
1 
0.0983558 0.486888 0.381578 0.000117862 0.0266957 0.00701279 0.0539808 
1 
0.0983558 0.486888 0.598562 0.0161471 0.0161471 0.000471448 0.00135541 
1 

完整數據集可以發現here

從訓練數據文件中使用的樣本數據,我應該得到匹配它的輸出,對吧?然而,如果我做以下,我得到0作爲輸出...

fann_type i[7], *o; 
i[0] = 0.429961; i[1] = 0.0509753; i[2] = 0.381578; i[3] = 0.0266957; i[4] = 0.000117862; i[5] = 0.00707172; i[6] = 0.0221581; 
o = nn.run(i); 
std::cout << "output (run) is " << o[0] << std::endl; 

有人能真正解釋我在這裏發生了什麼?

我使用的是fann的2.2.0版本。

謝謝

編輯:看來,2.1.0測試版產生預期的結果,但不是2.2.0版本。

編輯2:這實際上是我使用的版本中的一個錯誤。

+0

你已經得到16969個訓練實例,所以當你有一個MSE(均方誤差)<0.00001並不意味着所有內容都能正確預測。您的網絡是否會達到預期的錯誤? – alfa 2012-03-08 10:17:11

+0

是的。其實很快。 – ALOToverflow 2012-03-08 18:45:31

+0

你測試過任何其他輸入嗎? – alfa 2012-03-08 21:27:41

回答

1

我試圖重現你的錯誤,但我不能。下面是我的程序:

#include<iostream> 
using namespace std; 
#include <fann.h> 
#include <fann_cpp.h> 
#include <floatfann.h> 
int main() 
{ 
    FANN::neural_net nn; 
    const float desired_error = 0.00001; 
    const unsigned int max_epochs = 500000; 
    const unsigned int epochs_between_reports = 1000; 
    const unsigned int layers_count = 3; 
    const unsigned int layers[layers_count] = {7, 5, 1}; 
    nn.create_standard_array(layers_count, layers); 
    nn.train_on_file("test.train", max_epochs, epochs_between_reports, desired_error); 

    fann_type i[7]; 
    i[0] = 0.429961; i[1] = 0.0509753; i[2] = 0.381578; i[3] = 0.0266957; i[4] = 0.000117862; i[5] = 0.00707172; i[6] = 0.0221581; 
    fann_type *o = nn.run(i); 
    std::cout << "output (run) is " << o[0] << std::endl; 

    return 0; 
} 

這是輸出:

Max epochs 500000. Desired error: 0.0000100000. 
Epochs   1. Current error: 0.2283857614. Bit fail 4. 
Epochs   7. Current error: 0.0000000000. Bit fail 0. 
output (run) is 1 

也許你可以提供完整的訓練集?

+0

我猜測「test.train」包含我用這個問題發佈的數據集的樣本? – ALOToverflow 2012-03-09 19:31:43

+0

是的,我想這可能不足以進行比較。 – alfa 2012-03-09 19:34:49

+0

這是一個完全不同的數據文件。這不是fann格式。 – alfa 2012-03-09 20:38:03

0

我在某個時候遇到了問題,輸入和輸出都獲得了與我最初設置的值不同的值。這一切都歸結到使用一個激活函數,它具有與我期望的範圍不同的範圍。我張貼有關此問題這裏:

http://leenissen.dk/fann/forum/viewtopic.php?f=1&t=1827

默認活化功能FANN_SIGMOID_STEPWISE這是範圍[0,1]。看起來你所有的數據都在0到1之間,所以這是你的問題。

雖然可以將數據文件加載到fann數據結構中,然後查看get_input()和get_output()爲您提供的內容,以確保它們符合您的期望。

好運

(如果您發現了什麼事請在這裏發表它爲後人着想)

+0

問題只發生在他的FANN庫版本中,似乎是一個錯誤。 – alfa 2012-04-03 19:38:27