2015-03-02 54 views

回答

1

您需要使用fann_get_connection_array()函數。它給你排列struct fann_connection,並且struct fann_connection有字段weight,所以這是你想要的。

你可以做這樣的事情來打印你的權重矩陣:

int main(void) 
{ 
    struct fann *net;    /* your trained neural network */ 
    struct fann_connection *con; /* weight matrix */ 
    unsigned int connum;   /* connections number */ 
    size_t i; 

    /* Insert your net allocation and training code here */ 
    ... 

    connum = fann_get_total_connections(net); 
    if (connum == 0) { 
     fprintf(stderr, "Error: connections count is 0\n"); 
     return EXIT_FAILURE; 
    } 

    con = calloc(connum, sizeof(*con)); 
    if (con == NULL) { 
     fprintf(stderr, "Error: unable to allocate memory\n"); 
     return EXIT_FAILURE; 
    } 

    /* Get weight matrix */ 
    fann_get_connection_array(net, con); 

    /* Print weight matrix */ 
    for (i = 0; i < connum; ++i) { 
     printf("weight from %u to %u: %f\n", con[i].from_neuron, 
       con[i].to_neuron, con[i].weight); 
    } 

    free(con); 

    return EXIT_SUCCESS; 
} 

詳情:

[1] fann_get_connection_array()

[2] struct fann_connection

[3] fann_type (type for weight)

+0

我試圖使用你的代碼,但我獲得這個錯誤:分割錯誤:11 :(:( – Teo 2015-03-02 22:06:09

+0

我沒有安裝FANN庫,所以這段代碼只是答案的示意圖(代碼上方)。所以當然這個代碼可能會失敗。無論如何,我重新做了一點,現在就試試。在調用下面的代碼之前,一定要爲'net'變量分配內存並訓練它。 – 2015-03-02 22:15:55

+0

對不起,我好蠢!你的代碼是正確的...只是我以另一種方式調用了網絡,所以我之前使用了一個空網絡... – Teo 2015-03-02 22:18:50