如何从NN FANN获得体重矩阵?

时间:2015-03-02 21:13:50

标签: c artificial-intelligence neural-network fann

我正在使用FANN来使用神经网络。 (Link to FANN

我需要在训练网络后获得重量矩阵,但我没有从文档中找到任何内容。 (Link to documentation

你知道怎么得到那个矩阵???

谢谢!

1 个答案:

答案 0 :(得分: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)