Vowpal Wabbit
Functions
ldamath Namespace Reference

Functions

float fastlog2 (float x)
 
float fastlog (float x)
 
float fastpow2 (float p)
 
float fastexp (float p)
 
float fastpow (float x, float p)
 
float fastlgamma (float x)
 
float fastdigamma (float x)
 
template<typename T , const lda_math_mode mtype>
lgamma (T)
 
template<typename T , const lda_math_mode mtype>
digamma (T)
 
template<typename T , lda_math_mode mtype>
exponential (T)
 
template<typename T , lda_math_mode mtype>
powf (T, T)
 
template<>
float lgamma< float, USE_PRECISE > (float x)
 
template<>
float digamma< float, USE_PRECISE > (float x)
 
template<>
float exponential< float, USE_PRECISE > (float x)
 
template<>
float powf< float, USE_PRECISE > (float x, float p)
 
template<>
float lgamma< float, USE_FAST_APPROX > (float x)
 
template<>
float digamma< float, USE_FAST_APPROX > (float x)
 
template<>
float exponential< float, USE_FAST_APPROX > (float x)
 
template<>
float powf< float, USE_FAST_APPROX > (float x, float p)
 
template<>
float lgamma< float, USE_SIMD > (float x)
 
template<>
float digamma< float, USE_SIMD > (float x)
 
template<>
float exponential< float, USE_SIMD > (float x)
 
template<>
float powf< float, USE_SIMD > (float x, float p)
 
template<typename T , const lda_math_mode mtype>
void expdigammify (vw &all, T *gamma, T threshold, T initial)
 
template<>
void expdigammify< float, USE_SIMD > (vw &all, float *gamma, float threshold, float)
 
template<typename T , const lda_math_mode mtype>
void expdigammify_2 (vw &all, float *gamma, T *norm, const T threshold)
 
template<>
void expdigammify_2< float, USE_SIMD > (vw &all, float *gamma, float *norm, const float threshold)
 

Function Documentation

◆ digamma()

template<typename T , const lda_math_mode mtype>
T ldamath::digamma ( )
inline

Definition at line 414 of file lda_core.cc.

Referenced by digamma< float, USE_PRECISE >().

415 {
416  BOOST_STATIC_ASSERT_MSG(true, "ldamath::digamma is not defined for this type and math mode.");
417 }

◆ digamma< float, USE_FAST_APPROX >()

template<>
float ldamath::digamma< float, USE_FAST_APPROX > ( float  x)
inline

Definition at line 464 of file lda_core.cc.

References fastdigamma().

Referenced by lda::digamma(), and digamma< float, USE_SIMD >().

465 {
466  return fastdigamma(x);
467 }
float fastdigamma(float x)
Definition: lda_core.cc:172

◆ digamma< float, USE_PRECISE >()

template<>
float ldamath::digamma< float, USE_PRECISE > ( float  x)
inline

Definition at line 441 of file lda_core.cc.

References digamma().

Referenced by lda::digamma().

442 {
443  return boost::math::digamma(x);
444 }
T digamma(T)
Definition: lda_core.cc:414

◆ digamma< float, USE_SIMD >()

template<>
float ldamath::digamma< float, USE_SIMD > ( float  x)
inline

Definition at line 487 of file lda_core.cc.

References digamma< float, USE_FAST_APPROX >().

Referenced by lda::digamma().

488 {
490 }
float digamma< float, USE_FAST_APPROX >(float x)
Definition: lda_core.cc:464

◆ expdigammify()

template<typename T , const lda_math_mode mtype>
void ldamath::expdigammify ( vw all,
T *  gamma,
threshold,
initial 
)
inline

Definition at line 503 of file lda_core.cc.

References accumulate(), and vw::lda.

504 {
505  T sum = digamma<T, mtype>(std::accumulate(gamma, gamma + all.lda, initial));
506 
507  std::transform(gamma, gamma + all.lda, gamma,
508  [sum, threshold](T g) { return fmax(threshold, exponential<T, mtype>(digamma<T, mtype>(g) - sum)); });
509 }
void accumulate(vw &all, parameters &weights, size_t offset)
Definition: accumulate.cc:20
uint32_t lda
Definition: global_data.h:508

◆ expdigammify< float, USE_SIMD >()

template<>
void ldamath::expdigammify< float, USE_SIMD > ( vw all,
float *  gamma,
float  threshold,
float   
)
inline

Definition at line 511 of file lda_core.cc.

Referenced by lda::expdigammify().

512 {
513 #if defined(HAVE_SIMD_MATHMODE)
514  vexpdigammify(all, gamma, threshold);
515 #else
516  // Do something sensible if SIMD math isn't available:
517  expdigammify<float, USE_FAST_APPROX>(all, gamma, threshold, 0.0);
518 #endif
519 }

◆ expdigammify_2()

template<typename T , const lda_math_mode mtype>
void ldamath::expdigammify_2 ( vw all,
float *  gamma,
T *  norm,
const T  threshold 
)
inline

Definition at line 522 of file lda_core.cc.

References vw::lda.

523 {
524  std::transform(gamma, gamma + all.lda, norm, gamma,
525  [threshold](float g, float n) { return fmax(threshold, exponential<T, mtype>(digamma<T, mtype>(g) - n)); });
526 }
uint32_t lda
Definition: global_data.h:508

◆ expdigammify_2< float, USE_SIMD >()

template<>
void ldamath::expdigammify_2< float, USE_SIMD > ( vw all,
float *  gamma,
float *  norm,
const float  threshold 
)
inline

Definition at line 528 of file lda_core.cc.

Referenced by lda::expdigammify_2().

529 {
530 #if defined(HAVE_SIMD_MATHMODE)
531  vexpdigammify_2(all, gamma, norm, threshold);
532 #else
533  // Do something sensible if SIMD math isn't available:
534  expdigammify_2<float, USE_FAST_APPROX>(all, gamma, norm, threshold);
535 #endif
536 }

◆ exponential()

template<typename T , lda_math_mode mtype>
T ldamath::exponential ( )
inline

Definition at line 421 of file lda_core.cc.

422 {
423  BOOST_STATIC_ASSERT_MSG(true, "ldamath::exponential is not defined for this type and math mode.");
424 }

◆ exponential< float, USE_FAST_APPROX >()

template<>
float ldamath::exponential< float, USE_FAST_APPROX > ( float  x)
inline

Definition at line 469 of file lda_core.cc.

References fastexp().

Referenced by exponential< float, USE_SIMD >().

470 {
471  return fastexp(x);
472 }
static float fastexp(float p)
Definition: nn.cc:79

◆ exponential< float, USE_PRECISE >()

template<>
float ldamath::exponential< float, USE_PRECISE > ( float  x)
inline

Definition at line 446 of file lda_core.cc.

References correctedExp.

447 {
448  return correctedExp(x);
449 }
#define correctedExp
Definition: correctedMath.h:27

◆ exponential< float, USE_SIMD >()

template<>
float ldamath::exponential< float, USE_SIMD > ( float  x)
inline

Definition at line 492 of file lda_core.cc.

References exponential< float, USE_FAST_APPROX >().

493 {
495 }
float exponential< float, USE_FAST_APPROX >(float x)
Definition: lda_core.cc:469

◆ fastdigamma()

float ldamath::fastdigamma ( float  x)
inline

Definition at line 172 of file lda_core.cc.

References a, f, fastexp(), fastlog(), anonymous_namespace{lda_core.cc}::is_aligned16(), and vw::lda.

Referenced by digamma< float, USE_FAST_APPROX >().

173 {
174  float twopx = 2.0f + x;
175  float logterm = fastlog(twopx);
176 
177  return -(1.0f + 2.0f * x) / (x * (1.0f + x)) - (13.0f + 6.0f * x) / (12.0f * twopx * twopx) + logterm;
178 }
float fastlog(float x)
Definition: lda_core.cc:145
float f
Definition: cache.cc:40

◆ fastexp()

float ldamath::fastexp ( float  p)
inline

Definition at line 160 of file lda_core.cc.

References f, and fastpow2().

160 { return fastpow2(1.442695040f * p); }
static float fastpow2(float p)
Definition: nn.cc:64
float f
Definition: cache.cc:40

◆ fastlgamma()

float ldamath::fastlgamma ( float  x)
inline

Definition at line 164 of file lda_core.cc.

References f, and fastlog().

Referenced by lgamma< float, USE_FAST_APPROX >().

165 {
166  float logterm = fastlog(x * (1.0f + x) * (2.0f + x));
167  float xp3 = 3.0f + x;
168 
169  return -2.081061466f - x + 0.0833333f / xp3 - logterm + (2.5f + x) * fastlog(xp3);
170 }
float fastlog(float x)
Definition: lda_core.cc:145
float f
Definition: cache.cc:40

◆ fastlog()

float ldamath::fastlog ( float  x)
inline

Definition at line 145 of file lda_core.cc.

References fastlog2().

Referenced by fastdigamma(), and fastlgamma().

145 { return 0.69314718f * fastlog2(x); }
float fastlog2(float x)
Definition: lda_core.cc:127

◆ fastlog2()

float ldamath::fastlog2 ( float  x)
inline

Definition at line 127 of file lda_core.cc.

Referenced by fastlog(), and fastpow().

128 {
129  uint32_t mx;
130  memcpy(&mx, &x, sizeof(uint32_t));
131  mx = (mx & 0x007FFFFF) | (0x7e << 23);
132 
133  float mx_f;
134  memcpy(&mx_f, &mx, sizeof(float));
135 
136  uint32_t vx;
137  memcpy(&vx, &x, sizeof(uint32_t));
138 
139  float y = static_cast<float>(vx);
140  y *= 1.0f / (float)(1 << 23);
141 
142  return y - 124.22544637f - 1.498030302f * mx_f - 1.72587999f / (0.3520887068f + mx_f);
143 }

◆ fastpow()

float ldamath::fastpow ( float  x,
float  p 
)
inline

Definition at line 162 of file lda_core.cc.

References fastlog2(), and fastpow2().

Referenced by powf< float, USE_FAST_APPROX >().

162 { return fastpow2(p * fastlog2(x)); }
float fastlog2(float x)
Definition: lda_core.cc:127
static float fastpow2(float p)
Definition: nn.cc:64

◆ fastpow2()

float ldamath::fastpow2 ( float  p)
inline

Definition at line 147 of file lda_core.cc.

References f.

148 {
149  float offset = (p < 0) * 1.0f;
150  float clipp = (p < -126.0) ? -126.0f : p;
151  int w = (int)clipp;
152  float z = clipp - w + offset;
153  uint32_t approx = (uint32_t)((1 << 23) * (clipp + 121.2740838f + 27.7280233f / (4.84252568f - z) - 1.49012907f * z));
154 
155  float v;
156  memcpy(&v, &approx, sizeof(uint32_t));
157  return v;
158 }
float f
Definition: cache.cc:40

◆ lgamma()

template<typename T , const lda_math_mode mtype>
T ldamath::lgamma ( )
inline

Definition at line 407 of file lda_core.cc.

Referenced by lgamma< float, USE_PRECISE >().

408 {
409  BOOST_STATIC_ASSERT_MSG(true, "ldamath::lgamma is not defined for this type and math mode.");
410 }

◆ lgamma< float, USE_FAST_APPROX >()

template<>
float ldamath::lgamma< float, USE_FAST_APPROX > ( float  x)
inline

Definition at line 459 of file lda_core.cc.

References fastlgamma().

Referenced by lda::lgamma(), and lgamma< float, USE_SIMD >().

460 {
461  return fastlgamma(x);
462 }
float fastlgamma(float x)
Definition: lda_core.cc:164

◆ lgamma< float, USE_PRECISE >()

template<>
float ldamath::lgamma< float, USE_PRECISE > ( float  x)
inline

Definition at line 436 of file lda_core.cc.

References lgamma().

Referenced by lda::lgamma().

437 {
438  return boost::math::lgamma(x);
439 }
T lgamma(T)
Definition: lda_core.cc:407

◆ lgamma< float, USE_SIMD >()

template<>
float ldamath::lgamma< float, USE_SIMD > ( float  x)
inline

Definition at line 482 of file lda_core.cc.

References lgamma< float, USE_FAST_APPROX >().

Referenced by lda::lgamma().

483 {
485 }
float lgamma< float, USE_FAST_APPROX >(float x)
Definition: lda_core.cc:459

◆ powf()

template<typename T , lda_math_mode mtype>
T ldamath::powf ( ,
 
)
inline

Definition at line 428 of file lda_core.cc.

Referenced by GD::average_update(), GD::compute_rate_decay(), gd_mf_setup(), GD::get_scale(), mf_train(), parseFloat(), GD::pred_per_update_feature(), Search::random_policy(), and GD::setup().

429 {
430  BOOST_STATIC_ASSERT_MSG(true, "ldamath::powf is not defined for this type and math mode.");
431 }

◆ powf< float, USE_FAST_APPROX >()

template<>
float ldamath::powf< float, USE_FAST_APPROX > ( float  x,
float  p 
)
inline

Definition at line 474 of file lda_core.cc.

References fastpow().

Referenced by lda::powf(), and powf< float, USE_SIMD >().

475 {
476  return fastpow(x, p);
477 }
float fastpow(float x, float p)
Definition: lda_core.cc:162

◆ powf< float, USE_PRECISE >()

template<>
float ldamath::powf< float, USE_PRECISE > ( float  x,
float  p 
)
inline

Definition at line 451 of file lda_core.cc.

Referenced by lda::powf().

452 {
453  return std::pow(x, p);
454 }

◆ powf< float, USE_SIMD >()

template<>
float ldamath::powf< float, USE_SIMD > ( float  x,
float  p 
)
inline

Definition at line 497 of file lda_core.cc.

References powf< float, USE_FAST_APPROX >().

Referenced by lda::powf().

498 {
499  return powf<float, USE_FAST_APPROX>(x, p);
500 }
float powf< float, USE_FAST_APPROX >(float x, float p)
Definition: lda_core.cc:474