Как получить весовую матрицу от NN FANN?

Я использую FANN для использования нейронной сети. ( Ссылка на FANN)

Мне нужно получить матрицу веса после тренировки в сети, но я ничего не нашел в документации. ( Ссылка на документацию)

Вы знаете, как получить эту матрицу???

Спасибо!

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 (тип для веса)

Другие вопросы по тегам