1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| int main(){
std::vector<train_data> data;
int n_data=20;
int n_dimension=0;
double learning_rate=0;
double n_correct=0;
int n_epoch=0;
clock_t start,end;
for(size_t i=0;i<n_data;i++){
data.push_back(_data(i));
}
std::cout<<"data: \n";
for(int i=0;i<data.size();i++){
std::cout<<"["<<i<<"] "<<data[i].to_str()<<"\n";
}
std::cout<<"learning rate: ";
std::cin>>learning_rate;
std::cout<<"epoch: ";
std::cin>>n_epoch;
perceptron PLA(data, learning_rate);
start = clock();
PLA.train(n_epoch,false);
end = clock();
for(size_t i=0;i<n_data;i++){
std::cout<<"data["<<i<<"]: predict -> "<<
PLA.predict_type(data[i])<<", actual -> "<<data[i].to_str();
if(PLA.predict_type(data[i])==data[i].get_type()){
std::cout<<GREEN<<" ✓ \n"<<RESET;
n_correct+=1;
}else{
std::cout<<RED<<" x \n"<<RESET;
}
}
std::cout<<PLA.to_str()<<"\n";
std::cout<<"correct rate: "<<(n_correct/n_data)*100<<"%, time: "<<((double)end-start)/CLK_TCK;
return 0;
}
|