112#include <vigra/accumulator.hxx>
113#include <vigra/multi_math.hxx>
115#include <vigra/multi_fft.hxx>
129 template <
typename IN ,
typename OUT >
130 void eval (
const IN & in , OUT & out )
const
136int main (
int argc ,
char * argv[] )
138 std::cout << std::fixed << std::showpoint
140 (std::numeric_limits<double>::max_digits10) ;
144 std::cerr <<
"pass the spline's degree and the number of iterations"
146 <<
"and, optionally, the cutoff frequency"
151 int degree = std::atoi ( argv[1] ) ;
153 assert ( degree >= 0 && degree <= vspline_constants::max_degree ) ;
155 int iterations = std::max ( 1 , std::atoi ( argv[2] ) ) ;
157 double f_cutoff = .5 ;
160 f_cutoff = std::atof ( argv[3] ) ;
161 std::cout <<
"using frequency cutoff " << f_cutoff << std::endl ;
164 const std::size_t sz = 1024 ;
166 vigra::MultiArray < 1 , double > signal ( sz ) ;
167 vigra::MultiArray < 1 , double > target ( sz ) ;
169 vigra::MultiArray < 1 , vigra::FFTWComplex<double> >
170 fourier ( signal.shape() / 2 + 1 ) ;
172 std::random_device rd ;
173 std::mt19937 gen ( rd() ) ;
175 std::uniform_real_distribution<> dis ( -1 , 1 ) ;
181 for (
auto & e : fourier )
183 if ( fill < f_cutoff * sz / 2.0 )
184 e = vigra::FFTWComplex<double> ( dis(gen) , dis(gen) ) ;
186 e = vigra::FFTWComplex<double> ( 0.0 , 0.0 ) ;
192 vigra::fourierTransformInverse ( fourier , signal ) ;
210 using namespace vigra::multi_math ;
211 using namespace vigra::acc;
213 vigra::MultiArray < 1 , double > error_array
214 ( vigra::multi_math::squaredNorm ( bspw.
core ) ) ;
216 AccumulatorChain < double , Select < Mean, Maximum > > ac ;
217 extractFeatures ( error_array.begin() , error_array.end() , ac ) ;
219 std::cout <<
"coefficients Mean: "
220 << sqrt(get<Mean>(ac)) << std::endl;
221 std::cout <<
"coefficients Maximum: "
222 << sqrt(get<Maximum>(ac)) << std::endl;
236 double cumulated_offset = 0.0 ;
238 for (
int n = 0 ; n < iterations ; n++ )
244 double offset = 1000.0 * dis ( gen ) ;
251 if ( n == iterations - 1 )
252 offset = - cumulated_offset ;
254 cumulated_offset += offset ;
256 if ( n > ( iterations - 10 ) )
257 std::cout <<
"iteration " << n <<
" offset " << offset
258 <<
" cumulated offset " << cumulated_offset << std::endl ;
301 vigra::MultiArray < 1 , double > error_array
302 ( vigra::multi_math::squaredNorm ( target - signal ) ) ;
304 AccumulatorChain < double , Select < Mean, Maximum > > ac ;
305 extractFeatures ( error_array.begin() , error_array.end() , ac ) ;
307 if ( n > ( iterations - 10 ) )
309 if ( n == iterations - 1 )
310 std::cout <<
"final result, evaluating at signal unit steps" << std::endl ;
311 std::cout <<
"signal difference Mean: "
312 << sqrt(get<Mean>(ac)) << std::endl;
313 std::cout <<
"signal difference Maximum: "
314 << sqrt(get<Maximum>(ac)) << std::endl;
int main(int argc, char *argv[])
void transform(const unary_functor_type &functor, const vigra::MultiArrayView< dimension, typename unary_functor_type::in_type > &input, vigra::MultiArrayView< dimension, typename unary_functor_type::out_type > &output, int njobs=vspline::default_njobs, vspline::atomic< bool > *p_cancel=0)
implementation of two-array transform using wielding::coupled_wield.
vspline::grok_type< bspl_coordinate_type< spline_type, rc_type >, result_type, _vsize > make_safe_evaluator(const spline_type &bspl, vigra::TinyVector< int, spline_type::dimension > dspec=vigra::TinyVector< int, spline_type::dimension >(0), int shift=0)
make_safe_evaluator is a factory function, producing a functor which provides safe access to an evalu...
invoke with: bls <spline degree> <number of iterations> \ [ <frequency cutoff> ]
offset_f(const double &_offset)
void eval(const IN &in, OUT &out) const
class bspline now builds on class bspline_base, adding coefficient storage, while bspline_base provid...
void prefilter(vspline::xlf_type boost=vspline::xlf_type(1), int njobs=vspline::default_njobs)
prefilter converts the knot point data in the 'core' area into b-spline coefficients....
class unary_functor provides a functor object which offers a system of types for concrete unary funct...
includes all headers from vspline (most of them indirectly)