c - 如何从 NN FANN 获取权重矩阵?

标签 c artificial-intelligence neural-network fann

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

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

你知道如何得到这个矩阵吗???

谢谢!

最佳答案

您需要使用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)

关于c - 如何从 NN FANN 获取权重矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28819553/

相关文章:

python-3.x - Pytorch DataLoader 类错误

c - 什么类型的程序最好用C写

c - 何时将数组名或函数名“转换”为指针? (在C中)

c++ - 创建有点太大的数组时出现段错误

java - 编写可永久修改的字段或类(Java、ASM),无需数据库/文件

ruby - 编程技术 : How to create a simple card game

C 指针矩阵函数中的指针问题

opencv - 用手点裁剪所需区域

image-processing - 卷积神经网络中深度的解读

opencv - 如何计算神经网络输出层的二阶导数?