学校の課題で単純パーセプトロンのプログラムをっ作成せよという課題が出ました。 言語はC++です。
//パーセプトロンの重み計算
//ニューラルネットワークの出力計算のところがわかりません何かアドバイスをください。
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<math.h>
#define NUM 200
#define DIM 4
using namespace std;
int main(void) {
ifstream ifs;
double x[DIM][NUM] = { 0 };
int y[NUM] = { 0 };
int count = 0;
ifs.open("./data/iris.csv");
if (!ifs) {
printf_s("iris.csvを読み込めませんでした。");
return 0;
}
char str[100];
ifs.getline(str, 100, '\n');
while (!ifs.eof()) {
ifs.getline(str, 100, ',');
x[0][count] = atof(str);
ifs.getline(str, 100, ',');
x[1][count] = atof(str);
ifs.getline(str, 100, ',');
x[2][count] = atof(str);
ifs.getline(str, 100, ',');
x[3][count] = atof(str);
ifs.getline(str, 100, '\n');
if (!strcmp(str, "setosa")) {
y[count] = 0;
}
else if (!strcmp(str, "versicolor")) {
y[count] = 1;
}
count++;
}
count--;
double w[DIM] = { 0 }, b = 0;
double z, eta = 0.2;
int y2;
//パーセプトロンの重み計算
}
}
//確認
int yes = 0, no = 0;
for(int i=0;i<count;i++){
//ニューラルネットワークの出力計算
if (int i = 0; i < count; i++) {
printf_s("正解\n");
yes++;
}
else {
printf_s("不正解\n");
no++;
}
}
printf("正答率:%lf\n", (double)yes//(yes+no));
return 0;
}
学校の課題
Re: 学校の課題
東上☆海美☆「
とりあえず、https://www.onlinegdb.com/ で清書して、ビルドしたみみ。
"./data/iris.csv" も up するみみ。
どんな、単純パーセプトロンの重み計算で、ニューラルネットワークなのかは、
課題に、もっとくわしく書いてあるはずみみ。up するみみ。
」
とりあえず、https://www.onlinegdb.com/ で清書して、ビルドしたみみ。
"./data/iris.csv" も up するみみ。
どんな、単純パーセプトロンの重み計算で、ニューラルネットワークなのかは、
課題に、もっとくわしく書いてあるはずみみ。up するみみ。
」
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cmath>
#include <string.h>
const int NUM = 200;
const int DIM = 4;
using namespace std;
int main(void) {
ifstream ifs;
double x[DIM][NUM] = { 0 };
int y[NUM] = { 0 };
int count = 0;
ifs.open("./data/iris.csv");
if (!ifs) {
//printf_s("iris.csvを読み込めませんでした。");
printf("iris.csvを読み込めませんでした。");
return 0;
}
const int MAX=100;
char str[MAX];
ifs.getline(str, 100, '\n');
while (!ifs.eof()) {
ifs.getline(str, MAX, ',');
x[0][count] = atof(str);
ifs.getline(str, MAX, ',');
x[1][count] = atof(str);
ifs.getline(str, MAX, ',');
x[2][count] = atof(str);
ifs.getline(str, MAX, ',');
x[3][count] = atof(str);
ifs.getline(str, MAX, '\n');
if (!strcmp(str, "setosa")) {
y[count] = 0;
}
else if (!strcmp(str, "versicolor")) {
y[count] = 1;
}
count++;
}
count--;
#if 0
double w[DIM] = { 0 }, b = 0;
double z, eta = 0.2;
int y2;
//パーセプトロンの重み計算
#endif
//確認
int yes = 0, no = 0;
for( int i=0; i<count; i++ ) {
//ニューラルネットワークの出力計算
//if (int i = 0; i < count; i++ ) {
if( true ) {
//printf_s("正解\n");
printf("正解\n");
yes++;
}
else {
//printf_s("不正解\n");
printf("不正解\n");
no++;
}
}
printf("正答率:%lf\n", (double)yes ); //(yes+no))
return 0;
}
// end.
VTuber:
東上☆海美☆(とうじょう・うみみ)
http://atassyu.php.xdomain.jp/vtuber/index.html
レスがついていないものを優先して、レスするみみ。時々、見当外れなレスしみみ。
中の人:
手提鞄あたッしュ、[MrAtassyu] 手提鞄屋魚有店
http://ameblo.jp/mratassyu/
Pixiv: 666303
Windows, Mac, Linux, Haiku, Raspbery Pi, Jetson Nano, 電子ブロック 持ち。
東上☆海美☆(とうじょう・うみみ)
http://atassyu.php.xdomain.jp/vtuber/index.html
レスがついていないものを優先して、レスするみみ。時々、見当外れなレスしみみ。
中の人:
手提鞄あたッしュ、[MrAtassyu] 手提鞄屋魚有店
http://ameblo.jp/mratassyu/
Pixiv: 666303
Windows, Mac, Linux, Haiku, Raspbery Pi, Jetson Nano, 電子ブロック 持ち。