/////////////////////////////// INTERFACE //////////////////////////////// void GeneticClass::Interface(){ lc = 10000; int algorithmIteration = 30; float crossoverRatio = 0.9; int mutationIteration = 1000; int score = 0, parent1, parent2; DrawingPopulation(); Rating(); cout << "Rodzice: " << bestScoreInAll << endl; checksRepeatsInSet(); ////////////// SELEKCJA I KRZYZOWANIE I MUTACJA/////////////////////////////// for (int z = 0; z<algorithmIteration; z++){ int P = -1; // licznik nowej populacji vector<bool> crossed(lc,false); int crossoverIterations = (lc - 2) * crossoverRatio; #pragma omp parallel for for (P = -1; P < crossoverIterations; P += 2) { parent1 = TournamentSelection(10); do parent2 = TournamentSelection(10); while (parent1 == parent2); crossed[parent1] = true; crossed[parent2] = true; Crossover(parent1, parent2, children[P + 1], children[P + 2]); } for (int i = 0 ; i < lc; i++) { //Dopisuje do children osobniki ktore nie braly udzialu w krzyzowaniu if (crossoverIterations != lc) { if (crossed[i] == false) { children[crossoverIterations++] = chromosom[i]; } } else { break; } } chromosom.swap(children); for (int i = 0; i<mutationIteration; i++){ int target = TournamentSelection(100); Mutation(chromosom[target]); // przy zakomentowanym krzyzowaniu wpisalem tu chromosom zamiast children } checksRepeatsInSet(); score = Rating(); cout << "Populacja_" << z << " = " << score << endl; } showBest(); }
void predictAll(UserModel &trainDataModel, NeighborCollection *neighbor_cls, double *userRanks, UserModel &testDataModel, UserModel &resultDataModel) { //train(trainDataModel); for(int u = testDataModel.user_0; u < testDataModel.user_0 + testDataModel.n_user; u++) { map<int,Rating> &rs = testDataModel.getRatings(u); for(map<int,Rating>::iterator it_i = rs.begin(); it_i != rs.end(); it_i++) { int i = it_i->first; double s = predict(trainDataModel, neighbor_cls, userRanks, u, i, it_i->second.timestamp); resultDataModel.entities[u].ratings[i] = Rating(u,i,s,it_i->second.timestamp); } } }
void hasDMA::View() const { std::cout << "Label: " << Label() << std::endl; std::cout << "Rating: " << Rating() << std::endl; std::cout << "Style: " << _style << std::endl; }