Skip to content
Snippets Groups Projects
Commit f6e39f22 authored by Pavel Burovskiy's avatar Pavel Burovskiy
Browse files

Updating expression evaluator with additive gaussian noise function

git-svn-id: https://gforge.sci.utah.edu/svn/nektar/trunk@3904 305cdda6-5ce1-45b3-a98d-dfc68c8b3305
parent c41563d2
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,21 @@ namespace Nektar
return (arg > 0.0) - (arg < 0.0);
}
// Additive white Gaussian noise function.
// Arg: sigma of the zero-mean gaussian distribution
// Attention: this function is not actually used for
// evaluation purposes.
double awgn(double sigma)
{
AnalyticExpressionEvaluator::RandomGeneratorType rng;
boost::variate_generator<
AnalyticExpressionEvaluator::RandomGeneratorType&,
boost::normal_distribution<>
> _normal(rng, boost::normal_distribution<>(0, sigma) );
return _normal();
}
/** This struct creates a parser that matches the function
definitions from math.h. All of the functions accept one
of more doubles as arguments and returns a double. **/
......@@ -146,6 +161,7 @@ namespace Nektar
("tanh", tanh)
// and one more
("sign", sign)
("awgn", awgn)
;
}
} functions_p;
......@@ -218,10 +234,12 @@ namespace Nektar
// =========================================================================
// \brief Initializes the evaluator. Call DefineFunction(...) next.
AnalyticExpressionEvaluator::AnalyticExpressionEvaluator():
AnalyticExpressionEvaluator::AnalyticExpressionEvaluator(int seed = 123u):
m_total_eval_time(0),
m_timer()
m_timer(),
m_normal(m_generator, boost::normal_distribution<>(0, 1) )
{
m_generator.seed(seed);
m_state_size = 1;
AddConstant("MEANINGLESS", 0.0);
......@@ -260,6 +278,7 @@ namespace Nektar
m_functionMapNameToInstanceType["tan"] = E_TAN;
m_functionMapNameToInstanceType["tanh"] = E_TANH;
m_functionMapNameToInstanceType["sign"] = E_SIGN;
m_functionMapNameToInstanceType["awgn"] = E_AWGN;
m_function[ E_ABS ] = std::abs;
m_function[ E_ASIN ] = asin;
......@@ -279,6 +298,8 @@ namespace Nektar
m_function[ E_TAN ] = tan;
m_function[ E_TANH ] = tanh;
m_function[ E_SIGN ] = sign;
// there is no entry to m_function that correspond to awgn function.
// this is made in purpose. This function need not be pre-evaluated once!
}
AnalyticExpressionEvaluator::~AnalyticExpressionEvaluator(void)
......@@ -712,12 +733,22 @@ namespace Nektar
PrecomputedValue v = PrepareExecutionAsYouParse(location->children.begin(), stack, variableMap, stateIndex);
// random noise function
if (it->second == E_AWGN)
{
int const_index = AddConstant(std::string("SUB_EXPR_") + boost::lexical_cast<std::string>(m_constant.size()), v.second);
stack.push_back ( makeStep<StoreConst>( stateIndex, const_index ) );
stack.push_back ( makeStep<EvalAWGN>( stateIndex, stateIndex ) );
return std::make_pair(false,0);
}
// if precomputed value is valid, return function(value).
if (true == v.first)
{
return std::make_pair( true, m_function[it->second](v.second) );
}
// if somewhere down the parse tree there is a variable or parameter, set up an
// evaluation sequence.
switch (it->second)
......@@ -737,7 +768,7 @@ namespace Nektar
case E_CEIL:
stack.push_back ( makeStep<EvalCeil>( stateIndex, stateIndex ) );
return std::make_pair(false,0);
case E_COS:
case E_COS:
stack.push_back ( makeStep<EvalCos>( stateIndex, stateIndex ) );
return std::make_pair(false,0);
case E_COSH:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment