Beispiel #1
0
void Toolbox::calculateGlobalMeanAndStd(DataSet &X,dVector& mean,dVector& stdDev)
{
	calculateGlobalMean(X,mean);
	int nbElements = 0;

	//Calculate standard deviation
	stdDev.set(0);
	for(int i = 0;i < (int)X.size() ;i++)
	{
		double* pData = X.at(i)->getPrecomputedFeatures()->get();
		int Width = X.at(i)->getPrecomputedFeatures()->getWidth();
		int Height = X.at(i)->getPrecomputedFeatures()->getHeight();

		for(int col=0; col < Width; col++)
		{
			double* pStdDev = stdDev.get();
			double* pMean = mean.get();
			for(int row = 0; row < Height;row++)
			{
				*pStdDev += (*pData-*pMean) * (*pData-*pMean);
				pStdDev++;
				pData++;
				pMean++;
			}
		}
		nbElements+=Width;
	}
	stdDev.multiply(1.0/(double)nbElements);
	stdDev.eltSqrt();
}
Beispiel #2
0
//Compute gradient
void UnconstrainedOptimizer::G()
{
	dVector dgrad(n);
	memcpy(vecGradient.get(),x,n*sizeof(double));
	currentModel->setWeights(vecGradient);
	if(currentModel->getDebugLevel() >= 2)
		std::cout << "Compute gradient..." << std::endl;
	currentGradient->computeGradient(dgrad, currentModel,currentDataset);
	memcpy(g,dgrad.get(),n*sizeof(double));
}
Beispiel #3
0
// Compute error function
void UnconstrainedOptimizer::F()
{
	memcpy(vecGradient.get(),x,n*sizeof(double));
	currentModel->setWeights(vecGradient);

	if(currentModel->getDebugLevel() >= 2)
		std::cout << "Compute error..." << std::endl;
	f = currentEvaluator->computeError(currentDataset, currentModel);
	if(currentModel->getDebugLevel() >= 3)
	{
//		printf("  Iteration # = %i   Nb error eval = %i   Nb gradient eval =  %i\n\n", cnls, cnf, cng);
//		printf("F = %-0.10lg\n",f);
		std::cout << "  Iteration # = " << cnls << "   Nb error eval = " <<cnf << "   Nb gradient eval =  " << cng <<std::endl << std::endl;
		std::cout << "F = " << f << std::endl;
		std::cout.flush();
	}
	
}