|
@@ -4,7 +4,7 @@
|
|
// Optimizer class.
|
|
// Optimizer class.
|
|
//
|
|
//
|
|
// Written by Matthias Wacker
|
|
// Written by Matthias Wacker
|
|
-//
|
|
|
|
|
|
+// edited by Johannes Ruehle, 2012-10-11
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
#include "optimization/DerivativeBasedOptimizer.h"
|
|
#include "optimization/DerivativeBasedOptimizer.h"
|
|
@@ -63,24 +63,25 @@ const matrix_type DerivativeBasedOptimizer::getNumericalGradient(const matrix_t
|
|
|
|
|
|
for(int i=0; i < static_cast<int>(m_numberOfParameters);i++)
|
|
for(int i=0; i < static_cast<int>(m_numberOfParameters);i++)
|
|
{
|
|
{
|
|
- for(int j = 0 ; j< 2 * static_cast<int>(m_numberOfParameters);j++)
|
|
|
|
- {
|
|
|
|
- grid[i][j] = x[i][0] + ((j == i)? maskWidth[i][0] : 0.0)
|
|
|
|
- + ((j == i+1)? maskWidth[i][0] *(-1.0): 0.0);
|
|
|
|
- }
|
|
|
|
|
|
+ for(int j = 0 ; j< 2 * static_cast<int>(m_numberOfParameters);j++)
|
|
|
|
+ {
|
|
|
|
+ grid[i][j] = x[i][0] + (( j == i*2 )? +maskWidth[i][0] : 0.0)
|
|
|
|
+ + (( j == i*2+1 )? -maskWidth[i][0] : 0.0);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
matrix_type values = evaluateSetCostFunction(grid);
|
|
matrix_type values = evaluateSetCostFunction(grid);
|
|
|
|
|
|
for(int i=0; i < static_cast<int>(m_numberOfParameters);i++)
|
|
for(int i=0; i < static_cast<int>(m_numberOfParameters);i++)
|
|
{
|
|
{
|
|
- grad[i][0] = ( values[i][0] - values[i+1][0] )/( 2 * maskWidth[i][0]);
|
|
|
|
|
|
+ if(m_scales[i][0] == 0 )
|
|
|
|
+ {
|
|
|
|
+ grad[i][0] = 0;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ grad[i][0] = ( values[2*i][0] - values[2*i+1][0] )/( 2 * maskWidth[i][0]);
|
|
|
|
|
|
- if(m_scales[i][0] == 0 )
|
|
|
|
- {
|
|
|
|
- grad[i][0] = 0;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
return grad;
|
|
return grad;
|