Search a grid for maxima (global or local) More...
#include <GridSearch.h>
Public Member Functions | |
| double | globalMax () |
| GridSearch () | |
| Function2MaximaIterator | localMax (int nMax, double absThres=0.0, double relThres=0.0) |
| int | nx () const |
| int | ny () const |
| void | setAbsolutePrecision (double p) |
| void | setGrid (double minX, double maxX, double dX, double minY, double maxY, double dY) |
| void | setRelativePrecision (double p) |
| double | x (int i) const |
| double | y (int i) const |
| ~GridSearch () | |
Protected Attributes | |
| int | _nx |
| int | _ny |
| double | _precisionX |
| double | _precisionY |
| double * | _x |
| double * | _y |
Search a grid for maxima (global or local)
References _nx, _ny, _precisionX, _precisionY, _x, _y, and TRACE.
{
TRACE;
_precisionX=0.001;
_precisionY=0.001;
_nx=0;
_ny=0;
_x=0;
_y=0;
}
| double QGpCoreTools::GridSearch::globalMax | ( | ) |
Search all grid for its maximum and refine it
References QGpCoreTools::Function2Search::_function, _nx, _ny, QGpCoreTools::Function2Search::_pos, _x, _y, QGpCoreTools::Function2Search::highLimit(), QGpCoreTools::Function2Search::lowLimit(), QGpCoreTools::Point2D::setY(), TRACE, and QGpCoreTools::AbstractFunction2::value().
Referenced by ToolNR::t0Apply().
{
TRACE;
int maxix=0, maxiy=0;
double val,maxVal=-1e99;
int k=0;
for(int iy=0;iy<_ny;iy++) {
for(int ix=0;ix<_nx;ix++, k++) {
val=_function->value(_x[ix], _y[iy], k);
if(val>maxVal) {
maxVal=val;
maxix=ix;
maxiy=iy;
}
}
}
// Refine search by recursion and re-regridding
if(_ny==1) {
_pos.setY(_y[0]);
return refineMax(lowLimit(maxix, _x),highLimit(maxix, _x, _nx));
}
else return refineMax(lowLimit(maxix, _x), highLimit(maxix, _x, _nx),
lowLimit(maxiy, _y), highLimit(maxiy, _y, _ny));
}
| Function2MaximaIterator QGpCoreTools::GridSearch::localMax | ( | int | nMax, |
| double | absThres = 0.0, |
||
| double | relThres = 0.0 |
||
| ) |
Reimplemented from QGpCoreTools::Function2Search.
References QGpCoreTools::Function2Search::_function, QGpCoreTools::Function2Search::_localMaxima, _nx, _ny, QGpCoreTools::Function2Search::_pos, _x, _y, TRACE, and QGpCoreTools::AbstractFunction2::value().
Referenced by FKLoopTask::exportMax().
{
TRACE;
double * map=new double [_nx*_ny];
int k=0;
int iy;
for(iy=0;iy<_ny;iy++) {
for(int ix=0;ix<_nx;ix++,k++) {
map[k]=_function->value(_x[ix], _y[iy], k);
}
}
_localMaxima.clear();
int nxm=_nx-1;
int nym=_ny-1;
k=_nx+1;
for(iy=1;iy<nym;iy++) {
for(int ix=1;ix<nxm;ix++,k++) {
if(map[k-1]>0 && map[k]>map[k-1] &&
map[k+1]>0 && map[k]>map[k+1] &&
map[k-_nx-1]>0 && map[k]>map[k-_nx-1] &&
map[k-_nx]>0 && map[k]>map[k-_nx] &&
map[k-_nx+1]>0 && map[k]>map[k-_nx+1] &&
map[k+_nx-1]>0 && map[k]>map[k+_nx-1] &&
map[k+_nx]>0 && map[k]>map[k+_nx] &&
map[k+_nx+1]>0 && map[k]>map[k+_nx+1]) {
double val=refineMax(_x[ix-1],_x[ix+1], _y[iy-1],_y[iy+1]);
_localMaxima.append(Function2SearchMaximum(val, _pos));
}
}
k+=2;
}
delete [] map;
return Function2Search::localMax(nMax, absThres, relThres);
}
| int QGpCoreTools::GridSearch::nx | ( | ) | const [inline] |
Referenced by QGpCoreTools::IrregularGrid2DData::operator=(), and setGrid().
{return _nx;}
| int QGpCoreTools::GridSearch::ny | ( | ) | const [inline] |
Referenced by QGpCoreTools::IrregularGrid2DData::operator=(), and setGrid().
{return _ny;}
| void QGpCoreTools::GridSearch::setAbsolutePrecision | ( | double | p | ) | [inline] |
Referenced by T0GridSearch::setGrid().
{_precisionX=p;_precisionY=p; _relative=false;}
| void QGpCoreTools::GridSearch::setGrid | ( | double | minX, |
| double | maxX, | ||
| double | dX, | ||
| double | minY, | ||
| double | maxY, | ||
| double | dY | ||
| ) |
References QGpCoreTools::Function2Search::_function, _nx, _ny, _x, _y, QGpCoreTools::AbstractFunction2::initGrid(), nx(), ny(), and TRACE.
Referenced by RealTimeArrayProcess::setWavenumberRange().
{
TRACE;
ASSERT(_function);
int nx=(int)round((maxX-minX)/dX)+1;
int ny=(int)round((maxY-minY)/dY)+1;
if (nx!=_nx) {
delete [] _x;
_x=new double [nx];
_nx=nx;
}
if(ny!=_ny) {
delete [] _y;
_y=new double [ny];
_ny=ny;
}
for(int i=0;i<_nx;i++) _x[i]=minX+dX*(double)i;
for(int i=0;i<_ny;i++) _y[i]=minY+dY*(double)i;
_function->initGrid(_nx * _ny);
int k=0;
for(int iy=0;iy<_ny;iy++) {
for(int ix=0;ix<_nx;ix++, k++) {
_function->initGrid(_x[ix], _y[iy], k);
}
}
}
| void QGpCoreTools::GridSearch::setRelativePrecision | ( | double | p | ) | [inline] |
Referenced by ArrayCore::FKGridSearch::FKGridSearch().
{_precisionX=p;_precisionY=p; _relative=true;}
| double QGpCoreTools::GridSearch::x | ( | int | i | ) | const [inline] |
Referenced by QGpCoreTools::IrregularGrid2DData::operator=().
{return _x[i];}
| double QGpCoreTools::GridSearch::y | ( | int | i | ) | const [inline] |
Referenced by QGpCoreTools::IrregularGrid2DData::operator=().
{return _y[i];}
int QGpCoreTools::GridSearch::_nx [protected] |
Referenced by globalMax(), GridSearch(), localMax(), and setGrid().
int QGpCoreTools::GridSearch::_ny [protected] |
Referenced by globalMax(), GridSearch(), localMax(), and setGrid().
double QGpCoreTools::GridSearch::_precisionX [protected] |
Referenced by GridSearch().
double QGpCoreTools::GridSearch::_precisionY [protected] |
Referenced by GridSearch().
double* QGpCoreTools::GridSearch::_x [protected] |
Referenced by globalMax(), GridSearch(), localMax(), setGrid(), and ~GridSearch().
double * QGpCoreTools::GridSearch::_y [protected] |
Referenced by globalMax(), GridSearch(), localMax(), setGrid(), and ~GridSearch().