vista에서 stm32duino의 14.

개요
비스타로 stm32duino를 만들어 봤어요.
신경망, 해 봤어요.
샘플 코드
double w1[12] = {0.6203325, -1.027319, 1.8841791, -3.2817535, 1.2214272, 0.9679314, 1.4196726, 7.171823, 1.3714954, 3.7268815, 0.0598045, 1.1944624};
double b1[12] = {1.1656082, -2.0180476, -6.9387307, 3.3653135, -1.7032033, -2.8969588, 0.0565524, -9.5316219, -5.7146306, -2.8060255, -0.3085915, -6.3642092};
double w2[12] = {-1.2655445, -1.0401167, 0.2071615, -0.4695872, -2.6633599, -0.5835096, 1.2490041, 1.2825323, -1.5088843, 0.6767025, 0.0224434, 1.6849496};
double b2 = -0.2928229;
int i;

double tanh(double x) {
    if (x > 20)
        return 1.0;
    else if (x < -20)
        return -1.0;
    else
    {
        double a = exp(x);
        double b = exp(-x);
        return (a - b) / (a + b);
    }
}

void setup() {
    Serial.begin(9600);
    i = 0;
}
void loop() {
    int j;
    i++;
    if (i > 20)
        i = 0;
    double x = i / 3.0;
    double sum = 0;
    double d[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    for (j = 0; j < 12; j++)
    {
        d[j] += w1[j] * x + b1[j];
    }
    for (j = 0; j < 12; j++)
    {
        d[j] = tanh(d[j]);
    }
    for (j = 0; j < 12; j++)
    {
        sum += w2[j] * d[j];
    }
    sum += b2;
    sum = tanh(sum);
    Serial.println(sum);
}





결실

이상.

좋은 웹페이지 즐겨찾기