PetaVision  Alpha
KneeTimeScaleController.cpp
1 #include "KneeTimeScaleController.hpp"
2 
3 namespace PV {
4 
5 KneeTimeScaleController::KneeTimeScaleController(
6  char const *name,
7  int batchWidth,
8  double baseMax,
9  double baseMin,
10  double tauFactor,
11  double growthFactor,
12  bool writeTimeScaleFieldnames,
13  Communicator *comm,
14  double kneeThresh,
15  double kneeSlope)
16  : AdaptiveTimeScaleController(
17  name,
18  batchWidth,
19  baseMax,
20  baseMin,
21  tauFactor,
22  growthFactor,
23  writeTimeScaleFieldnames,
24  comm) {
25  mKneeThresh = kneeThresh;
26  mKneeSlope = kneeSlope;
27 }
28 
29 std::vector<double>
30 KneeTimeScaleController::calcTimesteps(double timeValue, std::vector<double> const &rawTimeScales) {
31 
32  std::vector<double> timeScales(
33  AdaptiveTimeScaleController::calcTimesteps(timeValue, rawTimeScales));
34 
35  for (int i = 0; i < timeScales.size(); ++i) {
36  // Scale timescalemax if it's above the knee
37  if (mTimeScaleInfo.mTimeScaleMax[i] > mKneeThresh) {
38  mTimeScaleInfo.mTimeScaleMax[i] =
39  mOldTimeScaleInfo.mTimeScaleMax[i]
40  + (mTimeScaleInfo.mTimeScaleMax[i] - mOldTimeScaleInfo.mTimeScaleMax[i])
41  * mKneeSlope;
42  // Cap our timescale to the newly calculated max
43  timeScales[i] = std::min(timeScales[i], mTimeScaleInfo.mTimeScaleMax[i]);
44  }
45  }
46  return timeScales;
47 }
48 }