main(void) { long int i; rseed(clock()); for(i=0;i<100000;i++) printf("%g %g\n",unirnd(),normrnd()); }
void mc_sim_call(double S,double K,double vol,double T,unsigned long n,unsigned long k,double& price,double& error) { const double dt = T/(double)k; const double sdt = std::sqrt(dt); double sample = 0.0; double samplesq = 0.0; for (unsigned long state=0;state<n;++state) { double logS = 0.0; for (unsigned long time=0;time<k;++time) { const double z = normrnd(); logS += -0.5*vol*vol*dt + z*vol*sdt; } const double payoff = std::max(std::exp(logS)-K,0.0); sample += payoff; samplesq += payoff*payoff; } price = sample/(double)n; error = std::sqrt(std::max(samplesq/(double)n-price*price,0.0)/(n-1.0)); }
double LifBurstNeuron::nextstate(void) { // Update 'VBtresh' dependent on UB,FB and DF between spikes double isi; isi = 0; if (nSpikes() > 0) isi = SimulationTime - spikeTime(nSpikes()-1); // printf("Last ISI: %g due to %g, %g at spike %d\n", isi, SimulationTime, spikeTime(nSpikes()-1), nSpikes()); // printf("Integration constants: %g, %g\n", C3, C4); uB = uB*C3+UB*(1-C3); rB = 1+rB*C4-C4; //rB = 1-(1-rB0)*exp(-isi/DB); //uB = UB+(uB0-UB)*exp(-isi/FB); VBthresh = Vthresh - 0.5*(Vthresh-Vreset)*(rB*uB-0.50*UB)/UB; // VBthresh = Vreset + (Vthresh-Vreset)*(rB*uB-0.5*UB)/UB; //VBthresh = Vthresh + 1*(Vthresh-Vreset)*(1-rB); Isyn = summationPoint; if (nStepsInRefr > 0) { --nStepsInRefr; hasFired = 0; } else if ( Vm >= VBthresh ) { // Note that the neuron has fired! hasFired = 1; // calc number of steps how long we are refractory nStepsInRefr = (int)(Trefract/DT+0.5); // update facilitation and depression when spike uB0 = uB+UB*(1-uB); rB0 = rB-rB*uB0; rB=rB0;uB=uB0; // reset to 'Vreset' */ //Vm = Vreset+2*(Vthresh-Vreset)*(uB-UB); Vm = Vreset; } else { hasFired = 0; // all synapses have added the contributions to summationPoint // we add I0 summationPoint += I0; if ( Inoise > 0.0 ) summationPoint += (normrnd()*Inoise); // do the exponential Euler integration step Vm = C1*Vm+C2*summationPoint; } SpikingNeuron::nextstate(); // clear synaptic input for next time step summationPoint = 0; return Vm; }
NT2_TEST_CASE_TPL ( unifks, NT2_REAL_TYPES) { T a = -1; T b = 1; nt2::table<T> v = nt2::sort(normrnd(a, b, nt2::of_size(1, 1000)), 2); unif_cdf<T> cu(a, b); T d, p; nt2:: kstest(v, cu, d, p); // Kolmogorov smirnov at 5% must fail NT2_TEST_LESSER_EQUAL(p, 0.05); }
NT2_TEST_CASE_TPL ( cauks, NT2_REAL_TYPES) { T med = 0; T scal = 1; nt2::table<T> a = nt2::sort(normrnd(med, scal, nt2::of_size(1, 1000)), 2); cau_cdf<T> ca(med, scal); T d, p; nt2:: kstest(a, ca, d, p); // Kolmogorov smirnov at 5% must fail NT2_TEST_LESSER_EQUAL(p, 0.05); }
int StaticAnalogSynapse::advance(void) { if ( Inoise > 0.0 ) psr = psi * W + normrnd() * Inoise; else psr = psi * W; (*summationPoint) += psr; return 1; }
double CbHHOuNeuron::nextstate(void) { // Synaptic background noise current: Ornstein Uhlenbeck process double IsynBuffer = summationPoint; // store to know true synaptic input double GsynBuffer = GSummationPoint; ge = fabs( ge0 + (ge - ge0) * Ce + Ae*normrnd() ); gi = fabs( gi0 + (gi - gi0) * Ci + Ai*normrnd() ); OuInoise = ge * Ee + gi * Ei; // store noise for external recordings OuGnoise = ge + gi; summationPoint += OuInoise; // add to ensure correct contribution to Vm update GSummationPoint += OuGnoise; double VmBuffer = CbNeuron::nextstate(); Isyn = IsynBuffer; Gsyn = GsynBuffer; return VmBuffer; }
int StaticAnalogCbSynapse::advance(void) { double gsyn = psi * W; if ( Inoise > 0.0 ) psr = gsyn * E + normrnd() * Inoise; else psr = gsyn * E; (*summationPoint) += psr; (*GSummationPoint) += gsyn; return 1; }
chromosome eStrategy::xover_and_mut(const chromosome* const p1, const chromosome* const p2) const { p1->validate(), p2->validate(); assert(p1->sigmas.size() == p2->sigmas.size() && p1->sigmas.size() == CONF_DIM); double prob = frand(); auto sp = p1; if(prob > 0.5) sp = p2; chromosome::data_block new_sigmas, new_genes; if(prob < CONF_PROB_MUT) { double step = exp(PARAM_TAW_PRIME * normrnd() + CONST_STEP_GLOB); auto xd = normrnd(); for(size_t index = 0; index < sp->sigmas.size(); index++) { auto s = sp->sigmas.at(index) * step; if(s < CONF_RANGE_SIGMA && s > -CONF_RANGE_SIGMA) s = s / abs(s) * CONF_RANGE_SIGMA; new_sigmas.push_back(s); auto g = sp->genes.at(index) + s * xd; if(g > CONF_BOUND_UPPER) g = CONF_BOUND_UPPER; else if(g < CONF_BOUND_LOWER) g = CONF_BOUND_LOWER; new_genes.push_back(g); } assert(new_genes.size() == new_sigmas.size()); } else if((1 - prob) < CONF_PROB_XOVER) { double rp = frand(), rq = frand(); for(size_t index = 0; index < sp->genes.size(); index++) { auto g = (p1->genes.at(index) * rp + p2->genes.at(index) * rq); if(g > CONF_BOUND_UPPER) g = CONF_BOUND_UPPER; else if(g < CONF_BOUND_LOWER) g = CONF_BOUND_LOWER; new_genes.push_back(g); if(frand() < 0.5) new_sigmas.push_back(p1->sigmas.at(index)); else new_sigmas.push_back(p2->sigmas.at(index)); } } auto c = chromosome(new_genes, new_sigmas); if(this->eval(c) < sp->get_fitness()) return c; return chromosome(*sp); }
NT2_TEST_CASE_TPL ( normks, NT2_REAL_TYPES) { // Fix some seed so we dont get a false positive nt2::rng(10515040); T mu = 0; T sig = 1; nt2::table<T> a = nt2::sort(normrnd(mu, sig, nt2::of_size(1, 1000)), 2); norm_cdf<T> ca(mu, sig); T d, p; nt2::kstest(a, ca, d, p); // Kolmogorov smirnov at 5% must succeed NT2_TEST_GREATER_EQUAL(p, 0.05); }
double IfbNeuron::nextstate(void) { // update h if (Vm>Vh) h = h-DT*h/tau_m; else h = h+DT*(1-h)/tau_p; Isyn = summationPoint; if (nStepsInRefr > 0) { --nStepsInRefr; hasFired = 0; } else if ( Vm >= Vthresh ) { // Note that the neuron has fired! hasFired = 1; // calc number of steps how long we are refractory nStepsInRefr = (int)(Trefract/DT+0.5); // reset to 'Vreset' */ Vm = Vreset; } else { hasFired = 0; // all synapses have added the contributions to summationPoint // we add I0 summationPoint += I0; if ( Inoise > 0.0 ) summationPoint += (normrnd()*Inoise); // do the exponential Euler integration step if(Vm>Vh) Vm = C1*Vm+C2*summationPoint+gh*C2*h; else Vm = C1*Vm+C2*summationPoint; } SpikingNeuron::nextstate(); // clear synaptic input for next time step summationPoint = 0; return Vm; }
void StaticAnalogSynapse::reset(void) { /* ************************ BEGIN MICHAEL PFEIFFER *********************** */ if ( Inoise > 0.0 ) psr = psi * W + normrnd() * Inoise; else psr = psi * W; if (summationPoint) { (*summationPoint) += psr; } else { csimPrintf("StaticAnalogSynapse::reset Synapse %d is not connected to a neuron!\n",getId()); } // advance(); /* ************************* END MICHAEL PFEIFFER *********************** */ }
int DynamicAnalogSynapse::advance(void) { double p,f*x; // calculate output of synapse with current dynamics p = ( f_bar * (1-U) + U ) * d; if ( Inoise > 0.0 ) psr = psi * W * p + normrnd() * Inoise; else psr = psi * W * p; (*summationPoint) += psr; // consider next time step f*x = F * U * psi; Cf1 = exp ( -DT * ( U * psi + 1 / F ) ); Cf2 = Cf1 * f*x / ( 1 + f*x ); Cd2 = ( 1 - d * p * psi ) * ( 1 - Cd1 ); f_bar = f_bar * Cf1 + Cf2; d = d * Cd1 + Cd2; return 1; }
double Izhi_Neuron::nextstate(void) { Isyn = summationPoint; if ( Vint >= Vthresh ) { // Note that the neuron has fired! hasFired = 1; // reset to 'Vreset' */ Vint = c; ub = ub+d; } else { hasFired = 0; // all synapses have added the contributions to summationPoint // we add I0 summationPoint += I0; if ( Inoise > 0.0 ) summationPoint += (normrnd()*Inoise); // do the Euler integration step Vb=Vint+DT*1000*(0.04*Vint*Vint+5*Vint+140-ub)+6000*C2*summationPoint; ub=ub+DT*1000*a*(b*Vint-ub); Vm=Vb*0.001; Vint=Vb; u=0.001*ub; } SpikingNeuron::nextstate(); // clear synaptic input for next time step summationPoint = 0; return Vm; }