Beispiel #1
0
    void report(Stats & info)
    {
        std::lock_guard<std::mutex> lock(mutex);

        /// Avoid zeros, nans or exceptions
        if (0 == info.queries)
            return;

        double seconds = info.watch.elapsedSeconds();

        std::cerr
            << "\n"
            << "QPS: " << (info.queries / seconds) << ", "
            << "RPS: " << (info.read_rows / seconds) << ", "
            << "MiB/s: " << (info.read_bytes / seconds / 1048576) << ", "
            << "result RPS: " << (info.result_rows / seconds) << ", "
            << "result MiB/s: " << (info.result_bytes / seconds / 1048576) << "."
            << "\n";

        auto print_percentile = [&](double percent)
        {
            std::cerr << percent << "%\t" << info.sampler.quantileInterpolated(percent / 100.0) << " sec." << std::endl;
        };

        for (int percent = 0; percent <= 90; percent += 10)
            print_percentile(percent);

        print_percentile(95);
        print_percentile(99);
        print_percentile(99.9);
        print_percentile(99.99);

        info.clear();
    }
Beispiel #2
0
void test_stats2() {
    // Test singleton pattern
    Stats* stats = Stats::getUniqueInstance();
    assert(stats->get((StatsKey)4) == 2);

    // Test clear()
    stats->clear();
    assert(stats->get((StatsKey)4) == 0);
}
Beispiel #3
0
void test_stats() {
    Stats* stats = Stats::getUniqueInstance();
    stats->clear();
    // Test Stats::put and get
    stats->put((StatsKey)1,10);
    stats->put((StatsKey)2,20);
    stats->put((StatsKey)3,30);
    assert(stats->get((StatsKey)1) == 10);
    assert(stats->get((StatsKey)2) == 20);
    assert(stats->get((StatsKey)3) == 30);
    stats->inc((StatsKey)1);
    assert(stats->get((StatsKey)1) == 11);

    assert(stats->get((StatsKey)4) == 0);

    // Test Stats::inc
    stats->inc((StatsKey)4);
    assert(stats->get((StatsKey)4) == 1);
    stats->inc((StatsKey)4);
    assert(stats->get((StatsKey)4) == 2);
    //stats->dump();

}
void StatsCalcFitnessNMSEOp::calculateStatsDeme(Stats &outStats, Deme &ioDeme, Context &ioContext) const {
    Beagle_StackTraceBeginM();
    outStats.clear();
    outStats.clearItems();
    int outputs = mConfig->getOutputs().size();
    outStats.addItem("processed", ioContext.getProcessedDeme());
    outStats.addItem("total-processed", ioContext.getTotalProcessedDeme());

    if(ioDeme.size() == 0) {
        outStats.setGenerationValues(Beagle::string("deme")+uint2str(ioContext.getDemeIndex()+1),
                                     ioContext.getGeneration(), 0, true);
        outStats.resize(3+outputs*2);
        outStats[0].mId  = "NMSE";
        outStats[0].mAvg = 0.0;
        outStats[0].mStd = 0.0;
        outStats[0].mMax = 0.0;
        outStats[0].mMin = 0.0;

        outStats[1].mId = "treedepth";
        outStats[1].mAvg = 0.0;
        outStats[1].mStd = 0.0;
        outStats[1].mMax = 0.0;
        outStats[1].mMin = 0.0;

        outStats[2].mId = "treesize";
        outStats[2].mAvg = 0.0;
        outStats[2].mStd = 0.0;
        outStats[2].mMax = 0.0;
        outStats[2].mMin = 0.0;

        for(int i=0; i<outputs; ++i) {
            int nr = 3 + i*2;
            outStats[nr].mId = "y" + int2str(i) + "-NMSE";
            outStats[nr].mAvg = 0.0;
            outStats[nr].mStd = 0.0;
            outStats[nr].mMax = 0.0;
            outStats[nr].mMin = 0.0;
            ++nr;
            outStats[nr].mId = "y" + int2str(i) + "-MSE";
            outStats[nr].mAvg = 0.0;
            outStats[nr].mStd = 0.0;
            outStats[nr].mMax = 0.0;
            outStats[nr].mMin = 0.0;
        }

        return;
    }

    const GP::Deme& gpDeme = castObjectT<const GP::Deme&>(ioDeme);
    const FitnessNMSE::Handle firstIndivFitness = castHandleT<FitnessNMSE>(ioDeme[0]->getFitness());


    if(ioDeme.size() == 1) {
        outStats.setGenerationValues(Beagle::string("deme")+uint2str(ioContext.getDemeIndex()+1),
                                     ioContext.getGeneration(), 1, true);

        outStats.resize(3+outputs*2);
        outStats[0].mId  = "NMSE";
        outStats[0].mAvg = firstIndivFitness->getNMSE();
        outStats[0].mStd = 0.0;
        outStats[0].mMax = firstIndivFitness->getNMSE();
        outStats[0].mMin = firstIndivFitness->getNMSE();

        outStats[1].mId = "treedepth";
        outStats[1].mAvg = gpDeme[0]->getMaxTreeDepth();
        outStats[1].mStd = 0.0;
        outStats[1].mMax = outStats[1].mAvg;
        outStats[1].mMin = outStats[1].mAvg;

        outStats[2].mId = "treesize";
        outStats[2].mAvg = gpDeme[0]->getTotalNodes();
        outStats[2].mStd = 0.0;
        outStats[2].mMax = outStats[2].mAvg;
        outStats[2].mMin = outStats[2].mAvg;

        for(int i=0; i<outputs; ++i) {
            int nr = 3 + i*2;
            double nmse = (*firstIndivFitness)[i].nmse;
            double mse = (*firstIndivFitness)[i].mse;
            outStats[nr].mId = "y" + int2str(i) + "-NMSE";
            outStats[nr].mAvg = nmse;
            outStats[nr].mStd = 0.0;
            outStats[nr].mMax = nmse;
            outStats[nr].mMin = nmse;
            ++nr;
            outStats[nr].mId = "y" + int2str(i) + "-MSE";
            outStats[nr].mAvg = mse;
            outStats[nr].mStd = 0.0;
            outStats[nr].mMax = mse;
            outStats[nr].mMin = mse;
        }
        return;
    }

    double sum = firstIndivFitness->getNMSE();
    double pow2sum = pow2Of<double>(sum);
    double max = sum;
    double min = sum;

    std::vector<double> sumNMSE(outputs, 0);
    std::vector<double> pow2sumNMSE(outputs, 0);
    std::vector<double> maxNMSE(outputs, 0);
    std::vector<double> minNMSE(outputs, 0);

    std::vector<double> sumMSE(outputs, 0);
    std::vector<double> pow2sumMSE(outputs, 0);
    std::vector<double> maxMSE(outputs, 0);
    std::vector<double> minMSE(outputs, 0);

    for(int i=0; i<outputs; ++i) {
        double nmse = (*firstIndivFitness)[i].nmse;
        double mse = (*firstIndivFitness)[i].mse;

        sumNMSE[i]      = nmse;
        pow2sumNMSE[i]  = pow2Of<double>(nmse);
        maxNMSE[i]      = nmse;
        minNMSE[i]      = nmse;

        sumMSE[i]       = mse;
        pow2sumMSE[i]   = pow2Of<double>(mse);
        maxMSE[i]       = mse;
        minMSE[i]       = mse;
    }

    unsigned int lMaxDepth = gpDeme[0]->getMaxTreeDepth();
    unsigned int lMinDepth = lMaxDepth;
    double lSumDepth       = (double)lMaxDepth;
    double lPow2SumDepth   = pow2Of<double>(lSumDepth);
    unsigned int lMaxSize  = gpDeme[0]->getTotalNodes();
    unsigned int lMinSize  = lMaxSize;
    double lSumSize        = (double)lMaxSize;
    double lPow2SumSize    = pow2Of<double>(lSumSize);

    unsigned indivs = 0;

    for(unsigned int i=1; i<ioDeme.size(); i++) {
        const FitnessNMSE::Handle indivFitness = castHandleT<FitnessNMSE>(ioDeme[i]->getFitness());
        double tNmse = indivFitness->getNMSE();
        //cout << endl << i << "\t" << tNmse << "\t" << indivFitness->size();

        if(tNmse != tNmse || tNmse == numeric_limits<double>::infinity()) {
            continue;
        }
        ++indivs;

        sum     += tNmse;
        pow2sum += pow2Of<double>(tNmse);
        max     =  maxOf<double>(max, tNmse);
        min     =  minOf<double>(min, tNmse);

        for(int j=0; j<outputs; ++j) {
            double nmse = (*indivFitness)[j].nmse;
            double mse = (*indivFitness)[j].mse;

            sumNMSE[j] += nmse;
            pow2sumNMSE[j] += pow2Of<double>(nmse);
            maxNMSE[j] = maxOf<double>(maxNMSE[j], nmse);
            minNMSE[j] = minOf<double>(minNMSE[j], nmse);

            sumMSE[j] += mse;
            pow2sumMSE[j] += pow2Of<double>(mse);
            maxMSE[j] = maxOf<double>(maxMSE[j], mse);
            minMSE[j] = minOf<double>(minMSE[j], mse);
        }

        unsigned int lTmpDepth = gpDeme[i]->getMaxTreeDepth();
        lSumDepth     += (double)lTmpDepth;
        lPow2SumDepth += pow2Of<double>((double)lTmpDepth);
        lMaxDepth     =  maxOf(lMaxDepth, lTmpDepth);
        lMinDepth     =  minOf(lMinDepth, lTmpDepth);

        unsigned int lTmpSize = gpDeme[i]->getTotalNodes();
        lSumSize     += (double)lTmpSize;
        lPow2SumSize += pow2Of<double>((double)lTmpSize);
        lMaxSize     =  maxOf(lMaxSize, lTmpSize);
        lMinSize     =  minOf(lMinSize, lTmpSize);
    }


    float lDepthStdError =
            (float)(lPow2SumDepth - (pow2Of<double>(lSumDepth) / indivs)) / (indivs - 1);
    lDepthStdError       = sqrt(lDepthStdError);

    float lSizeStdError =
            (float)(lPow2SumSize - (pow2Of<double>(lSumSize) / indivs)) / (indivs - 1);
    lSizeStdError       = sqrt(lSizeStdError);

    outStats.setGenerationValues(Beagle::string("deme")+uint2str(ioContext.getDemeIndex()+1),
                                 ioContext.getGeneration(),
                                 ioDeme.size(),
                                 true);

    outStats.resize(3+outputs*2);
    outStats[0].mId  = "NMSE";
    outStats[0].mAvg = sum / indivs;
    outStats[0].mStd = sqrt((pow2sum - (pow2Of<double>(sum)/indivs)) / (indivs-1));
    outStats[0].mMax = max;
    outStats[0].mMin = min;

    outStats[1].mId = "treedepth";
    outStats[1].mAvg = (float)(lSumDepth / indivs);
    outStats[1].mStd = lDepthStdError;
    outStats[1].mMax = (float)lMaxDepth;
    outStats[1].mMin = (float)lMinDepth;

    outStats[2].mId = "treesize";
    outStats[2].mAvg = (float)(lSumSize / indivs);
    outStats[2].mStd = lSizeStdError;
    outStats[2].mMax = (float)lMaxSize;
    outStats[2].mMin = (float)lMinSize;

    for(int j=0; j<outputs; ++j) {
        int nr = 3 + j*2;
        outStats[nr].mId = "y" + int2str(j) + "-NMSE";
        outStats[nr].mAvg = sumNMSE[j] / indivs;
        outStats[nr].mStd = sqrt((pow2sumNMSE[j] - (pow2Of<double>(sumNMSE[j])/indivs)) / (indivs-1));
        outStats[nr].mMax = maxNMSE[j];
        outStats[nr].mMin = minNMSE[j];
        ++nr;
        outStats[nr].mId = "y" + int2str(j) + "-MSE";
        outStats[nr].mAvg = sumMSE[j] / indivs;
        outStats[nr].mStd = sqrt((pow2sumMSE[j] - (pow2Of<double>(sumMSE[j])/indivs)) / (indivs-1));
        outStats[nr].mMax = maxMSE[j];
        outStats[nr].mMin = minMSE[j];
    }

    Beagle_StackTraceEndM("void SinsGP::StatsCalcFitnessNMSEOp::calculateStatsDeme(Beagle::Stats& outStats, Beagle::Deme& ioDeme, Beagle::Context& ioContext) const");
}
/*!
 *  \brief  Calculate statistics of a given vivarium.
 *  \param  outStats Computed stats of the deme.
 *  \param  ioVivarium Vivarium to evaluate the statistics.
 *  \param  ioContext Context of the evolution.
 */
void StatsCalculateOp::calculateStatsVivarium(Stats& outStats,
        Vivarium& ioVivarium,
        Context& ioContext) const
{
	Beagle_StackTraceBeginM();
	outStats.clear();
	outStats.clearItems();

	unsigned int lPopSize = 0;
	for(unsigned int i=0; i<ioVivarium.size(); ++i) {
		Beagle::Stats::Handle lDemeStats = ioVivarium[i]->getStats();
		Beagle_NonNullPointerAssertM(lDemeStats);
		lPopSize += lDemeStats->getPopSize();
	}
	outStats.setGenerationValues("vivarium", ioContext.getGeneration(), lPopSize, true);
	outStats.addItem("processed", ioContext.getProcessedVivarium());
	outStats.addItem("total-processed", ioContext.getTotalProcessedVivarium());

	if(ioVivarium.size() == 0) return;

	outStats.resize(ioVivarium[0]->getStats()->size());
	for(unsigned int i=0; i<outStats.size(); ++i) {
		double lSumXi     = 0.0;
		double lSumXiPow2 = 0.0;
		double lMax       = (*ioVivarium[0]->getStats())[i].mMax;
		double lMin       = (*ioVivarium[0]->getStats())[i].mMin;

		for(unsigned int j=0; j<ioVivarium.size(); ++j) {
			Beagle_AssertM(outStats.size() == ioVivarium[j]->getStats()->size());
			const Measure& lMeasure  = (*ioVivarium[j]->getStats())[i];
			unsigned int   lDemeSize = ioVivarium[j]->getStats()->getPopSize();
			if(lDemeSize != 0) {
				double lSumFit  =  lMeasure.mAvg * lDemeSize;
				double lTmpVar1 =  pow2Of<double>(lSumFit) / lDemeSize;
				double lTmpVar2 =  pow2Of<double>(lMeasure.mStd) * (lDemeSize-1);
				lSumXi          += lSumFit;
				lSumXiPow2      += lTmpVar1 + lTmpVar2;
				lMax            =  maxOf<double>(lMax, lMeasure.mMax);
				lMin            =  minOf<double>(lMin, lMeasure.mMin);
			}
		}

		outStats[i].mID  = (*ioVivarium[0]->getStats())[i].mID;
		if(lPopSize == 0) {
			outStats[i].mAvg = 0.0;
			outStats[i].mStd = 0.0;
			outStats[i].mMax = 0.0;
			outStats[i].mMin = 0.0;
		} else if(lPopSize == 1) {
			outStats[i].mAvg = lSumXi;
			outStats[i].mStd = 0.0;
			outStats[i].mMax = lMax;
			outStats[i].mMin = lMin;
		} else {
			double lAverage  = lSumXi / lPopSize;
			double lVariance =
			    lSumXiPow2 - (pow2Of<double>(lAverage*((double)lPopSize)) / ((double)lPopSize));
			double lStdError = sqrt(lVariance / (lPopSize - 1));
			outStats[i].mAvg = lAverage;
			outStats[i].mStd = lStdError;
			outStats[i].mMax = lMax;
			outStats[i].mMin = lMin;
		}
	}
	Beagle_StackTraceEndM("void StatsCalculateOp::calculateStatsVivarium(Stats& outStats, Vivarium& ioVivarium, Context& ioContext) const");
}
Beispiel #6
0
	void render(/*double currentTime*/)
	{
		currentTime += time_offset;


		static const GLfloat color[] = { 0.0f, 0.0f, 0.0f, 0.0f };

		float r = 0.0f;

		float t = (float)currentTime;

		r = t + time_offset;

		glm::vec2 C(
				(sinf(r * 0.1f) + cosf(r * 0.53f)) * 2.5f,
				(cosf(r * 0.13f) + sinf(r * 0.21f)) * 0.5f
			   );


		i++;
		if((i % 100) == 0) {

			if(1) {
				int total = 0;
				int count = 0;
				int it_max = -1;
				int it_min = max_iterations + 1;
				int skip = 10;
				float a;
				float log_a_min = FLT_MAX;
				float log_a_max = FLT_MIN;

				stat_a.clear();

				for(int px = 0; px < iscreen.x; px+=skip) {
					for(int py = 0; py < iscreen.y; py+=skip) {
						if(debug) {
							if((count%10)==0) {
								printf("%6s%6s%12s%12s%12s%12s%12s%6s%12s%12s%12s\n", 
										"px", "py",
										"zoom",
										"f", "f",
										"x", "y",
										"it",
										"a",
										"log(a)",
										"a0");
							}}

						int it = solve(glm::ivec2(px,py), C, a);

						count++;
						total += it;
						if(it > it_max) it_max = it;
						if(it < it_min) it_min = it;

						//printf("%f\n",a);
						stat_a.push(a);
						//printf("%f\n",a);
						if(isinf(a)) {
							stat_log_a.push((float)FLT_MAX_EXP);
						} else {
							stat_log_a.push(log(a));
						}
					}
				}

				log_a_min = stat_log_a.min();
				log_a_max = stat_log_a.max();
				if(isinf(log_a_max)) {
					printf("inf log %f\n", (float)FLT_MAX_EXP);
					log_a_max = FLT_MAX_EXP;
				}

				printf("%8s%8s%8s%8s%8s%12s%12s%12s%12s%12s%12s\n",
						"count",
						"total",
						"avg",
						"it_min",
						"it_max",
						"a_min",
						"a_max",
						"log a_min",
						"log a_max",
						"avg log_a",
						"std log_a"
				      );
				printf("%8i%8i%8.2f%8i%8i%12.2e%12.2e%12.2e%12.2e%12.2e%12.2e\n",
						count,
						total,
						(float)total/(float)count,
						it_min,
						it_max,
						stat_a.min(),
						stat_a.max(),
						log_a_min,
						log_a_max,
						stat_log_a.avg(),
						stat_log_a.std());
			}



			printf("%12s%12s\n","zoom","time");
			printf("%12.2e%12.2f\n",zoom,currentTime);
		}

		float offset[2] = { x_offset, y_offset };

		// rendering part
		glClearBufferfv(GL_COLOR, 0, color);

		glUseProgram(program);

		glUniform2fv(uniforms.C, 1, &C[0]);
		glUniform2fv(uniforms.offset, 1, offset);
		glUniform2fv(uniforms.screen, 1, &screen.x);
		glUniform1f(uniforms.zoom, zoom);
		glUniform1i(uniforms.iter, max_iterations);
		glUniform1i(uniforms.mode, mode);
		glUniform1f(uniforms.damp, damp);
		glUniform1f(uniforms.log_a_min, log_a_min);
		glUniform1f(uniforms.log_a_max, log_a_max);

		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

		glutSwapBuffers();
	}