renamed DE::Engine::CalculateError to DE::Engine::TestFitness
added ErrorAccumulator to aid in calculating RMSE converted piecewiseapprox.cpp and polyapprox.cpp to use new pure virtual method name and ErrorAccumulator
This commit is contained in:
1 parent
6f03c0b106
commit
aac0b98ba9
4 files changed
+91
-34
No files matched your search
@@ -207,7 +207,7 @@ bool DE::Engine<DIM,POPSIZE>::RunOneGeneration()
|
||||
MakeTrial_randtobest1exp(candidate,trial);
|
||||
|
||||
// determine fitness of trial individual
|
||||
double trialfitness = CalculateError(trial,success);
|
||||
double trialfitness = TestFitness(trial,success);
|
||||
|
||||
// see if the trial improved current candidate in population
|
||||
if ( trialfitness < fitness[candidate] )
|
||||
@@ -448,5 +448,55 @@ inline void DE::Engine<DIM,POPSIZE>::MakeTrial_rand2bin(unsigned int candidate,
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <unsigned int DIM, unsigned int POPSIZE>
|
||||
inline DE::Engine<DIM,POPSIZE>::ErrorAccumulator::ErrorAccumulator()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
template <unsigned int DIM, unsigned int POPSIZE>
|
||||
inline DE::Engine<DIM,POPSIZE>::ErrorAccumulator::~ErrorAccumulator()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
template <unsigned int DIM, unsigned int POPSIZE>
|
||||
inline void DE::Engine<DIM,POPSIZE>::ErrorAccumulator::Clear()
|
||||
{
|
||||
num_tests = 0;
|
||||
sum_error_squared = 0.0;
|
||||
error_rmse = 0.0; // initial error == zero
|
||||
}
|
||||
|
||||
template <unsigned int DIM, unsigned int POPSIZE>
|
||||
inline void DE::Engine<DIM,POPSIZE>::ErrorAccumulator::AddTestCase(double expected, double actual)
|
||||
{
|
||||
double e = expected - actual; // compute error
|
||||
sum_error_squared += e * e; // add to sum of error^2
|
||||
num_tests += 1; // increment total test count
|
||||
error_rmse = -1.0; // mark as dirty
|
||||
}
|
||||
|
||||
template <unsigned int DIM, unsigned int POPSIZE>
|
||||
inline double DE::Engine<DIM,POPSIZE>::ErrorAccumulator::GetRMSE()
|
||||
{
|
||||
if ( error_rmse < 0.0 ) // recalculate if set to "dirty"
|
||||
CalculateError();
|
||||
|
||||
return error_rmse;
|
||||
}
|
||||
|
||||
template <unsigned int DIM, unsigned int POPSIZE>
|
||||
inline void DE::Engine<DIM,POPSIZE>::ErrorAccumulator::CalculateError()
|
||||
{
|
||||
// convert squared error to root mean squared error
|
||||
error_rmse = sqrt(sum_error_squared / (double)num_tests);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // __de_inl__
|
||||
|
||||
Reference in new issue
Block a user