LoginSignup
0
0

More than 5 years have passed since last update.

cでnn その4

Last updated at Posted at 2018-09-25

概要

cで、ニューラルネットワークやってみた。
xor問題やってみた。

ライブラリー

サンプルコード

#include "catseye.h"

int main()
{
    int repeat = 2000;
    int sample = 4;
    int size = 2;
    int label = 2;
    CatsEye cat;
    CatsEye__construct(&cat, size, 8, label, 0);
    double x[size * sample];
    int t[sample];
    x[0] = 0;
    x[1] = 0;
    t[0] = 0;

    x[2] = 0;
    x[3] = 1;
    t[1] = 1;

    x[4] = 1;
    x[5] = 0;
    t[2] = 1;

    x[6] = 1;
    x[7] = 1;
    t[3] = 0;

    CatsEye_train(&cat, x, t, sample, repeat, 0.1);
    int r = 0;
    for (int i = 0; i < sample; i++) 
    {
        int p = CatsEye_predict(&cat, x + size * i);
        if (p == t[i]) r++;
        printf ("%d -> %d\n", p, t[i]);
    }
    printf ("Prediction accuracy on training data = %f%%\n", (float) r / sample * 100.0);
    return 0;
}

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0