PetaVision  Alpha
SigmoidLayer.cpp
1 /*
2  * SigmoidLayer.cpp
3  *
4  * Created on: May 11, 2011
5  * Author: garkenyon
6  */
7 
8 #include "SigmoidLayer.hpp"
9 #include <stdio.h>
10 
11 #include "../include/default_params.h"
12 
13 // SigmoidLayer can be used to implement Sigmoid junctions
14 namespace PV {
15 SigmoidLayer::SigmoidLayer() { initialize_base(); }
16 
17 SigmoidLayer::SigmoidLayer(const char *name, HyPerCol *hc) {
18  initialize_base();
19  initialize(name, hc);
20 }
21 
22 SigmoidLayer::~SigmoidLayer() {}
23 
24 int SigmoidLayer::initialize_base() { return PV_SUCCESS; }
25 
26 int SigmoidLayer::initialize(const char *name, HyPerCol *hc) {
27  int status_init = CloneVLayer::initialize(name, hc);
28 
29  if (parent->columnId() == 0) {
30  if (InverseFlag)
31  InfoLog().printf("SigmoidLayer: Inverse flag is set\n");
32  if (SigmoidFlag)
33  InfoLog().printf("SigmoidLayer: True Sigmoid flag is set\n");
34  }
35 
36  if (SigmoidAlpha < 0.0f || SigmoidAlpha > 1.0f) {
37  if (parent->columnId() == 0) {
38  ErrorLog().printf(
39  "%s: SigmoidAlpha cannot be negative or greater than 1.\n", getDescription_c());
40  }
41  MPI_Barrier(parent->getCommunicator()->communicator());
42  exit(EXIT_FAILURE);
43  }
44 
45  return status_init;
46 }
47 
48 int SigmoidLayer::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
49  int status = CloneVLayer::ioParamsFillGroup(ioFlag);
50  ioParam_Vrest(ioFlag);
51  ioParam_VthRest(ioFlag);
52  ioParam_InverseFlag(ioFlag);
53  ioParam_SigmoidFlag(ioFlag);
54  ioParam_SigmoidAlpha(ioFlag);
55  return status;
56 }
57 
58 void SigmoidLayer::ioParam_Vrest(enum ParamsIOFlag ioFlag) {
59  parent->parameters()->ioParamValue(ioFlag, name, "Vrest", &V0, (float)V_REST);
60 }
61 void SigmoidLayer::ioParam_VthRest(enum ParamsIOFlag ioFlag) {
62  parent->parameters()->ioParamValue(ioFlag, name, "VthRest", &Vth, (float)VTH_REST);
63 }
64 void SigmoidLayer::ioParam_InverseFlag(enum ParamsIOFlag ioFlag) {
65  parent->parameters()->ioParamValue(ioFlag, name, "InverseFlag", &InverseFlag, (bool)INVERSEFLAG);
66 }
67 void SigmoidLayer::ioParam_SigmoidFlag(enum ParamsIOFlag ioFlag) {
68  parent->parameters()->ioParamValue(ioFlag, name, "SigmoidFlag", &SigmoidFlag, (bool)SIGMOIDFLAG);
69 }
70 void SigmoidLayer::ioParam_SigmoidAlpha(enum ParamsIOFlag ioFlag) {
71  parent->parameters()->ioParamValue(
72  ioFlag, name, "SigmoidAlpha", &SigmoidAlpha, (float)SIGMOIDALPHA);
73 }
74 
75 Response::Status
76 SigmoidLayer::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
77  return CloneVLayer::communicateInitInfo(message);
78 }
79 
80 Response::Status SigmoidLayer::allocateDataStructures() {
81  auto status = CloneVLayer::allocateDataStructures();
82  // Should have been initialized with zero channels, so GSyn should be NULL and freeChannels()
83  // call should be unnecessary
84  pvAssert(GSyn == nullptr);
85  return status;
86 }
87 
88 int SigmoidLayer::setActivity() {
89  float *activity = clayer->activity->data;
90  memset(activity, 0, sizeof(float) * clayer->numExtendedAllBatches);
91  return 0;
92 }
93 
94 Response::Status SigmoidLayer::updateState(double timef, double dt) {
95  int status;
96  updateState(
97  timef,
98  dt,
99  getLayerLoc(),
100  getCLayer()->activity->data,
101  getV(),
102  0,
103  NULL,
104  Vth,
105  V0,
106  SigmoidAlpha,
107  SigmoidFlag,
108  InverseFlag);
109  return Response::SUCCESS;
110 }
111 
112 void SigmoidLayer::updateState(
113  double timef,
114  double dt,
115  const PVLayerLoc *loc,
116  float *A,
117  float *V,
118  int num_channels,
119  float *gSynHead,
120  float Vth,
121  float V0,
122  float sigmoid_alpha,
123  bool sigmoid_flag,
124  bool inverse_flag) {
125  int nx = loc->nx;
126  int ny = loc->ny;
127  int nf = loc->nf;
128  int num_neurons = nx * ny * nf;
129  int nbatch = loc->nbatch;
130  updateV_SigmoidLayer(); // Does nothing as sourceLayer is responsible for updating V.
131  setActivity_SigmoidLayer(
132  nbatch,
133  num_neurons,
134  A,
135  V,
136  nx,
137  ny,
138  nf,
139  loc->halo.lt,
140  loc->halo.rt,
141  loc->halo.dn,
142  loc->halo.up,
143  Vth,
144  V0,
145  sigmoid_alpha,
146  sigmoid_flag,
147  inverse_flag,
148  dt);
149 }
150 
151 } // end namespace PV
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: CloneVLayer.cpp:34
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override