-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_classification_data1.cpp
More file actions
executable file
·41 lines (31 loc) · 1.51 KB
/
Copy pathtask_classification_data1.cpp
File metadata and controls
executable file
·41 lines (31 loc) · 1.51 KB
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
#include <vector>
#include <iostream>
#include <fstream>
#include <cmath>
#include "ea.hpp"
#include "activation.hpp"
#include "fitness.hpp"
#include "utils.hpp"
int main(){
// individuals, epochs, number of recombined individuals, mutation range, mutation probability, abort fitness
Ea_settings ea_settings {2000, 100, 1000, 2.0, 0.2, 1.0};
// input neurons, hidden neurons, output neurons, initial weight range
// if output neurons is set to 0 the hidden neurons become the output neurons
Ann_settings ann_settings {2, 1, 0, 2.0, Sigmoid};
std::string file_descriptor = "data";
std::vector<struct data_point> set = parse_data_file(file_descriptor);
Evolution evo = Evolution(ea_settings, ann_settings, fitness_classification);
std::tuple<Network, Genome> winner = evo.eval(set);
Network winner_net = get<0>(winner);
Genome winner_genome = get<1>(winner);
winner_net.set_input_weights(winner_genome.input_weights);
winner_net.set_hidden_weights(winner_genome.hidden_weights);
FILE * fp = fopen("classification_results_data1", "w");
std::cout << "Best classification: " << winner_genome.fitness << std::endl;
std::cout << "X Y Classification Prediction" << std::endl;
for(auto e: set){
int output = (int) std::round(winner_net.evaluate(e.input)[0]);
fprintf(fp, "%f %f %i %i \n", e.input[0], e.input[1], e.classification, output);
std::cout << e.input[0] << " " << e.input[1] << " " << e.classification << " " << output << std::endl;
}
}