PetaVision  Alpha
HyPerDelivery.cpp
1 /*
2  * HyPerDelivery.cpp
3  *
4  * Created on: Aug 24, 2017
5  * Author: Pete Schultz
6  */
7 
8 #include "HyPerDelivery.hpp"
9 #include "columns/HyPerCol.hpp"
10 #include "utils/MapLookupByType.hpp"
11 
12 namespace PV {
13 
14 HyPerDelivery::HyPerDelivery(char const *name, HyPerCol *hc) { initialize(name, hc); }
15 
16 HyPerDelivery::HyPerDelivery() {}
17 
18 HyPerDelivery::~HyPerDelivery() {}
19 
20 int HyPerDelivery::initialize(char const *name, HyPerCol *hc) {
21  return BaseDelivery::initialize(name, hc);
22 }
23 
24 void HyPerDelivery::setObjectType() { mObjectType = "HyPerDelivery"; }
25 
26 int HyPerDelivery::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
27  int status = PV_SUCCESS;
28  // Only read params because HyPerDeliveryFacade will read/write them too.
29  // The facade needs to read the params in order to determine which HyPerDelivery subclass
30  // to instantiate.
31  if (ioFlag == PARAMS_IO_READ) {
32  status = BaseDelivery::ioParamsFillGroup(ioFlag);
33  }
35  return PV_SUCCESS;
36 }
37 
38 void HyPerDelivery::ioParam_convertRateToSpikeCount(enum ParamsIOFlag ioFlag) {
39  parent->parameters()->ioParamValue(
40  ioFlag,
41  this->getName(),
42  "convertRateToSpikeCount",
43  &mConvertRateToSpikeCount,
44  mConvertRateToSpikeCount /*default value*/);
45 }
46 
47 Response::Status
48 HyPerDelivery::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
49  auto status = BaseDelivery::communicateInitInfo(message);
50  if (!Response::completed(status)) {
51  return status;
52  }
53  mWeightsPair = mapLookupByType<WeightsPair>(message->mHierarchy, getDescription());
54  FatalIf(!mWeightsPair, "%s requires a WeightsPair component.\n", getDescription_c());
55  if (!mWeightsPair->getInitInfoCommunicatedFlag()) {
56  return Response::POSTPONE;
57  }
58 
59  mArborList = mapLookupByType<ArborList>(message->mHierarchy, getDescription());
60  FatalIf(!mArborList, "%s requires an ArborList component.\n", getDescription_c());
61  if (!mArborList->getInitInfoCommunicatedFlag()) {
62  return Response::POSTPONE;
63  }
64  return Response::SUCCESS;
65 }
66 
67 Response::Status HyPerDelivery::allocateDataStructures() {
68  auto status = BaseDelivery::allocateDataStructures();
69  if (!Response::completed(status)) {
70  return status;
71  }
72  if (mAccumulateType == STOCHASTIC) {
73  mDeltaTimeFactor = (float)parent->getDeltaTime();
74  }
75  else if (mConvertRateToSpikeCount and !mPreLayer->activityIsSpiking()) {
76  mDeltaTimeFactor =
77  (float)convertToRateDeltaTimeFactor(mPostLayer->getChannelTimeConst(mChannelCode));
78  }
79  else {
80  mDeltaTimeFactor = 1.0f;
81  }
82  return Response::SUCCESS;
83 }
84 
85 double HyPerDelivery::convertToRateDeltaTimeFactor(double timeConstantTau) const {
86  double dt = parent->getDeltaTime();
87  double dtFactor;
88  if (timeConstantTau > 0) {
89  dtFactor = std::exp(dt / timeConstantTau) - 1.0;
90  // the above factor was chosen so that for a constant input of G_SYN to an excitatory
91  // conductance G_EXC, then G_EXC -> G_SYN as t -> inf
92  }
93  else {
94  dtFactor = dt;
95  }
96  return dtFactor;
97 }
98 
100  bool isReady = true;
101  if (getChannelCode() != CHANNEL_NOUPDATE) {
102  int const numArbors = mArborList->getNumAxonalArbors();
103  for (int a = 0; a < numArbors; a++) {
104  isReady &= getPreLayer()->isExchangeFinished(mArborList->getDelay(a));
105  }
106  }
107  return isReady;
108 }
109 
110 } // end namespace PV
virtual void ioParam_convertRateToSpikeCount(enum ParamsIOFlag ioFlag)
convertRateToSpikeCount: If true, presynaptic activity is converted from a rate (spikes per second) t...
bool isExchangeFinished(int delay=0)
static bool completed(Status &a)
Definition: Response.hpp:49
virtual bool isAllInputReady() override
int getNumAxonalArbors() const
Definition: ArborList.hpp:52
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
bool getInitInfoCommunicatedFlag() const
Definition: BaseObject.hpp:95