PetaVision  Alpha
LogTimeScaleController.cpp
1 #include "LogTimeScaleController.hpp"
2 #include <cmath>
3 
4 namespace PV {
5 
6 LogTimeScaleController::LogTimeScaleController(
7  char const *name,
8  int batchWidth,
9  double baseMax,
10  double baseMin,
11  double tauFactor,
12  double growthFactor,
13  bool writeTimeScaleFieldnames,
14  Communicator *comm,
15  double logThresh,
16  double logSlope)
17  : AdaptiveTimeScaleController(
18  name,
19  batchWidth,
20  baseMax,
21  baseMin,
22  tauFactor,
23  growthFactor,
24  writeTimeScaleFieldnames,
25  comm) {
26  mLogThresh = logThresh;
27  mLogSlope = -(logThresh - mBaseMax) / log(logSlope);
28 }
29 
30 std::vector<double>
31 LogTimeScaleController::calcTimesteps(double timeValue, std::vector<double> const &rawTimeScales) {
32  mOldTimeScaleInfo = mTimeScaleInfo;
33  mTimeScaleInfo.mTimeScaleTrue = rawTimeScales;
34  for (int b = 0; b < mBatchWidth; b++) {
35  double E_dt = mTimeScaleInfo.mTimeScaleTrue[b];
36  double E_0 = mOldTimeScaleInfo.mTimeScaleTrue[b];
37  double dE_dt_scaled = (E_0 - E_dt) / mTimeScaleInfo.mTimeScale[b];
38 
39  if (E_dt == E_0) {
40  continue;
41  }
42 
43  if ((dE_dt_scaled <= 0.0) || (E_0 <= 0) || (E_dt <= 0)) {
44  mTimeScaleInfo.mTimeScale[b] = mBaseMin;
45  mTimeScaleInfo.mTimeScaleMax[b] = mBaseMax;
46  }
47  else {
48  double tau_eff_scaled = E_0 / dE_dt_scaled;
49 
50  // dt := mTimeScaleMaxBase * tau_eff
51  mTimeScaleInfo.mTimeScale[b] = mTauFactor * tau_eff_scaled;
52  if (mTimeScaleInfo.mTimeScale[b] >= mTimeScaleInfo.mTimeScaleMax[b]) {
53  double growthFactor =
54  mGrowthFactor * exp(-(mTimeScaleInfo.mTimeScaleMax[b] - mBaseMax) / mLogSlope);
55  mTimeScaleInfo.mTimeScale[b] = mTimeScaleInfo.mTimeScaleMax[b];
56  mTimeScaleInfo.mTimeScaleMax[b] = (1 + growthFactor) * mTimeScaleInfo.mTimeScaleMax[b];
57  }
58  }
59  }
60  return mTimeScaleInfo.mTimeScale;
61 }
62 }