Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding inhomogeneous poisson generator model #671

Merged
merged 15 commits into from
Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ set( models_sources
music_message_in_proxy.h music_message_in_proxy.cpp
noise_generator.h noise_generator.cpp
parrot_neuron.h parrot_neuron.cpp
inh_poisson_generator.h inh_poisson_generator.cpp
inhomogeneous_poisson_generator.h inhomogeneous_poisson_generator.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a spurious indent.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

poisson_generator.h poisson_generator.cpp
pp_psc_delta.h pp_psc_delta.cpp
pp_pop_psc_delta.h pp_pop_psc_delta.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* inh_poisson_generator.cpp
* inhomogeneous_poisson_generator.cpp
*
* This file is part of NEST.
*
Expand All @@ -19,7 +19,7 @@
* along with NEST. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "inh_poisson_generator.h"
#include "inhomogeneous_poisson_generator.h"

#include "event_delivery_manager_impl.h"
#include "kernel_manager.h"
Expand All @@ -41,7 +41,7 @@
* Default constructors defining default parameter
* ---------------------------------------------------------------- */

nest::inh_poisson_generator::Parameters_::Parameters_()
nest::inhomogeneous_poisson_generator::Parameters_::Parameters_()
: rate_times_() // ms
, rate_values_() // spikes/ms
{
Expand All @@ -52,7 +52,7 @@ nest::inh_poisson_generator::Parameters_::Parameters_()
* ---------------------------------------------------------------- */

void
nest::inh_poisson_generator::Parameters_::get( DictionaryDatum& d ) const
nest::inhomogeneous_poisson_generator::Parameters_::get( DictionaryDatum& d ) const
{
( *d )[ names::rate_times ] =
DoubleVectorDatum( new std::vector< double_t >( rate_times_ ) );
Expand All @@ -61,15 +61,15 @@ nest::inh_poisson_generator::Parameters_::get( DictionaryDatum& d ) const
}

void
nest::inh_poisson_generator::Parameters_::set( const DictionaryDatum& d,
nest::inhomogeneous_poisson_generator::Parameters_::set( const DictionaryDatum& d,
Buffers_& b )
{
const bool ut =
const bool times =
updateValue< std::vector< double_t > >( d, names::rate_times, rate_times_ );
const bool uv = updateValue< std::vector< double_t > >(
const bool rates = updateValue< std::vector< double_t > >(
d, names::rate_values, rate_values_ );

if ( ut xor uv )
if ( times xor rates )
{
throw BadProperty( "Rate times and values must be reset together." );
}
Expand All @@ -80,7 +80,7 @@ nest::inh_poisson_generator::Parameters_::set( const DictionaryDatum& d,
}

// ensure amp times are strictly monotonically increasing
if ( rate_times_.empty() == false )
if ( not rate_times_.empty() )
{
std::vector< double_t >::const_iterator prev = rate_times_.begin();
std::vector< double_t >::const_iterator next = prev + 1;
Expand All @@ -93,7 +93,7 @@ nest::inh_poisson_generator::Parameters_::set( const DictionaryDatum& d,
}
}

if ( ut && uv )
if ( times && rates )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& -> and

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
b.idx_ = 0; // reset if we got new data
}
Expand All @@ -103,43 +103,43 @@ nest::inh_poisson_generator::Parameters_::set( const DictionaryDatum& d,
* Default and copy constructor for node
* ---------------------------------------------------------------- */

nest::inh_poisson_generator::inh_poisson_generator()
nest::inhomogeneous_poisson_generator::inhomogeneous_poisson_generator()
: Node()
, device_()
, P_()
{
}

nest::inh_poisson_generator::inh_poisson_generator(
const inh_poisson_generator& n )
nest::inhomogeneous_poisson_generator::inhomogeneous_poisson_generator(
const inhomogeneous_poisson_generator& n )
: Node( n )
, device_( n.device_ )
, P_( n.P_ )
{
}


/* ----------------------------------------------------------------
* Node initialization functions
* ---------------------------------------------------------------- */
void
nest::inh_poisson_generator::init_state_( const Node& proto )
nest::inhomogeneous_poisson_generator::init_state_( const Node& proto )
{
const inh_poisson_generator& pr = downcast< inh_poisson_generator >( proto );
const inhomogeneous_poisson_generator& pr =
downcast< inhomogeneous_poisson_generator >( proto );

device_.init_state( pr.device_ );
}

void
nest::inh_poisson_generator::init_buffers_()
nest::inhomogeneous_poisson_generator::init_buffers_()
{
device_.init_buffers();
B_.idx_ = 0;
B_.rate_ = 0;
}

void
nest::inh_poisson_generator::calibrate()
nest::inhomogeneous_poisson_generator::calibrate()
{
device_.calibrate();
V_.h_ = Time::get_resolution().get_ms();
Expand All @@ -150,7 +150,7 @@ nest::inh_poisson_generator::calibrate()
* ---------------------------------------------------------------- */

void
nest::inh_poisson_generator::update( Time const& origin,
nest::inhomogeneous_poisson_generator::update( Time const& origin,
const long from,
const long to )
{
Expand All @@ -164,7 +164,6 @@ nest::inh_poisson_generator::update( Time const& origin,
// random number generator
librandom::RngPtr rng = kernel().rng_manager.get_rng( get_thread() );


// Skip any times in the past. Since we must send events proactively,
// idx_ must point to times in the future.
const long first = t0 + from;
Expand All @@ -180,17 +179,16 @@ nest::inh_poisson_generator::update( Time const& origin,

// Keep the amplitude up-to-date at all times.
// We need to change the amplitude one step ahead of time, see comment
// on class SimulatingDevice.
if ( B_.idx_ < P_.rate_times_.size()
&& curr_time + 1
== Time( Time::ms( P_.rate_times_[ B_.idx_ ] ) ).get_steps() )
// on class StimulatingDevice.
if ( B_.idx_ < P_.rate_times_.size() && curr_time + 1
== Time( Time::ms( P_.rate_times_[ B_.idx_ ] ) ).get_steps() )
{
B_.rate_ = P_.rate_values_[ B_.idx_ ] / 1000.0; // scale the rate to ms^-1
B_.idx_++;
++B_.idx_;
}

// create spikes
if ( B_.rate_ > 0 && device_.is_active( Time::step( t0 + offs ) ) )
if ( B_.rate_ > 0 && device_.is_active( Time::step( curr_time ) ) )
{
DSSpikeEvent se;
kernel().event_delivery_manager.send( *this, se, offs );
Expand All @@ -199,7 +197,7 @@ nest::inh_poisson_generator::update( Time const& origin,
}

void
nest::inh_poisson_generator::event_hook( DSSpikeEvent& e )
nest::inhomogeneous_poisson_generator::event_hook( DSSpikeEvent& e )
{
librandom::RngPtr rng = kernel().rng_manager.get_rng( get_thread() );
V_.poisson_dev_.set_lambda( B_.rate_ * V_.h_ );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* inh_poisson_generator.h
* inhomogeneous_poisson_generator.h
*
* This file is part of NEST.
*
Expand All @@ -22,15 +22,15 @@


/*BeginDocumentation
Name: inh_poisson_generator - provides Poisson spike trains at a piecewise
constant rate
Name: inhomogeneous_poisson_generator - provides Poisson spike trains
at a piecewise constant rate

Description:
The inhomogeneous Poisson generator provides Poisson spike trains at a
piecewise constant rate
to the connected node(s). The rate of the process is changed at the
specified times. The unit of the instantaneous rate is spikes/s.
By default, each target of the generator will receive a different spike train.
piecewise constant rate to the connected node(s). The rate of the process
is changed at the specified times. The unit of the instantaneous rate
is spikes/s. By default, each target of the generator will receive
a different spike train.

Parameters:
The following parameters can be set in the status dictionary:
Expand All @@ -40,7 +40,7 @@

Examples:
The current can be altered in the following way:
/inh_poisson_generator Create /sc Set
/inhomogeneous_poisson_generator Create /sc Set
sc << /rate_times [0.2 0.5] /rate_values [2.0 4.0] >> SetStatus

The average firing rate of each realization of the Poisson process will be
Expand All @@ -67,8 +67,8 @@
SeeAlso: sinusoidal_poisson_generator, step_current_generator, Device,
StimulatingDevice
*/
#ifndef INH_POISSON_GENERATOR_H
#define INH_POISSON_GENERATOR_H
#ifndef INHOMOGENEOUS_POISSON_GENERATOR_H
#define INHOMOGENEOUS_POISSON_GENERATOR_H

#include "poisson_randomdev.h"

Expand All @@ -86,12 +86,12 @@
namespace nest
{

class inh_poisson_generator : public Node
class inhomogeneous_poisson_generator : public Node
{

public:
inh_poisson_generator();
inh_poisson_generator( const inh_poisson_generator& );
inhomogeneous_poisson_generator();
inhomogeneous_poisson_generator( const inhomogeneous_poisson_generator& );

bool
has_proxies() const
Expand All @@ -104,14 +104,8 @@ class inh_poisson_generator : public Node
* @see Technical Issues / Virtual Functions: Overriding, Overloading, and
* Hiding
*/
// using Node::handle;
// using Node::handles_test_event;
using Node::event_hook;

// void handle( DataLoggingRequest& );

// port handles_test_event( DataLoggingRequest&, rport );

port send_test_event( Node&, rport, synindex, bool );

void get_status( DictionaryDatum& ) const;
Expand All @@ -128,17 +122,6 @@ class inh_poisson_generator : public Node

struct Buffers_;

/*
* Buffers of the model.

struct Buffers_
{
Buffers_( inh_poisson_generator& );
Buffers_( const Buffers_&, inh_poisson_generator& );
UniversalDataLogger< inh_poisson_generator > logger_;
};
*/

/*
* Store independent parameters of the model.
*/
Expand All @@ -149,7 +132,6 @@ class inh_poisson_generator : public Node

Parameters_(); //!< Sets default parameter values
Parameters_( const Parameters_&, Buffers_& );
// Parameters_& operator=( const Parameters_& p ); // Copy constructor EN

void get( DictionaryDatum& ) const; //!< Store current values in dictionary
void set( const DictionaryDatum&,
Expand Down Expand Up @@ -182,7 +164,7 @@ class inh_poisson_generator : public Node
};

inline port
inh_poisson_generator::send_test_event( Node& target,
inhomogeneous_poisson_generator::send_test_event( Node& target,
rport receptor_type,
synindex syn_id,
bool dummy_target )
Expand All @@ -207,14 +189,14 @@ inh_poisson_generator::send_test_event( Node& target,


inline void
inh_poisson_generator::get_status( DictionaryDatum& d ) const
inhomogeneous_poisson_generator::get_status( DictionaryDatum& d ) const
{
P_.get( d );
device_.get_status( d );
}

inline void
inh_poisson_generator::set_status( const DictionaryDatum& d )
inhomogeneous_poisson_generator::set_status( const DictionaryDatum& d )
{
Parameters_ ptmp = P_; // temporary copy in case of errors

Expand All @@ -230,4 +212,4 @@ inh_poisson_generator::set_status( const DictionaryDatum& d )

} // namespace

#endif // INH_POISSON_GENERATOR_H
#endif // INHOMOGENEOUS_POISSON_GENERATOR_H
6 changes: 3 additions & 3 deletions models/modelsmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
#include "mip_generator.h"
#include "noise_generator.h"
#include "poisson_generator.h"
#include "inh_poisson_generator.h"
#include "inhomogeneous_poisson_generator.h"
#include "ppd_sup_generator.h"
#include "pulsepacket_generator.h"
#include "sinusoidal_gamma_generator.h"
Expand Down Expand Up @@ -207,8 +207,8 @@ ModelsModule::init( SLIInterpreter* )
kernel().model_manager.register_node_model< dc_generator >( "dc_generator" );
kernel().model_manager.register_node_model< spike_generator >(
"spike_generator" );
kernel().model_manager.register_node_model< inh_poisson_generator >(
"inh_poisson_generator" );
kernel().model_manager.register_node_model< inhomogeneous_poisson_generator >(
"inhomogeneous_poisson_generator" );
kernel().model_manager.register_node_model< poisson_generator >(
"poisson_generator" );
kernel().model_manager.register_node_model< pulsepacket_generator >(
Expand Down