/*--------------------------------------------------------------------------
   Author: Thomas Nowotny
  
   Institute: Institute for Nonlinear Dynamics
              University of California San Diego
              La Jolla, CA 92093-0402
  
   email to:  tnowotny@ucsd.edu
  
   initial version: 2005-08-17
  
--------------------------------------------------------------------------*/

#ifndef CN_POPPOISSONN_H
#define CN_POPPOISSONN_H

#include "CN_neuron.h"

#define POPPOI_IVARNO 0
#define POPPOI_PNO 1

double stdPOPPOI_p[POPPOI_PNO]= {
  0.0  // refractory period [ms]
};

double *POPPOI_p= stdPOPPOI_p;

class PopPoissonN: public neuron
{
 private:
  double fire_t;
  double next_spike;
  double *Lambda;
  
 public:
  PopPoissonN(int, vector<int>, double *);
  PopPoissonN(int, double *);
  ~PopPoissonN();
  virtual double E(double *);
  virtual void validate_E(double *, double);
  virtual void step();
  virtual void derivative(double *, double *) { }
  virtual void init(double *, double *);
  virtual void set_Lambda(double *);  // set an external rate variable
};

// this typical spike form was lifted from Valneurons

#define PPSPIKE_DURATION 7.91
#define PPSPIKE_DT 0.01
#define PPMAXIT 790

double PPSPIKEV[791]= {
  -6.0526905e+01,
  -6.0519070e+01,
  -6.0511258e+01,
  -6.0503468e+01,
  -6.0495700e+01,
  -6.0487954e+01,
  -6.0480229e+01,
  -6.0472526e+01,
  -6.0464844e+01,
  -6.0457182e+01,
  -6.0449541e+01,
  -6.0441921e+01,
  -6.0434320e+01,
  -6.0426739e+01,
  -6.0419178e+01,
  -6.0411635e+01,
  -6.0404112e+01,
  -6.0396608e+01,
  -6.0389122e+01,
  -6.0381654e+01,
  -6.0374205e+01,
  -6.0366773e+01,
  -6.0359359e+01,
  -6.0351962e+01,
  -6.0344582e+01,
  -6.0337219e+01,
  -6.0329872e+01,
  -6.0322542e+01,
  -6.0315228e+01,
  -6.0307930e+01,
  -6.0300647e+01,
  -6.0293380e+01,
  -6.0286128e+01,
  -6.0278892e+01,
  -6.0271669e+01,
  -6.0264462e+01,
  -6.0257268e+01,
  -6.0250089e+01,
  -6.0242924e+01,
  -6.0235772e+01,
  -6.0228633e+01,
  -6.0221508e+01,
  -6.0214396e+01,
  -6.0207296e+01,
  -6.0200209e+01,
  -6.0193135e+01,
  -6.0186072e+01,
  -6.0179021e+01,
  -6.0171982e+01,
  -6.0164954e+01,
  -6.0157938e+01,
  -6.0150933e+01,
  -6.0143938e+01,
  -6.0136954e+01,
  -6.0129980e+01,
  -6.0123017e+01,
  -6.0116063e+01,
  -6.0109119e+01,
  -6.0102185e+01,
  -6.0095260e+01,
  -6.0088344e+01,
  -6.0081437e+01,
  -6.0074539e+01,
  -6.0067649e+01,
  -6.0060768e+01,
  -6.0053894e+01,
  -6.0047029e+01,
  -6.0040171e+01,
  -6.0033320e+01,
  -6.0026477e+01,
  -6.0019641e+01,
  -6.0012812e+01,
  -6.0005989e+01,
  -5.9999173e+01,
  -5.9992363e+01,
  -5.9985558e+01,
  -5.9978760e+01,
  -5.9971968e+01,
  -5.9965180e+01,
  -5.9958398e+01,
  -5.9951621e+01,
  -5.9944849e+01,
  -5.9938081e+01,
  -5.9931318e+01,
  -5.9924559e+01,
  -5.9917804e+01,
  -5.9911052e+01,
  -5.9904304e+01,
  -5.9897560e+01,
  -5.9890818e+01,
  -5.9884080e+01,
  -5.9877344e+01,
  -5.9870611e+01,
  -5.9863880e+01,
  -5.9857151e+01,
  -5.9850424e+01,
  -5.9843698e+01,
  -5.9836975e+01,
  -5.9830252e+01,
  -5.9823531e+01,
  -5.9816810e+01,
  -5.9810090e+01,
  -5.9803370e+01,
  -5.9796651e+01,
  -5.9789931e+01,
  -5.9783212e+01,
  -5.9776491e+01,
  -5.9769771e+01,
  -5.9763049e+01,
  -5.9756326e+01,
  -5.9749602e+01,
  -5.9742877e+01,
  -5.9736149e+01,
  -5.9729420e+01,
  -5.9722688e+01,
  -5.9715955e+01,
  -5.9709218e+01,
  -5.9702479e+01,
  -5.9695736e+01,
  -5.9688990e+01,
  -5.9682241e+01,
  -5.9675488e+01,
  -5.9668731e+01,
  -5.9661969e+01,
  -5.9655204e+01,
  -5.9648433e+01,
  -5.9641658e+01,
  -5.9634877e+01,
  -5.9628091e+01,
  -5.9621299e+01,
  -5.9614502e+01,
  -5.9607698e+01,
  -5.9600888e+01,
  -5.9594071e+01,
  -5.9587248e+01,
  -5.9580417e+01,
  -5.9573579e+01,
  -5.9566733e+01,
  -5.9559880e+01,
  -5.9553018e+01,
  -5.9546148e+01,
  -5.9539269e+01,
  -5.9532381e+01,
  -5.9525484e+01,
  -5.9518578e+01,
  -5.9511662e+01,
  -5.9504736e+01,
  -5.9497799e+01,
  -5.9490853e+01,
  -5.9483895e+01,
  -5.9476926e+01,
  -5.9469946e+01,
  -5.9462954e+01,
  -5.9455950e+01,
  -5.9448933e+01,
  -5.9441905e+01,
  -5.9434863e+01,
  -5.9427808e+01,
  -5.9420740e+01,
  -5.9413658e+01,
  -5.9406561e+01,
  -5.9399451e+01,
  -5.9392326e+01,
  -5.9385185e+01,
  -5.9378029e+01,
  -5.9370858e+01,
  -5.9363671e+01,
  -5.9356467e+01,
  -5.9349246e+01,
  -5.9342009e+01,
  -5.9334754e+01,
  -5.9327481e+01,
  -5.9320190e+01,
  -5.9312881e+01,
  -5.9305553e+01,
  -5.9298206e+01,
  -5.9290839e+01,
  -5.9283452e+01,
  -5.9276045e+01,
  -5.9268618e+01,
  -5.9261169e+01,
  -5.9253698e+01,
  -5.9246206e+01,
  -5.9238692e+01,
  -5.9231154e+01,
  -5.9223594e+01,
  -5.9216010e+01,
  -5.9208402e+01,
  -5.9200770e+01,
  -5.9193113e+01,
  -5.9185430e+01,
  -5.9177722e+01,
  -5.9169987e+01,
  -5.9162226e+01,
  -5.9154437e+01,
  -5.9146621e+01,
  -5.9138777e+01,
  -5.9130904e+01,
  -5.9123002e+01,
  -5.9115070e+01,
  -5.9107108e+01,
  -5.9099116e+01,
  -5.9091092e+01,
  -5.9083036e+01,
  -5.9074948e+01,
  -5.9066827e+01,
  -5.9058673e+01,
  -5.9050484e+01,
  -5.9042261e+01,
  -5.9034003e+01,
  -5.9025709e+01,
  -5.9017378e+01,
  -5.9009010e+01,
  -5.9000604e+01,
  -5.8992160e+01,
  -5.8983677e+01,
  -5.8975154e+01,
  -5.8966591e+01,
  -5.8957987e+01,
  -5.8949340e+01,
  -5.8940651e+01,
  -5.8931919e+01,
  -5.8923143e+01,
  -5.8914321e+01,
  -5.8905454e+01,
  -5.8896541e+01,
  -5.8887581e+01,
  -5.8878572e+01,
  -5.8869514e+01,
  -5.8860407e+01,
  -5.8851249e+01,
  -5.8842039e+01,
  -5.8832777e+01,
  -5.8823462e+01,
  -5.8814092e+01,
  -5.8804667e+01,
  -5.8795185e+01,
  -5.8785646e+01,
  -5.8776049e+01,
  -5.8766393e+01,
  -5.8756675e+01,
  -5.8746897e+01,
  -5.8737055e+01,
  -5.8727150e+01,
  -5.8717180e+01,
  -5.8707143e+01,
  -5.8697039e+01,
  -5.8686866e+01,
  -5.8676623e+01,
  -5.8666309e+01,
  -5.8655922e+01,
  -5.8645461e+01,
  -5.8634925e+01,
  -5.8624311e+01,
  -5.8613620e+01,
  -5.8602848e+01,
  -5.8591995e+01,
  -5.8581060e+01,
  -5.8570039e+01,
  -5.8558932e+01,
  -5.8547737e+01,
  -5.8536453e+01,
  -5.8525077e+01,
  -5.8513607e+01,
  -5.8502042e+01,
  -5.8490380e+01,
  -5.8478619e+01,
  -5.8466757e+01,
  -5.8454791e+01,
  -5.8442720e+01,
  -5.8430541e+01,
  -5.8418253e+01,
  -5.8405852e+01,
  -5.8393336e+01,
  -5.8380703e+01,
  -5.8367951e+01,
  -5.8355076e+01,
  -5.8342076e+01,
  -5.8328949e+01,
  -5.8315691e+01,
  -5.8302299e+01,
  -5.8288771e+01,
  -5.8275104e+01,
  -5.8261293e+01,
  -5.8247336e+01,
  -5.8233230e+01,
  -5.8218971e+01,
  -5.8204555e+01,
  -5.8189979e+01,
  -5.8175238e+01,
  -5.8160329e+01,
  -5.8145248e+01,
  -5.8129990e+01,
  -5.8114551e+01,
  -5.8098926e+01,
  -5.8083111e+01,
  -5.8067101e+01,
  -5.8050890e+01,
  -5.8034474e+01,
  -5.8017847e+01,
  -5.8001004e+01,
  -5.7983938e+01,
  -5.7966643e+01,
  -5.7949114e+01,
  -5.7931344e+01,
  -5.7913325e+01,
  -5.7895052e+01,
  -5.7876516e+01,
  -5.7857710e+01,
  -5.7838626e+01,
  -5.7819257e+01,
  -5.7799592e+01,
  -5.7779624e+01,
  -5.7759343e+01,
  -5.7738739e+01,
  -5.7717802e+01,
  -5.7696522e+01,
  -5.7674888e+01,
  -5.7652887e+01,
  -5.7630508e+01,
  -5.7607738e+01,
  -5.7584564e+01,
  -5.7560971e+01,
  -5.7536946e+01,
  -5.7512472e+01,
  -5.7487535e+01,
  -5.7462116e+01,
  -5.7436198e+01,
  -5.7409762e+01,
  -5.7382788e+01,
  -5.7355256e+01,
  -5.7327144e+01,
  -5.7298427e+01,
  -5.7269083e+01,
  -5.7239083e+01,
  -5.7208402e+01,
  -5.7177010e+01,
  -5.7144875e+01,
  -5.7111964e+01,
  -5.7078243e+01,
  -5.7043674e+01,
  -5.7008217e+01,
  -5.6971829e+01,
  -5.6934465e+01,
  -5.6896076e+01,
  -5.6856610e+01,
  -5.6816010e+01,
  -5.6774215e+01,
  -5.6731161e+01,
  -5.6686776e+01,
  -5.6640986e+01,
  -5.6593707e+01,
  -5.6544850e+01,
  -5.6494316e+01,
  -5.6442002e+01,
  -5.6387789e+01,
  -5.6331551e+01,
  -5.6273148e+01,
  -5.6212427e+01,
  -5.6149218e+01,
  -5.6083333e+01,
  -5.6014563e+01,
  -5.5942674e+01,
  -5.5867407e+01,
  -5.5788469e+01,
  -5.5705528e+01,
  -5.5618210e+01,
  -5.5526088e+01,
  -5.5428675e+01,
  -5.5325406e+01,
  -5.5215630e+01,
  -5.5098587e+01,
  -5.4973383e+01,
  -5.4838959e+01,
  -5.4694048e+01,
  -5.4537122e+01,
  -5.4366315e+01,
  -5.4179320e+01,
  -5.3973242e+01,
  -5.3744396e+01,
  -5.3487997e+01,
  -5.3197701e+01,
  -5.2864884e+01,
  -5.2477463e+01,
  -5.2017891e+01,
  -5.1459528e+01,
  -5.0759613e+01,
  -4.9844348e+01,
  -4.8573413e+01,
  -4.6641048e+01,
  -4.3231640e+01,
  -3.5383024e+01,
  -1.0454338e+01,
   2.6432709e+01,
   3.8454793e+01,
   3.7020684e+01,
   2.9077114e+01,
   1.7236404e+01,
   3.5844328e+00
  -1.0122124e+01,
  -2.2658499e+01,
  -3.3335271e+01,
  -4.2311038e+01,
  -5.0054239e+01,
  -5.6445296e+01,
  -6.1275390e+01,
  -6.4725797e+01,
  -6.7147337e+01,
  -6.8841274e+01,
  -7.0023975e+01,
  -7.0845667e+01,
  -7.1410675e+01,
  -7.1791987e+01,
  -7.2041111e+01,
  -7.2194694e+01,
  -7.2278996e+01,
  -7.2312947e+01,
  -7.2310261e+01,
  -7.2280914e+01,
  -7.2232185e+01,
  -7.2169402e+01,
  -7.2096474e+01,
  -7.2016273e+01,
  -7.1930915e+01,
  -7.1841959e+01,
  -7.1750556e+01,
  -7.1657560e+01,
  -7.1563598e+01,
  -7.1469138e+01,
  -7.1374524e+01,
  -7.1280013e+01,
  -7.1185793e+01,
  -7.1092005e+01,
  -7.0998751e+01,
  -7.0906106e+01,
  -7.0814126e+01,
  -7.0722851e+01,
  -7.0632307e+01,
  -7.0542515e+01,
  -7.0453488e+01,
  -7.0365234e+01,
  -7.0277758e+01,
  -7.0191061e+01,
  -7.0105143e+01,
  -7.0020001e+01,
  -6.9935634e+01,
  -6.9852036e+01,
  -6.9769203e+01,
  -6.9687130e+01,
  -6.9605812e+01,
  -6.9525242e+01,
  -6.9445414e+01,
  -6.9366322e+01,
  -6.9287960e+01,
  -6.9210321e+01,
  -6.9133399e+01,
  -6.9057187e+01,
  -6.8981680e+01,
  -6.8906869e+01,
  -6.8832750e+01,
  -6.8759316e+01,
  -6.8686560e+01,
  -6.8614475e+01,
  -6.8543056e+01,
  -6.8472297e+01,
  -6.8402191e+01,
  -6.8332731e+01,
  -6.8263912e+01,
  -6.8195728e+01,
  -6.8128173e+01,
  -6.8061240e+01,
  -6.7994924e+01,
  -6.7929218e+01,
  -6.7864118e+01,
  -6.7799617e+01,
  -6.7735709e+01,
  -6.7672389e+01,
  -6.7609651e+01,
  -6.7547489e+01,
  -6.7485898e+01,
  -6.7424873e+01,
  -6.7364407e+01,
  -6.7304496e+01,
  -6.7245134e+01,
  -6.7186316e+01,
  -6.7128036e+01,
  -6.7070290e+01,
  -6.7013072e+01,
  -6.6956377e+01,
  -6.6900199e+01,
  -6.6844535e+01,
  -6.6789378e+01,
  -6.6734724e+01,
  -6.6680568e+01,
  -6.6626905e+01,
  -6.6573731e+01,
  -6.6521039e+01,
  -6.6468827e+01,
  -6.6417088e+01,
  -6.6365819e+01,
  -6.6315014e+01,
  -6.6264670e+01,
  -6.6214781e+01,
  -6.6165343e+01,
  -6.6116352e+01,
  -6.6067803e+01,
  -6.6019691e+01,
  -6.5972013e+01,
  -6.5924765e+01,
  -6.5877941e+01,
  -6.5831537e+01,
  -6.5785550e+01,
  -6.5739976e+01,
  -6.5694810e+01,
  -6.5650047e+01,
  -6.5605685e+01,
  -6.5561719e+01,
  -6.5518145e+01,
  -6.5474959e+01,
  -6.5432157e+01,
  -6.5389736e+01,
  -6.5347691e+01,
  -6.5306019e+01,
  -6.5264716e+01,
  -6.5223779e+01,
  -6.5183203e+01,
  -6.5142985e+01,
  -6.5103121e+01,
  -6.5063608e+01,
  -6.5024442e+01,
  -6.4985620e+01,
  -6.4947138e+01,
  -6.4908993e+01,
  -6.4871181e+01,
  -6.4833700e+01,
  -6.4796544e+01,
  -6.4759712e+01,
  -6.4723200e+01,
  -6.4687005e+01,
  -6.4651123e+01,
  -6.4615552e+01,
  -6.4580287e+01,
  -6.4545327e+01,
  -6.4510667e+01,
  -6.4476305e+01,
  -6.4442238e+01,
  -6.4408463e+01,
  -6.4374976e+01,
  -6.4341775e+01,
  -6.4308857e+01,
  -6.4276219e+01,
  -6.4243858e+01,
  -6.4211771e+01,
  -6.4179956e+01,
  -6.4148409e+01,
  -6.4117128e+01,
  -6.4086110e+01,
  -6.4055352e+01,
  -6.4024852e+01,
  -6.3994607e+01,
  -6.3964615e+01,
  -6.3934872e+01,
  -6.3905377e+01,
  -6.3876126e+01,
  -6.3847118e+01,
  -6.3818349e+01,
  -6.3789817e+01,
  -6.3761520e+01,
  -6.3733456e+01,
  -6.3705621e+01,
  -6.3678014e+01,
  -6.3650632e+01,
  -6.3623473e+01,
  -6.3596534e+01,
  -6.3569814e+01,
  -6.3543309e+01,
  -6.3517019e+01,
  -6.3490940e+01,
  -6.3465070e+01,
  -6.3439407e+01,
  -6.3413950e+01,
  -6.3388696e+01,
  -6.3363642e+01,
  -6.3338787e+01,
  -6.3314129e+01,
  -6.3289665e+01,
  -6.3265395e+01,
  -6.3241314e+01,
  -6.3217423e+01,
  -6.3193718e+01,
  -6.3170198e+01,
  -6.3146861e+01,
  -6.3123705e+01,
  -6.3100728e+01,
  -6.3077928e+01,
  -6.3055304e+01,
  -6.3032853e+01,
  -6.3010574e+01,
  -6.2988466e+01,
  -6.2966525e+01,
  -6.2944751e+01,
  -6.2923142e+01,
  -6.2901696e+01,
  -6.2880412e+01,
  -6.2859287e+01,
  -6.2838321e+01,
  -6.2817510e+01,
  -6.2796855e+01,
  -6.2776353e+01,
  -6.2756003e+01,
  -6.2735803e+01,
  -6.2715752e+01,
  -6.2695848e+01,
  -6.2676089e+01,
  -6.2656474e+01,
  -6.2637002e+01,
  -6.2617671e+01,
  -6.2598480e+01,
  -6.2579427e+01,
  -6.2560511e+01,
  -6.2541730e+01,
  -6.2523083e+01,
  -6.2504569e+01,
  -6.2486186e+01,
  -6.2467933e+01,
  -6.2449809e+01,
  -6.2431812e+01,
  -6.2413941e+01,
  -6.2396195e+01,
  -6.2378572e+01,
  -6.2361071e+01,
  -6.2343691e+01,
  -6.2326431e+01,
  -6.2309290e+01,
  -6.2292265e+01,
  -6.2275357e+01,
  -6.2258564e+01,
  -6.2241884e+01,
  -6.2225317e+01,
  -6.2208861e+01,
  -6.2192516e+01,
  -6.2176279e+01,
  -6.2160151e+01,
  -6.2144130e+01,
  -6.2128214e+01,
  -6.2112404e+01,
  -6.2096697e+01,
  -6.2081092e+01,
  -6.2065590e+01,
  -6.2050188e+01,
  -6.2034885e+01,
  -6.2019681e+01,
  -6.2004575e+01,
  -6.1989565e+01,
  -6.1974651e+01,
  -6.1959832e+01,
  -6.1945106e+01,
  -6.1930473e+01,
  -6.1915932e+01,
  -6.1901482e+01,
  -6.1887122e+01,
  -6.1872850e+01,
  -6.1858667e+01,
  -6.1844572e+01,
  -6.1830562e+01,
  -6.1816639e+01,
  -6.1802800e+01,
  -6.1789044e+01,
  -6.1775372e+01,
  -6.1761782e+01,
  -6.1748273e+01,
  -6.1734845e+01,
  -6.1721497e+01,
  -6.1708227e+01,
  -6.1695036e+01,
  -6.1681922e+01,
  -6.1668884e+01,
  -6.1655923e+01,
  -6.1643036e+01,
  -6.1630224e+01,
  -6.1617485e+01,
  -6.1604819e+01,
  -6.1592225e+01,
  -6.1579703e+01,
  -6.1567251e+01,
  -6.1554869e+01,
  -6.1542557e+01,
  -6.1530313e+01,
  -6.1518136e+01,
  -6.1506028e+01,
  -6.1493985e+01,
  -6.1482009e+01,
  -6.1470098e+01,
  -6.1458251e+01,
  -6.1446468e+01,
  -6.1434749e+01,
  -6.1423092e+01,
  -6.1411497e+01,
  -6.1399964e+01,
  -6.1388492e+01,
  -6.1377080e+01,
  -6.1365727e+01,
  -6.1354433e+01,
  -6.1343198e+01,
  -6.1332021e+01,
  -6.1320901e+01,
  -6.1309837e+01,
  -6.1298830e+01,
  -6.1287879e+01,
  -6.1276982e+01,
  -6.1266140e+01,
  -6.1255352e+01,
  -6.1244617e+01,
  -6.1233935e+01,
  -6.1223306e+01,
  -6.1212728e+01,
  -6.1202201e+01,
  -6.1191726e+01,
  -6.1181300e+01,
  -6.1170925e+01,
  -6.1160599e+01,
  -6.1150321e+01,
  -6.1140092e+01,
  -6.1129911e+01,
  -6.1119776e+01,
  -6.1109689e+01,
  -6.1099649e+01,
  -6.1089654e+01,
  -6.1079704e+01,
  -6.1069800e+01,
  -6.1059940e+01,
  -6.1050125e+01,
  -6.1040353e+01,
  -6.1030624e+01,
  -6.1020938e+01,
  -6.1011294e+01,
  -6.1001693e+01,
  -6.0992132e+01,
  -6.0982613e+01,
  -6.0973135e+01,
  -6.0963697e+01,
  -6.0954298e+01,
  -6.0944939e+01,
  -6.0935620e+01,
  -6.0926338e+01,
  -6.0917096e+01,
  -6.0907890e+01,
  -6.0898723e+01,
  -6.0889592e+01,
  -6.0880499e+01,
  -6.0871441e+01,
  -6.0862419e+01,
  -6.0853434e+01,
  -6.0844483e+01,
  -6.0835567e+01,
  -6.0826685e+01,
  -6.0817838e+01,
  -6.0809024e+01,
  -6.0800244e+01,
  -6.0791497e+01,
  -6.0782783e+01,
  -6.0774101e+01,
  -6.0765451e+01,
  -6.0756833e+01,
  -6.0748246e+01,
  -6.0739690e+01,
  -6.0731165e+01,
  -6.0722670e+01,
  -6.0714205e+01,
  -6.0705770e+01,
  -6.0697364e+01,
  -6.0688987e+01,
  -6.0680639e+01,
  -6.0672320e+01,
  -6.0664029e+01,
  -6.0655765e+01,
  -6.0647529e+01,
  -6.0639320e+01,
  -6.0631139e+01,
  -6.0622983e+01,
  -6.0614854e+01,
  -6.0606751e+01,
  -6.0598674e+01,
  -6.0590622e+01,
  -6.0582596e+01,
  -6.0574594e+01,
  -6.0566617e+01,
  -6.0558664e+01,
  -6.0550735e+01,
  -6.0542830e+01,
  -6.0534948e+01
};



#endif