PetaVision  Alpha
PV::ColumnEnergyProbe Class Reference

#include <ColumnEnergyProbe.hpp>

Inheritance diagram for PV::ColumnEnergyProbe:
PV::ColProbe PV::BaseProbe PV::BaseObject PV::CheckpointerDataInterface PV::Observer

BaseProbe Parameters

List of parameters for the BaseProbe class

virtual void ioParam_message (enum ParamsIOFlag ioFlag)
 message: A string parameter that is typically included in the lines output by the outputState method
 
virtual void ioParam_textOutputFlag (enum ParamsIOFlag ioFlag)
 textOutputFlag: A boolean parameter that sets whether to generate an output file. Defaults to true.
 
virtual void ioParam_probeOutputFile (enum ParamsIOFlag ioFlag)
 probeOutputFile: If textOutputFlag is true, probeOutputFile specifies the name of the file that the outputState method writes to. If blank, the output is sent to the output stream.
 
virtual void ioParam_triggerFlag (enum ParamsIOFlag ioFlag)
 triggerFlag: If false, the needUpdate method always returns true, so that outputState is called every timestep. If true, the needUpdate method uses triggerLayerName and triggerOffset to determine if the probe should be triggered.
 
virtual void ioParam_triggerLayerName (enum ParamsIOFlag ioFlag)
 triggerLayerName: If triggerFlag is true, triggerLayerName specifies the layer to check for triggering.
 
virtual void ioParam_triggerOffset (enum ParamsIOFlag ioFlag)
 triggerOffset: If triggerFlag is true, triggerOffset specifies the time interval before the triggerLayer's nextUpdate time that needUpdate() returns true.
 
virtual void ioParam_energyProbe (enum ParamsIOFlag ioFlag)
 energyProbe: If nonblank, specifies the name of a ColumnEnergyProbe that this probe contributes an energy term to.
 
virtual void ioParam_coefficient (enum ParamsIOFlag ioFlag)
 coefficient: If energyProbe is set, the coefficient parameter specifies that ColumnEnergyProbe multiplies the result of this probe's getValues() method by coefficient when computing the error. More...
 

Public Member Functions

 ColumnEnergyProbe (const char *probename, HyPerCol *hc)
 
virtual ~ColumnEnergyProbe ()
 
int addTerm (BaseProbe *probe)
 Adds a probe to the energy calculation. More...
 
virtual int calcValues (double timevalue) override
 
virtual int communicateInitInfo (CommunicateInitInfoMessage const *message) override
 
double getCoefficient ()
 
bool getDataStructuresAllocatedFlag ()
 
std::string const & getDescription () const
 
char const * getDescription_c () const
 
char const * getEnergyProbe ()
 
bool getInitialValuesSetFlag ()
 
bool getInitInfoCommunicatedFlag ()
 
char const * getKeyword () const
 
double getLastUpdateTime ()
 
MPIBlock const * getMPIBlock ()
 
char const * getName () const
 
int getNumValues ()
 
const char * getTargetName ()
 
double getValue (double timevalue, int index)
 
int getValues (double timevalue, double *valuesVector)
 
int getValues (double timevalue, std::vector< double > *valuesVector)
 
int ioParams (enum ParamsIOFlag ioFlag)
 
bool isUsingGPU () const
 
virtual int outputState (double timevalue) override
 
virtual int outputStateWrapper (double timef, double dt)
 
virtual int registerData (Checkpointer *checkpointer) override
 
virtual int respond (std::shared_ptr< BaseMessage const > message) override
 
virtual int writeTimer (PrintStream &stream)
 

Protected Member Functions

 ColumnEnergyProbe ()
 
virtual int allocateDataStructures ()
 
virtual int cleanup ()
 
virtual int copyInitialStateToGPU ()
 
const char * getMessage ()
 
char const * getProbeOutputFilename ()
 
bool getTextOutputFlag () const
 
int getValues (double timevalue)
 
double * getValuesBuffer ()
 
int initialize (const char *name, HyPerCol *hc)
 
int initializeColumnEnergyProbe (const char *probename, HyPerCol *hc)
 
virtual int initializeState ()
 
virtual int initMessage (const char *msg)
 
virtual int initNumValues ()
 
virtual void initOutputStreams (const char *filename, Checkpointer *checkpointer) override
 
virtual void ioParam_reductionInterval (enum ParamsIOFlag ioFlag)
 
virtual void ioParam_targetName (enum ParamsIOFlag ioFlag) override
 targetName: ColProbe sets targetName to the empty string, since the only possible target is the parent HyPerCol. The targenName parameter is neither read nor written by this method.
 
virtual int ioParamsFillGroup (enum ParamsIOFlag ioFlag) override
 
bool isWritingToFile () const
 
virtual bool needRecalc (double timevalue) override
 
virtual bool needUpdate (double time, double dt)
 
PrintStreamoutput (int b)
 
virtual void outputHeader () override
 
virtual int prepareCheckpointWrite ()
 
virtual int processCheckpointRead ()
 
virtual int readStateFromCheckpoint (Checkpointer *checkpointer) override
 
virtual double referenceUpdateTime () const override
 
int respondAllocateData (AllocateDataMessage const *message)
 
int respondCleanup (CleanupMessage const *message)
 
int respondCommunicateInitInfo (CommunicateInitInfoMessage const *message)
 
int respondCopyInitialStateToGPUMessage (CopyInitialStateToGPUMessage const *message)
 
int respondInitializeState (InitializeStateMessage const *message)
 
int respondPrepareCheckpointWrite (PrepareCheckpointWriteMessage const *message)
 
int respondProcessCheckpointRead (ProcessCheckpointReadMessage const *message)
 
int respondReadStateFromCheckpoint (ReadStateFromCheckpointMessage< Checkpointer > const *message)
 
int respondRegisterData (RegisterDataMessage< Checkpointer > const *message)
 
void setDataStructuresAllocatedFlag ()
 
virtual int setDescription ()
 
void setInitialValuesSetFlag ()
 
void setInitInfoCommunicatedFlag ()
 
int setName (char const *name)
 
int setNumValues (int n)
 
int setParent (HyPerCol *hc)
 

Protected Attributes

double coefficient
 
std::string description
 
char * energyProbe
 
bool mInitialValuesSetFlag = false
 
std::vector< PrintStream * > mOutputStreams
 
bool mUsingGPUFlag = false
 
char * name = nullptr
 
size_t numTerms
 
HyPerColparent = nullptr
 
char * targetName
 
BaseProbe ** terms
 
bool triggerFlag
 
HyPerLayertriggerLayer
 
char * triggerLayerName
 
double triggerOffset
 

Private Member Functions

int initialize_base ()
 

Private Attributes

double mLastTimeValue = -1
 
int mSkipInterval = 0
 
int mSkipTimer = 0
 

Detailed Description

ColumnEnergyProbe assembles several base probes each of which contribute a term to an energy of the entire HyPerCol.

At the params file level, define a ColumnEnergyProbe group. Say, for example that the group is named "total_energy". Then for each base probe you want to add to the probe, its params should include the line

energyProbe = "total_energy";

Then optionally specify a coefficient, which defaults to 1.

The contribution from this probe to the total energy is coefficient * value where value is the result of calling the BaseProbe's getValues() method.

At the C/C++ code level, BaseProbes register themselves to the ColumnEnergyProbe by calling the ColumnEnergyProbe's addTerm() method. Each call to a ColumnEnergyProbe's object that calls addTerm() must have the same getNumValues() value, which becomes the ColumnEnergyProbe's getNumValues() value.

Definition at line 40 of file ColumnEnergyProbe.hpp.

Constructor & Destructor Documentation

PV::ColumnEnergyProbe::ColumnEnergyProbe ( const char *  probename,
HyPerCol hc 
)

Public constructor for the ColumnEnergyProbe class.

Definition at line 22 of file ColumnEnergyProbe.cpp.

PV::ColumnEnergyProbe::~ColumnEnergyProbe ( )
virtual

Destructor for the ColumnEnergyProbe class.

Definition at line 27 of file ColumnEnergyProbe.cpp.

PV::ColumnEnergyProbe::ColumnEnergyProbe ( )
protected

The constructor without arguments should be used by derived classes.

Definition at line 14 of file ColumnEnergyProbe.cpp.

Member Function Documentation

int PV::ColumnEnergyProbe::addTerm ( BaseProbe probe)

Adds a probe to the energy calculation.

Returns PV_SUCCESS if the probe is added successfully. If probe is NULL, the list of terms is unchanged and PV_FAILURE is returned. Nothing prevents a probe from being added more than once. All BaseProbes added to the ColumnEnergyProbe must have the same getNumValues().

Definition at line 67 of file ColumnEnergyProbe.cpp.

int PV::ColumnEnergyProbe::calcValues ( double  timevalue)
overridevirtual

A pure virtual method to calculate the values of the probe. calcValues() can assume that needRecalc() has been called and returned true. It should write the computed values into the buffer of member variable 'probeValues'.

Implements PV::BaseProbe.

Definition at line 149 of file ColumnEnergyProbe.cpp.

int PV::ColProbe::communicateInitInfo ( CommunicateInitInfoMessage const *  message)
overridevirtualinherited

Calls BaseProbe::communicateInitInfo (which sets up any triggering or attaching to an energy probe) and then attaches to the parent HyPerCol by calling parent->insertProbe().

Implements PV::BaseProbe.

Reimplemented in PV::AdaptiveTimeScaleProbe, and PV::QuotientColProbe.

Definition at line 55 of file ColProbe.cpp.

double PV::BaseProbe::getCoefficient ( )
inlineinherited

Returns the coefficient if the energy probe is set.

Definition at line 96 of file BaseProbe.hpp.

bool PV::BaseObject::getDataStructuresAllocatedFlag ( )
inlineinherited

Get-method for mDataStructuresAllocatedFlag, which is false on initialization and then becomes true once setDataStructuresAllocatedFlag() is called.

Definition at line 65 of file BaseObject.hpp.

char const* PV::BaseProbe::getEnergyProbe ( )
inlineinherited

Returns the name of the energy probe the probe is attached to (null if not attached to an energy probe)

Definition at line 91 of file BaseProbe.hpp.

bool PV::BaseObject::getInitialValuesSetFlag ( )
inlineinherited

Get-method for mInitialValuesSetFlag, which is false on initialization and then becomes true once setInitialValuesSetFlag() is called.

Definition at line 71 of file BaseObject.hpp.

bool PV::BaseObject::getInitInfoCommunicatedFlag ( )
inlineinherited

Get-method for mInitInfoCommunicatedFlag, which is false on initialization and then becomes true once setInitInfoCommunicatedFlag() is called.

Definition at line 58 of file BaseObject.hpp.

double PV::BaseProbe::getLastUpdateTime ( )
inlineinherited

Returns the time that calcValues was last called. BaseProbe updates the last update time in getValues() and getValue(), based on the result of needRecalc.

Definition at line 103 of file BaseProbe.hpp.

const char* PV::BaseProbe::getMessage ( )
inlineprotectedinherited

Returns a pointer to the message parameter.

Definition at line 278 of file BaseProbe.hpp.

int PV::BaseProbe::getNumValues ( )
inlineinherited

Returns the number of value indices the probe can compute (typically the value of the parent HyPerCol's nBatch parameter). BaseProbe::getNumValues() returns the parent HyPerCol's getNBatch(), which can be overridden. Probes derived from BaseProbe can set numValues to zero or a negative number to indicate that getValues() and getNumValues() are not fully implemented for that probe.

Definition at line 62 of file BaseProbe.hpp.

char const* PV::BaseProbe::getProbeOutputFilename ( )
inlineprotectedinherited

Returns the probeOutputFilename parameter

Definition at line 312 of file BaseProbe.hpp.

const char* PV::BaseProbe::getTargetName ( )
inlineinherited

Returns the name of the targetName parameter for this probe. LayerProbe uses targetName to specify the layer to attach to; BaseConnectionProbe uses it to specify the connection to attach to.

Definition at line 84 of file BaseProbe.hpp.

bool PV::BaseProbe::getTextOutputFlag ( ) const
inlineprotectedinherited

Returns the value of the textOutputFlag parameter

Definition at line 322 of file BaseProbe.hpp.

double PV::BaseProbe::getValue ( double  timevalue,
int  index 
)
inherited

getValue() is meant for situations where the caller needs one value that would be returned by getValues(), not the whole buffer. getValue() returns a signaling NaN if index is out of bounds. If index is valid, getValue() calls calcValues() if needRecalc() returns true, and then returns probeValues[index]. Derived classes should not override or hide this method. Instead, they should override calcValues.

Definition at line 359 of file BaseProbe.cpp.

int PV::BaseProbe::getValues ( double  timevalue,
double *  valuesVector 
)
inherited

getValues(double timevalue, double * values) sets the buffer 'values' with the probe's calculated values. It assumes that the values buffer is large enough to hold getNumValues() double-precision values. If 'values' is NULL, the values are still updated internally if needed, but those values are not returned. Internally, getValues() calls calcValues() if needRecalc() is true. It then copies the probeValues buffer to the input argument buffer 'values'. Derived classes should not override or hide this method. Instead, they should override calcValues.

Definition at line 346 of file BaseProbe.cpp.

int PV::BaseProbe::getValues ( double  timevalue,
std::vector< double > *  valuesVector 
)
inherited

getValues(double timevalue, vector<double> * valuesVector) is a wrapper around getValues(double, double *) that uses C++ vectors. It resizes valuesVector to size getNumValues() and then fills the vector with the values returned by getValues.

Definition at line 354 of file BaseProbe.cpp.

int PV::BaseProbe::getValues ( double  timevalue)
protectedinherited

If needRecalc() returns true, getValues(double) updates the probeValues buffer (by calling calcValues) and sets lastUpdateTime to the timevalue input argument.

Definition at line 335 of file BaseProbe.cpp.

double* PV::BaseProbe::getValuesBuffer ( )
inlineprotectedinherited

Returns a pointer to the buffer containing the probeValues.

Definition at line 317 of file BaseProbe.hpp.

int PV::ColProbe::initialize ( const char *  name,
HyPerCol hc 
)
protectedinherited

Reads the parameters and performs initializations that do not depend on other param groups. It is called by the public constructor and should be called by the initializer of any derived classes.

Definition at line 31 of file ColProbe.cpp.

int PV::ColumnEnergyProbe::initialize_base ( )
private

Sets member variables to safe values. It is called by both the public and protected constructors, and should not otherwise be called.

Definition at line 32 of file ColumnEnergyProbe.cpp.

int PV::ColumnEnergyProbe::initializeColumnEnergyProbe ( const char *  probename,
HyPerCol hc 
)
protected

Reads the parameters and performs initializations that do not depend on other param groups. It is called by the public constructor and should be called by the initializer of any derived classes.

Definition at line 50 of file ColumnEnergyProbe.cpp.

int PV::BaseProbe::initMessage ( const char *  msg)
protectedvirtualinherited

The method called by BaseProbe::initialize() to set the message used by the probe's outputState method.

Definition at line 289 of file BaseProbe.cpp.

int PV::BaseProbe::initNumValues ( )
protectedvirtualinherited

initNumValues is called by initialize. BaseProbe::initNumValues sets numValues to the parent HyPerCol's getNBatch(). Derived classes can override initNumValues to initialize numValues to a different value.

Reimplemented in PV::PointProbe, PV::StatsProbe, PV::KernelProbe, and PV::PointLIFProbe.

Definition at line 227 of file BaseProbe.cpp.

void PV::ColProbe::initOutputStreams ( const char *  filename,
Checkpointer checkpointer 
)
overrideprotectedvirtualinherited

Calls BaseProbe::initOutputStreams and then calls outputHeader()

Reimplemented from PV::BaseProbe.

Definition at line 50 of file ColProbe.cpp.

void PV::BaseProbe::ioParam_coefficient ( enum ParamsIOFlag  ioFlag)
protectedvirtualinherited

coefficient: If energyProbe is set, the coefficient parameter specifies that ColumnEnergyProbe multiplies the result of this probe's getValues() method by coefficient when computing the error.

Note that coefficient does not affect the value returned by the getValue() or getValues() method.

Reimplemented in PV::FirmThresholdCostFnLCAProbe, PV::L0NormLCAProbe, and PV::L1NormLCAProbe.

Definition at line 114 of file BaseProbe.cpp.

int PV::ColumnEnergyProbe::ioParamsFillGroup ( enum ParamsIOFlag  ioFlag)
overrideprotectedvirtual

Reads parameters from the params file/writes parameters to the output params file. If a derived class introduces a new parameter, its ioParamsFillGroup method should call an ioParam_ method for that parameter. If a derived class eliminates a a parameter of the base class, or changes the dependencies of a parameter, it should override the ioParam_ method for that parameter. The derived class's ioParamsFillGroup method should call its base class's ioParamsFillGroup method.

Reimplemented from PV::ColProbe.

Definition at line 39 of file ColumnEnergyProbe.cpp.

bool PV::BaseObject::isUsingGPU ( ) const
inlineinherited

Returns true if the object requires the GPU; false otherwise. HyPerCol will not initialize the GPU unless one of the objects in its hierarchy returns true

Definition at line 79 of file BaseObject.hpp.

bool PV::BaseProbe::isWritingToFile ( ) const
inlineprotectedinherited

Returns true if a probeOutputFile is being used. Otherwise, returns false (indicating output is going to getOutputStream().

Definition at line 328 of file BaseProbe.hpp.

bool PV::ColumnEnergyProbe::needRecalc ( double  timevalue)
overrideprotectedvirtual

Implements the needRecalc method. Always returns true, in the expectation that the hard work is done by the probes in the constituent energy terms.

Implements PV::BaseProbe.

Definition at line 145 of file ColumnEnergyProbe.cpp.

bool PV::BaseProbe::needUpdate ( double  time,
double  dt 
)
protectedvirtualinherited

If there is a triggering layer, needUpdate returns true when the triggering layer's nextUpdateTime, modified by the probe's triggerOffset parameter, occurs; otherwise false. If there is not a triggering layer, needUpdate always returns true. This behavior can be overridden if a probe uses some criterion other than triggering to choose when output its state.

Reimplemented in PV::AdaptiveTimeScaleProbe.

Definition at line 320 of file BaseProbe.cpp.

PrintStream& PV::BaseProbe::output ( int  b)
inlineprotectedinherited

Returns a reference to the PrintStream for the given batch element

Definition at line 289 of file BaseProbe.hpp.

void PV::ColumnEnergyProbe::outputHeader ( )
overrideprotectedvirtual

Called by initialize_stream after opening the stream member variable. Derived classes can override this method to write header data to the output file.

Reimplemented from PV::ColProbe.

Definition at line 54 of file ColumnEnergyProbe.cpp.

int PV::ColumnEnergyProbe::outputState ( double  timevalue)
overridevirtual

Prints the energies to the output stream, formatted as a comma-separated value: "Name of probe",timevalue,index,energy The number of lines printed is equal to getVectorSize(), and index goes from 0 to getVectorSize()-1.

Reimplemented from PV::ColProbe.

Definition at line 170 of file ColumnEnergyProbe.cpp.

int PV::BaseProbe::outputStateWrapper ( double  timef,
double  dt 
)
virtualinherited

The public interface for calling the outputState method. BaseConnection::outputStateWrapper calls outputState() if needUpdate() returns true. This behavior is intended to be general, but the method can be overridden if needed.

Definition at line 375 of file BaseProbe.cpp.

double PV::ColumnEnergyProbe::referenceUpdateTime ( ) const
overrideprotectedvirtual

Implementation of referenceUpdateTime(). Since ColumnEnergyProbe updates every timestep, it uses current simulation time.

Implements PV::BaseProbe.

Definition at line 147 of file ColumnEnergyProbe.cpp.

int PV::BaseProbe::registerData ( Checkpointer checkpointer)
overridevirtualinherited

Called during HyPerCol::run, during the allocateDataStructures stage. BaseProbe::allocateDataStructures sets up the output stream. Derived classes that override this method should make sure to call this method in their own allocateDataStructures methods.

Reimplemented from PV::CheckpointerDataInterface.

Reimplemented in PV::AdaptiveTimeScaleProbe, and PV::StatsProbe.

Definition at line 327 of file BaseProbe.cpp.

void PV::BaseObject::setDataStructuresAllocatedFlag ( )
inlineprotectedinherited

This method sets mDataStructuresAllocatedFlag to true.

Definition at line 111 of file BaseObject.hpp.

void PV::BaseObject::setInitialValuesSetFlag ( )
inlineprotectedinherited

This method sets the flag returned by getInitialValuesSetFlag to true.

Definition at line 116 of file BaseObject.hpp.

void PV::BaseObject::setInitInfoCommunicatedFlag ( )
inlineprotectedinherited

This method sets mInitInfoCommunicatedFlag to true.

Definition at line 106 of file BaseObject.hpp.

int PV::BaseProbe::setNumValues ( int  n)
protectedinherited

Sets the numValues member variable (returned by getNumValues()) and reallocates the probeValues member variable to hold numValues double-precision values. If the reallocation fails, the probeValues buffer is left unchanged, errno is set (by a realloc() call), and PV_FAILURE is returned. Otherwise, PV_SUCCESS is returned.

Definition at line 229 of file BaseProbe.cpp.


The documentation for this class was generated from the following files: