Beispiel #1
0
void SpikingOutput::initialize_state(){
    CImg<double>::iterator next_spk_time_it = next_spk_time->begin();
    CImg<double>::iterator curr_ref_period_it = curr_ref_period->begin();

    while(next_spk_time_it < next_spk_time->end()){ // For every spiking output
        double first_firing_period;
        // To initialize the state of each output, we set the last next_spk_time
        // to the next firing period.
        
        // Determine firing period in the "unwarped" time slot
        if(isfinite(Spike_dist_shape)) // Select stochastic or deterministic spike times
            first_firing_period = gam_dist(rand_gen);
        else // Spike_dist_shape is infinite (not specified), so we do not use stochasticity
            first_firing_period = 1; // 1Hz is the firing freq. in a "unwarped" time slot

        *next_spk_time_it = first_firing_period * First_spk_delay; // Anticipate (if First_spk_delay < 1) or postpone (if First_spk_delay > 1) first spike time according to First_spk_delay
        
        // Set refractory eriod for each neuron
        if(Min_period_std_dev == 0.0) // If fixed refractory period:
            *curr_ref_period_it = Min_period/1000.0;
        else
            *curr_ref_period_it = norm_dist(rand_gen);
            
        next_spk_time_it++;
        curr_ref_period_it++;
    }
}
Beispiel #2
0
// time of next spike (*next_spk_time_it) is relative to slot start time and corresponding to a input rate of value 1.
// *next_spk_time_it specifies the spike time in a "unwarped" time slot (time is then scaled according to input rate)
// told_next_spk specifies the real time of spike (warped)
// So, the length of a warped simulation time slot is step and
// the length of a unwarped simulation time slot is step*mean_firing_rate, this is step/inp_pix_per
vector<spike_t> SpikingOutput::stochastic_spike_generation(unsigned long out_neu_idx, double input_val, CImg<double>::iterator next_spk_time_it, CImg<double>::iterator last_spk_time_it, CImg<double>::iterator curr_ref_period_it){
    vector<spike_t> slot_spks; // Temporal vector of output spikes for current sim. time slot
    // Intermediate variables used to calculate next spike time
    double inp_pix_per;
    double tslot_start, slot_len;

    // All calculations are done in whole units, so convert class time properties (in ms) into seconds
    tslot_start = simTime / 1000.0; // Start time of the current sim. slot: Convert it into seconds
    slot_len = step / 1000.0; // Length in time of a simulation slot (step)

    inp_pix_per = inp_pixel_to_period(input_val); // Convert input pixel magnitude into firing period in seconds
    // If input is not zero, we do not have to calculate spike times but the expression for updating
    // the next spike time becomes an indeterminate form, so evaluate its limit
    if(isfinite(inp_pix_per)) {
        double new_spk_time; // New spike time relative to current time slot start
        spike_t new_spk;

        new_spk.neuron = out_neu_idx; // Index of output neuron are assigned in the same way as Cimg pixel offsets
        // We can have several spikes in a single simulation time slot: iterate
        while((new_spk_time = apply_ref_period(*next_spk_time_it * inp_pix_per, *last_spk_time_it - tslot_start, *curr_ref_period_it)) < slot_len){ // warp next spike time accoring to input rate to get the desired firing rate and apply ref. period
            double firing_period;

            new_spk.time = tslot_start + new_spk_time; // Time of next spike
            // These conditions should never be met:
            if(new_spk.time < tslot_start)
                cout << "Internal error: a spike for a previous simulation step has been generated. current step [" << tslot_start << "," << tslot_start + slot_len << ") spike time:" << new_spk.time << "s" << endl;
            if(!isfinite(*next_spk_time_it))
                cout << "Internal error: spike time could not be calculated (indeterminate form). current step [" << tslot_start << "," << tslot_start + slot_len << ") spike time:" << new_spk.time << endl;

            slot_spks.push_back(new_spk); // Insert spike in list
            *last_spk_time_it = new_spk.time; // Update last spike time
            renew_ref_period_val(curr_ref_period_it);
            
            // Determine firing period in the "unwarped" time slot
            if(isfinite(Spike_dist_shape)) // Select stochastic or deterministic spike times
                firing_period = gam_dist(rand_gen);
            else // Spike_dist_shape is infinite (not specified), so we do not use stochasticity
                firing_period = 1; // 1Hz is the firing freq. in a "unwarped" time slot
        
            *next_spk_time_it = *next_spk_time_it + firing_period; // Update the time of predicted next firing for this neuron
        }
        *next_spk_time_it = *next_spk_time_it - slot_len/inp_pix_per; // Make *next_spk_time_it relative to the next time slot
    }
    return(slot_spks);
}
Beispiel #3
0
struct brkdn_dist *
brkdn_dist(unsigned short seed[3])
{
	int i;
	struct brkdn_dist *apps = (struct brkdn_dist *) malloc(NUMAPP*sizeof(struct brkdn_dist));
	float normalizer = 0.0;

	for (i = 0; i < NUMAPP; i++) {
		apps[i].appname = apps_brkdn[i].appname;
		apps[i].cdf = gam_dist(apps_brkdn[i].mean, apps_brkdn[i].mean_sqr, apps_brkdn[i].var, seed);
		normalizer += apps[i].cdf;
	}

	apps[0].cdf /= normalizer;
	for (i = 1; i < NUMAPP; i++) {
		apps[i].cdf /= normalizer;
		apps[i].cdf += apps[i-1].cdf;
	}

	return apps;
}