Пример #1
0
ArrayDatum
ConnectionManager::get_connections( DictionaryDatum params ) const
{
  ArrayDatum connectome;

  const Token& source_t = params->lookup( names::source );
  const Token& target_t = params->lookup( names::target );
  const Token& syn_model_t = params->lookup( names::synapse_model );
  const TokenArray* source_a = 0;
  const TokenArray* target_a = 0;

  if ( not source_t.empty() )
    source_a = dynamic_cast< TokenArray const* >( source_t.datum() );
  if ( not target_t.empty() )
    target_a = dynamic_cast< TokenArray const* >( target_t.datum() );

  size_t syn_id = 0;

#ifdef _OPENMP
  std::string msg;
  msg = String::compose( "Setting OpenMP num_threads to %1.", net_.get_num_threads() );
  net_.message( SLIInterpreter::M_DEBUG, "ConnectionManager::get_connections", msg );
  omp_set_num_threads( net_.get_num_threads() );
#endif

  // First we check, whether a synapse model is given.
  // If not, we will iterate all.
  if ( not syn_model_t.empty() )
  {
    Name synmodel_name = getValue< Name >( syn_model_t );
    const Token synmodel = synapsedict_->lookup( synmodel_name );
    if ( !synmodel.empty() )
      syn_id = static_cast< size_t >( synmodel );
    else
      throw UnknownModelName( synmodel_name.toString() );
    get_connections( connectome, source_a, target_a, syn_id );
  }
  else
  {
    for ( syn_id = 0; syn_id < prototypes_[ 0 ].size(); ++syn_id )
    {
      ArrayDatum conn;
      get_connections( conn, source_a, target_a, syn_id );
      if ( conn.size() > 0 )
        connectome.push_back( new ArrayDatum( conn ) );
    }
  }

  return connectome;
}
Пример #2
0
void
nest::weight_recorder::Parameters_::set( const DictionaryDatum& d )
{
  if ( d->known( names::senders ) )
  {
    senders_ = getValue< std::vector< long > >( d->lookup( names::senders ) );
    std::sort( senders_.begin(), senders_.end() );
  }

  if ( d->known( names::targets ) )
  {
    targets_ = getValue< std::vector< long > >( d->lookup( names::targets ) );
    std::sort( targets_.begin(), targets_.end() );
  }
}
void
aeif_cond_alpha_multisynapse::State_::set( const DictionaryDatum& d )
{
  updateValue< double >( d, names::V_m, y_[ V_M ] );

  if ( ( d->known( names::g_ex ) ) && ( d->known( names::dg_ex ) ) && ( d->known( names::g_in ) )
    && ( d->known( names::dg_in ) ) )
  {
    const std::vector< double_t > g_exc =
      getValue< std::vector< double_t > >( d->lookup( names::g_ex ) );
    const std::vector< double_t > dg_exc =
      getValue< std::vector< double_t > >( d->lookup( names::dg_ex ) );
    const std::vector< double_t > g_inh =
      getValue< std::vector< double_t > >( d->lookup( names::g_in ) );
    const std::vector< double_t > dg_inh =
      getValue< std::vector< double_t > >( d->lookup( names::dg_in ) );

    if ( ( g_exc.size() != dg_exc.size() ) || ( g_exc.size() != g_inh.size() )
      || ( g_exc.size() != dg_inh.size() ) )
    {
      throw BadProperty( "Conductances must have the same sizes." );
    }

    for ( size_t i = 0; i < g_exc.size(); ++i )
    {
      if ( ( g_exc[ i ] < 0 ) || ( dg_exc[ i ] < 0 ) || ( g_inh[ i ] < 0 ) || ( dg_inh[ i ] < 0 ) )
      {
        throw BadProperty( "Conductances must not be negative." );
      }

      y_[ State_::G_EXC + ( State_::NUMBER_OF_STATES_ELEMENTS_PER_RECEPTOR * i ) ] = g_exc[ i ];
      y_[ State_::DG_EXC + ( State_::NUMBER_OF_STATES_ELEMENTS_PER_RECEPTOR * i ) ] = dg_exc[ i ];
      y_[ State_::G_INH + ( State_::NUMBER_OF_STATES_ELEMENTS_PER_RECEPTOR * i ) ] = g_inh[ i ];
      y_[ State_::DG_INH + ( State_::NUMBER_OF_STATES_ELEMENTS_PER_RECEPTOR * i ) ] = dg_inh[ i ];
    }
  }

  updateValue< double >( d, names::w, y_[ W ] );
}
Пример #4
0
void nest::spike_generator::Parameters_::set(const DictionaryDatum& d, State_& s,
        const Time& origin, const Time& now)
{
    const bool flags_changed =    updateValue<bool>(d, names::precise_times, precise_times_)
                                  || updateValue<bool>(d, "allow_offgrid_spikes", allow_offgrid_spikes_)
                                  || updateValue<bool>(d, "shift_now_spikes", shift_now_spikes_);
    if ( precise_times_ && ( allow_offgrid_spikes_ || shift_now_spikes_ ) )
        throw BadProperty("Option precise_times cannot be set to true when either allow_offgrid_spikes "
                          "or shift_now_spikes is set to true.");

    const bool updated_spike_times = d->known(names::spike_times);
    if ( flags_changed && !(updated_spike_times || spike_stamps_.empty()) )
        throw BadProperty("Options can only be set together with spike times or if no "
                          "spike times have been set.");

    if ( updated_spike_times )
    {
        const std::vector<double_t> d_times = getValue<std::vector<double> >(d->lookup(names::spike_times));
        const size_t n_spikes = d_times.size();
        spike_stamps_.clear();
        spike_stamps_.reserve(n_spikes);
        spike_offsets_.clear();
        if ( precise_times_ )
            spike_offsets_.reserve(n_spikes);

        // Check spike times for ordering and grid compatibility and insert them
        if ( !d_times.empty() )
        {
            // handle first spike time, no predecessor to compare with
            std::vector<double_t>::const_iterator prev = d_times.begin();
            assert_valid_spike_time_and_insert_(*prev, origin, now);

            // handle all remaining spike times, compare to predecessor
            for ( std::vector<double_t>::const_iterator next = prev + 1;
                    next != d_times.end() ; ++next, ++prev )
                if ( *prev > *next )
                    throw BadProperty("Spike times must be sorted in non-descending order.");
                else
                    assert_valid_spike_time_and_insert_(*next, origin, now);
        }
    }

    // spike_weights can be the same size as spike_times, or can be of size 0 to
    // only use the spike_times array
    bool updated_spike_weights = d->known("spike_weights");
    if (updated_spike_weights)
    {
        std::vector<double> spike_weights = getValue<std::vector<double> >(d->lookup("spike_weights"));

        if (spike_weights.empty())
            spike_weights_.clear();
        else
        {
            if (spike_weights.size() != spike_stamps_.size())
                throw BadProperty("spike_weights must have the same number of elements as spike_times,"
                                  " or 0 elements to clear the property.");

            spike_weights_.swap(spike_weights);
        }
    }

    // Set position to start if something changed
    if ( updated_spike_times || updated_spike_weights || d->known(names::origin) )
        s.position_ = 0;
}
Пример #5
0
  index AbstractLayer::create_layer(const DictionaryDatum & layer_dict)
  {
    index length = 0;
    const char *layer_model_name = 0;
    std::vector<long_t> element_ids;
    std::string element_name;
    Token element_model;

    const Token& t = layer_dict->lookup(names::elements);
    ArrayDatum* ad = dynamic_cast<ArrayDatum *>(t.datum());

    if (ad) {

      for (Token* tp = ad->begin(); tp != ad->end(); ++tp) {

        element_name = std::string(*tp);
        element_model = net_->get_modeldict().lookup(element_name);

        if ( element_model.empty() )
          throw UnknownModelName(element_name);

        // Creates several nodes if the next element in
        // the elements variable is a number.
        if ((tp+1 != ad->end()) && dynamic_cast<IntegerDatum*>((tp+1)->datum())) {
          // Select how many nodes that should be created.
          const long_t number = getValue<long_t>(*(++tp));

          for(long_t i=0;i<number;++i)
            element_ids.push_back(static_cast<long>(element_model));
        } else {
          element_ids.push_back(static_cast<long>(element_model));
        }

      }

    } else {

      element_name = getValue<std::string>(layer_dict, names::elements);
      element_model = net_->get_modeldict().lookup(element_name);

      if ( element_model.empty() )
        throw UnknownModelName(element_name);

      element_ids.push_back(static_cast<long>(element_model));

    }

    if (layer_dict->known(names::positions)) {
      if (layer_dict->known(names::rows) or layer_dict->known(names::columns) or layer_dict->known(names::layers))
        throw BadProperty("Can not specify both positions and rows or columns.");

      TokenArray positions = getValue<TokenArray>(layer_dict, names::positions);

      if (positions.size() == 0) {
        throw BadProperty("Empty positions array.");
      }

      std::vector<double_t> pos = getValue<std::vector<double_t> >(positions[0]);
      if (pos.size() == 2)
        layer_model_name = "topology_layer_free";
      else if (pos.size() == 3)
        layer_model_name = "topology_layer_free_3d";
      else
        throw BadProperty("Positions must have 2 or 3 coordinates.");

      length = positions.size();

    } else if (layer_dict->known(names::columns)) {

      if (not layer_dict->known(names::rows)) {
        throw BadProperty("Both columns and rows must be given.");
      }

      length=getValue<long_t>(layer_dict, names::columns) * getValue<long_t>(layer_dict, names::rows);

      if (layer_dict->known(names::layers)) {
        layer_model_name = "topology_layer_grid_3d";
        length *= getValue<long_t>(layer_dict, names::layers);
      } else {
        layer_model_name = "topology_layer_grid";
      }

    } else {
      throw BadProperty("Unknown layer type.");
    }

    assert(layer_model_name != 0);
    Token layer_model = net_->get_modeldict().lookup(layer_model_name);
    if ( layer_model.empty() )
      throw UnknownModelName(layer_model_name);

    index layer_node = net_->add_node(layer_model);

    // Remember original subnet
    const index cwnode = net_->get_cwn()->get_gid();
					  
    net_->go_to(layer_node);

    // Create layer nodes.
    for ( size_t i = 0 ; i < element_ids.size() ; ++i )
    {
      for ( index n = 0 ; n < length ; ++n )
      {
        net_->add_node(element_ids[i]);
      }
    }

    // Return to original subnet
    net_->go_to(cwnode);

    //Set layer parameters according to input dictionary.
    AbstractLayer *layer = dynamic_cast<AbstractLayer *>(net_->get_node(layer_node));
    layer->depth_ = element_ids.size();
    layer->set_status(layer_dict);

    return layer_node;
  }