Esempio n. 1
0
    public double[,] Simulate(double[] y0, IStimulus stimulus)
    {
      Initialize(y0);
      double[,] retValue = new double[y.Length + 1, Nsave];
      int ns = skip;
      int p = 0;

      try
      {
        for (int n = 0; n < N; ++n)
        {
          if (ns == skip)
          {
            if (p < Nsave)
            {
              retValue[0, p] = t1 + n * h;

              for (int k = 0; k < y.Length; ++k)
                retValue[k + 1, p] = y[k];
            }
            p = p + 1;
            ns = 0;
          }
          ++ns;

          Integrate(t1 + n * h, stimulus);
        }
      }
      catch { }

      return retValue;
    }
Esempio n. 2
0
        public double[,] Simulate(double[] y0, IStimulus stimulus)
        {
            Initialize(y0);
            double[,] retValue = new double[y.Length + 1, Nsave];
            int ns = skip;
            int p  = 0;

            try
            {
                for (int n = 0; n < N; ++n)
                {
                    if (ns == skip)
                    {
                        if (p < Nsave)
                        {
                            retValue[0, p] = t1 + n * h;

                            for (int k = 0; k < y.Length; ++k)
                            {
                                retValue[k + 1, p] = y[k];
                            }
                        }
                        p  = p + 1;
                        ns = 0;
                    }
                    ++ns;

                    Integrate(t1 + n * h, stimulus);
                }
            }
            catch { }

            return(retValue);
        }
Esempio n. 3
0
        protected virtual void WriteStimulus(Epoch e, IExternalDevice ed, IStimulus s)
        {
            // write s.StimulusID
            Console.WriteLine("Epoch stimulus id {0} for device {1}", s.StimulusID, ed.Name);

            WriteStimulusParameters(e, ed, s, s.Parameters);
        }
Esempio n. 4
0
        protected virtual void WriteStimulusParameters(Epoch e, IExternalDevice ed, IStimulus s, IDictionary <string, object> p)
        {
            foreach (var k in s.Parameters.Keys)
            {
                var v = s.Parameters[k];

                WriteStimulusParameter(e, ed, s, k, v);
            }
        }
 public static void AssertStimuliEqual(IStimulus expected, IPersistentStimulus actual)
 {
     Assert.AreEqual(expected.StimulusID, actual.StimulusID);
     Assert.AreEqual(expected.Units, actual.Units);
     Assert.AreEqual(expected.SampleRate, actual.SampleRate);
     Assert.AreEqual(expected.Duration, actual.Duration);
     Assert.AreEqual(expected.Data, actual.Data);
     CollectionAssert.AreEquivalent(expected.Parameters, actual.Parameters);
     AssertConfigurationSpansEqual(expected.OutputConfigurationSpans.Consolidate(), actual.ConfigurationSpans);
 }
Esempio n. 6
0
    public static double Threshold(AnalysisParameters P, PatchModel M, IStimulus Is)
    {
      var solver = new ModelSolver()
      {
        Model = M,
        H = 2e-6,
        T1 = P.T1,
        T2 = P.T2
      };

      return solver.EstimateThreshold(P.y0, Is);     
    }
Esempio n. 7
0
    public virtual void dydt(double[] dydt, double t, double[] y, IStimulus stimulus)
    {
      double En = y[0];
      double Ei = y[1];

      alpha(a, y);
      beta(b, y);

      dydt[0] = -(Iion_n(y) - stimulus.GetValue(t) - (Ei - En) / Ril) / (Cn + Cm);
      dydt[1] = -(Iion_i(y) + (Ei - En) / Ril - Cm * dydt[0]) / Ci;

      for (int n = 0; n < Ngating; ++n)
        dydt[n + 2] = a[n] * (1 - y[n + 2]) - b[n] * y[n + 2]; 
    }
Esempio n. 8
0
    public double[] GetFinalState(double[] y0, IStimulus stimulus)
    {
      Initialize(y0);
      double[] retValue = new double[y.Length];

      try
      {
        for (int n = 0; n < N; ++n)
          Integrate(t1 + n * h, stimulus);

        for (int n = 0; n < y.Length; ++n)
          retValue[n] = y[n];
      }
      catch { }

      return retValue;
    }
Esempio n. 9
0
        public double EstimateThreshold(double[] y0, IStimulus stimulus)
        {
            const int max_iter = 200;
            int       count    = 0;
            double    I1       = 0;
            double    I2       = 1e-9;

            try
            {
                while (!IsActivated(y0, stimulus, I2))
                {
                    I1 = I2;
                    I2 = 2 * I2;
                    ++count;

                    if (count > max_iter)
                    {
                        break;
                    }
                }

                while (Math.Abs(I2 - I1) > 1e-12)
                {
                    double Itest = (I2 - I1) / 2 + I1;

                    if (IsActivated(y0, stimulus, Itest))
                    {
                        I2 = Itest;
                    }
                    else
                    {
                        I1 = Itest;
                    }

                    ++count;
                    if (count > max_iter)
                    {
                        break;
                    }
                }
            }
            catch { }

            return(I2);
        }
Esempio n. 10
0
    public bool IsActivated(double[] y0, IStimulus stimulus)
    {
      bool retValue = false;

      try
      {
        Initialize(y0);

        for (int n = 0; n < N; ++n)
        {
          Integrate(t1 + n * h, stimulus);

          if (y[0] > 0)
          {
            retValue = true;
            break;
          }
        }
      }
      catch { }

      return retValue;
    }
Esempio n. 11
0
        /// <summary>
        /// Constructs an output data stream around a given Stimulus with a hint at the block duration
        /// to use for enumerating the stimulus data.
        /// </summary>
        /// <param name="stimulus">Stimulus to stream</param>
        /// <param name="blockDuration">Block duration to use for enumerating the stimulus data</param>
        public StimulusOutputDataStream(IStimulus stimulus, TimeSpan blockDuration)
        {
            if (stimulus == null)
                throw new ArgumentNullException("stimulus");

            if (blockDuration <= TimeSpan.Zero)
                throw new ArgumentOutOfRangeException("blockDuration");

            Stimulus = stimulus;
            StimulusDataEnumerator = stimulus.DataBlocks(blockDuration).GetEnumerator();
            Position = TimeSpan.Zero;
            OutputPosition = TimeSpan.Zero;
        }
Esempio n. 12
0
 private void WriteStimulusDataConfigurationSpans(H5GroupId sId, IStimulus s)
 {
     WriteConfigurationSpans(sId, s.OutputConfigurationSpans);
 }
Esempio n. 13
0
 private void WriteStimulusConfigurationSpans(IStimulus s)
 {
     WriteConfigurationSpans(s.OutputConfigurationSpans);
 }
Esempio n. 14
0
        protected override void WriteStimulus(Epoch e, IExternalDevice ed, IStimulus s)
        {
            writer.WriteStartElement("stimulus");
            writer.WriteAttributeString("device", ed.Name);
            writer.WriteAttributeString("stimulusID", s.StimulusID);
            writer.WriteAttributeString("stimulusUnits", s.Units);

            WriteDictionary("parameters", s.Parameters);

            WriteStimulusConfigurationSpans(s);

            writer.WriteEndElement();
        }
Esempio n. 15
0
 protected virtual void WriteStimulusParameter(Epoch e, IExternalDevice ed, IStimulus s, string k, object v)
 {
     Console.WriteLine("Epoch stimulus parameter {0}={1}", k, v);
 }
Esempio n. 16
0
        protected virtual void WriteStimulus(Epoch e, IExternalDevice ed, IStimulus s)
        {
            // write s.StimulusID
            Console.WriteLine("Epoch stimulus id {0} for device {1}", s.StimulusID, ed.Name);

            WriteStimulusParameters(e, ed, s, s.Parameters);
        }
Esempio n. 17
0
 protected virtual void WriteStimulusParameter(Epoch e, IExternalDevice ed, IStimulus s, string k, object v)
 {
     Console.WriteLine("Epoch stimulus parameter {0}={1}", k, v);
 }
Esempio n. 18
0
    public double EstimateThreshold(double[] y0, IStimulus stimulus)
    {
      const int max_iter = 200;
      int count = 0;
      double I1 = 0;
      double I2 = 1e-9;

      try
      {
        while (!IsActivated(y0, stimulus, I2))
        {
          I1 = I2;
          I2 = 2 * I2;
          ++count;

          if (count > max_iter)
            break;
        }

        while (Math.Abs(I2 - I1) > 1e-12)
        {
          double Itest = (I2 - I1) / 2 + I1;

          if (IsActivated(y0, stimulus, Itest))
            I2 = Itest;
          else
            I1 = Itest;

          ++count;
          if (count > max_iter)
            break;
        }
      }
      catch { }

      return I2;
    }
Esempio n. 19
0
 public bool IsActivated(double[] y0, IStimulus stimulus, double Is)
 {
   stimulus.Is = Is;
   return IsActivated(y0, stimulus);
 }
Esempio n. 20
0
    public override void dydt(double[] dydt, double t, double[] y, IStimulus stimulus)
    {
      double En = y[0];
      double Ei = y[1];
      double Rbb = getRbb(y);

      alpha(a, y);
      beta(b, y);

      dydt[0] = -(Iion_n(y) - stimulus.GetValue(t) - (Ei - En) / Rbb) / (Cn + Cm);
      dydt[1] = -(Iion_i(y) + (Ei - En) / Rbb - Cm * dydt[0]) / Ci;

      if (ClampKo == 1)
        dydt[2] = 0;
      else
        dydt[2] = (jK_i(y) + jPump(y))/Vpa;

      for (int n = 0; n < Ngating; ++n)
        dydt[n + 3] = a[n] * (1 - y[n + 3]) - b[n] * y[n + 3];
    }
Esempio n. 21
0
        protected virtual void WriteStimulusParameters(Epoch e, IExternalDevice ed, IStimulus s, IDictionary<string, object> p)
        {
            foreach (var k in s.Parameters.Keys)
            {
                var v = s.Parameters[k];

                WriteStimulusParameter(e, ed, s, k, v);
            }
        }
        public void SetUp()
        {
            const int srate = 1000;
            IList<IMeasurement> list = Enumerable.Range(0, srate * 2).Select(i => new Measurement(i, "V") as IMeasurement).ToList();
            data = new OutputData(list, new Measurement(srate, "Hz"));

            stim = new RenderedStimulus("stimID", new Dictionary<string, object>(), data);
            stream = new StimulusOutputDataStream(stim, TimeSpan.FromSeconds(0.13));

            indefiniteStim = new RenderedStimulus("indefID", new Dictionary<string, object>(), data, Option<TimeSpan>.None());
            indefiniteStream = new StimulusOutputDataStream(indefiniteStim, TimeSpan.FromSeconds(0.52));
        }
Esempio n. 23
0
    private void Integrate(double t, IStimulus stimulus)
    {
      model.dydt(dydt, t, y, stimulus);

      for (int n = 0; n < y.Length; ++n)
      {
        y[n] += h * dydt[n];

        if (y[n] > 1)
          y[n] = 1;
        if (y[n] < -1)
          y[n] = -1;
      }
    }