ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itk::CacheableScalarFunction Class Reference

#include <itkCacheableScalarFunction.h>

Detailed Description

function cache implementation

This is the base class for continuous scalar functions which needs cache for their pre-evaluated function returns.

The internal cache is created using the upper- and lower-bound domain values of the functional form (f(x))of subclasses of this class. So the cache only stores pre-evaluated values between f(lower-bound) and f(upper-bound).

To create a cache for continuous function, it uses sampling. With the given sample number , upper-bound, and lower-bound, it calculates interval within the ranges. It pre-evaluates and save f(x) where x = lower-bound + interval * [0 - sample number]

If a subclass of this class want to use a cache, it should explicitly call CreateCache(...) member function. GetCachedValue(x) will return pre-evaluated f(x) value. However, the return value from GetCachedValue(x) might be different from the exact return value from f(x) which is Evaluate(x) member function of subclasses of this class, because The GetCachedValue(x) member function internally converts x to cache table index and the conversion involves with truncation. So, users can think the cached value as an approximate to exact function return.

In some case, approximate values can be useful. For example, CompositeValleyFunction can be used as an M-estimator and it is currently used for MRIBiasFieldCorrectionFilter as an energy function. The bias field estimation requires calculation of energy values again and again for each iteration.

Definition at line 60 of file itkCacheableScalarFunction.h.

+ Inheritance diagram for itk::CacheableScalarFunction:
+ Collaboration diagram for itk::CacheableScalarFunction:

Public Types

using MeasureArrayType = Array<MeasureType>
 
using MeasureType = double
 

Public Member Functions

 CacheableScalarFunction ()
 
virtual MeasureType Evaluate (MeasureType x)
 
MeasureType GetCachedValue (MeasureType x)
 
double GetCacheLowerBound () const
 
double GetCacheUpperBound () const
 
double GetInterval () const
 
SizeValueType GetNumberOfSamples () const
 
bool IsCacheAvailable () const
 
virtual ~CacheableScalarFunction ()
 

Protected Member Functions

void CreateCache (double lowerBound, double upperBound, SizeValueType sampleSize)
 

Private Attributes

bool m_CacheAvailable { false }
 
double m_CacheLowerBound { 0.0 }
 
MeasureArrayType m_CacheTable {}
 
double m_CacheUpperBound { 0.0 }
 
SizeValueType m_NumberOfSamples { 0 }
 
double m_TableInc { 0.0 }
 

Member Typedef Documentation

◆ MeasureArrayType

◆ MeasureType

Function's input and output value type.

Definition at line 70 of file itkCacheableScalarFunction.h.

Constructor & Destructor Documentation

◆ CacheableScalarFunction()

itk::CacheableScalarFunction::CacheableScalarFunction ( )

Constructor.

◆ ~CacheableScalarFunction()

virtual itk::CacheableScalarFunction::~CacheableScalarFunction ( )
virtual

Destructor.

Member Function Documentation

◆ CreateCache()

void itk::CacheableScalarFunction::CreateCache ( double lowerBound,
double upperBound,
SizeValueType sampleSize )
protected

Create the internal cache table and fill it with pre-evaluated values.

◆ Evaluate()

virtual MeasureType itk::CacheableScalarFunction::Evaluate ( MeasureType x)
virtual

y = f(x) Subclasses of this class should override this member function to provide their own functional operation .

Reimplemented in itk::CompositeValleyFunction.

◆ GetCachedValue()

MeasureType itk::CacheableScalarFunction::GetCachedValue ( MeasureType x)
inline

y = f(x) = (approximately) cache_table(index(x)) Get the function return using the internal cache table NOTE: Since the index calculation needs conversion from double to int, truncation happens. As a result, the return values from Evaluate(x) and GetCachedValue(x) may not be same for the same x.

Definition at line 121 of file itkCacheableScalarFunction.h.

References m_CacheLowerBound, m_CacheTable, m_CacheUpperBound, and m_TableInc.

Referenced by itk::CompositeValleyFunction::operator()().

◆ GetCacheLowerBound()

double itk::CacheableScalarFunction::GetCacheLowerBound ( ) const
inline

Get the lower-bound of domain that is used for filling the cache table.

Definition at line 97 of file itkCacheableScalarFunction.h.

References m_CacheLowerBound.

◆ GetCacheUpperBound()

double itk::CacheableScalarFunction::GetCacheUpperBound ( ) const
inline

Get the upper-bound of domain that is used for filling the cache table.

Definition at line 90 of file itkCacheableScalarFunction.h.

References m_CacheUpperBound.

◆ GetInterval()

double itk::CacheableScalarFunction::GetInterval ( ) const
inline

Gets the interval of each cell between the upper and lower bound

Definition at line 110 of file itkCacheableScalarFunction.h.

References m_TableInc.

◆ GetNumberOfSamples()

SizeValueType itk::CacheableScalarFunction::GetNumberOfSamples ( ) const
inline

Get the number of samples between the lower-bound and upper-bound of the cache table.

Definition at line 76 of file itkCacheableScalarFunction.h.

References m_NumberOfSamples.

◆ IsCacheAvailable()

bool itk::CacheableScalarFunction::IsCacheAvailable ( ) const
inline

Check if the internal cache table and its values are valid.

Definition at line 83 of file itkCacheableScalarFunction.h.

References m_CacheAvailable.

Referenced by itk::CompositeValleyFunction::operator()().

Member Data Documentation

◆ m_CacheAvailable

bool itk::CacheableScalarFunction::m_CacheAvailable { false }
private

Is the cache available?

Definition at line 156 of file itkCacheableScalarFunction.h.

Referenced by IsCacheAvailable().

◆ m_CacheLowerBound

double itk::CacheableScalarFunction::m_CacheLowerBound { 0.0 }
private

The lower-bound of domain that is used for filling the cache table.

Definition at line 150 of file itkCacheableScalarFunction.h.

Referenced by GetCachedValue(), and GetCacheLowerBound().

◆ m_CacheTable

MeasureArrayType itk::CacheableScalarFunction::m_CacheTable {}
private

Storage for the precalculated function values.

Definition at line 144 of file itkCacheableScalarFunction.h.

Referenced by GetCachedValue().

◆ m_CacheUpperBound

double itk::CacheableScalarFunction::m_CacheUpperBound { 0.0 }
private

The upper-bound of domain that is used for filling the cache table.

Definition at line 147 of file itkCacheableScalarFunction.h.

Referenced by GetCachedValue(), and GetCacheUpperBound().

◆ m_NumberOfSamples

SizeValueType itk::CacheableScalarFunction::m_NumberOfSamples { 0 }
private

The number of samples will be precalculated and saved in the cache table.

Definition at line 141 of file itkCacheableScalarFunction.h.

Referenced by GetNumberOfSamples().

◆ m_TableInc

double itk::CacheableScalarFunction::m_TableInc { 0.0 }
private

Sampling interval for function evaluation.

Definition at line 153 of file itkCacheableScalarFunction.h.

Referenced by GetCachedValue(), and GetInterval().


The documentation for this class was generated from the following file: