Skip to content

Commit

Permalink
index fixes, mean printing
Browse files Browse the repository at this point in the history
  • Loading branch information
gprabowski committed Nov 16, 2020
1 parent f367963 commit 3da0f2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/FitnessFunctionKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ __global__ void calculate_fitness(

float epsilon = cumulative_error / ((node_number * data_size) - (node_number * window_size));
fitness[index] = 1.0 / (1.0 + epsilon);

printf("Fitness: %f, index: %d\n", fitness[index], index);
}
13 changes: 9 additions & 4 deletions src/TimeSeriesPredictor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ auto TimeSeriesPredictor::crossover(Chromosome chr1, Chromosome chr2) -> std::ve

auto TimeSeriesPredictor::mutate(Chromosome chr) -> Chromosome {
for(int i = 0; i < chr.genes.size(); ++i) {
if(this->distribution(mt) < 0.08) {
if(this->distribution(mt) < 0.18) {
chr.genes[i] = distribution(mt) * 2 - 1;
}
}
Expand Down Expand Up @@ -152,8 +152,8 @@ auto TimeSeriesPredictor::launchCudaKernel() -> void {

for(int i = 0; i < this->populationSize; ++i) {
float * weights = this->population[i].genes.data();
gpuErrchk(cudaMemcpy(&this->dataWeightsGpu[i], weights, w * n * sizeof(float), cudaMemcpyHostToDevice));
gpuErrchk(cudaMemcpy(&this->mapWeightsGpu[i], &weights[w * n], n * n * sizeof(float), cudaMemcpyHostToDevice));
gpuErrchk(cudaMemcpy(&this->dataWeightsGpu[i * w * n], weights, w * n * sizeof(float), cudaMemcpyHostToDevice));
gpuErrchk(cudaMemcpy(&this->mapWeightsGpu[i * n * n], &weights[w * n], n * n * sizeof(float), cudaMemcpyHostToDevice));
}

cudaMemset(this->mapInputGpu, 0, n * sizeof(float));
Expand All @@ -163,8 +163,13 @@ auto TimeSeriesPredictor::launchCudaKernel() -> void {
gpuErrchk(cudaDeviceSynchronize());

gpuErrchk(cudaMemcpy(fitnessHost, fitnessGpu, this->populationSize * sizeof(float), cudaMemcpyDeviceToHost));


auto sum = 0.0;
auto ehh = 0;
for(int i = 0; i < this->populationSize; ++i) {
sum += fitnessHost[i];
++ehh;
this->population[i].fitness = fitnessHost[i];
}
printf("The mean is %f \n", sum / ehh);
}

0 comments on commit 3da0f2c

Please sign in to comment.