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; }
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); }
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); }
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); }
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); }
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]; }
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; }
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); }
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; }
/// <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; }
private void WriteStimulusDataConfigurationSpans(H5GroupId sId, IStimulus s) { WriteConfigurationSpans(sId, s.OutputConfigurationSpans); }
private void WriteStimulusConfigurationSpans(IStimulus s) { WriteConfigurationSpans(s.OutputConfigurationSpans); }
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(); }
protected virtual void WriteStimulusParameter(Epoch e, IExternalDevice ed, IStimulus s, string k, object v) { Console.WriteLine("Epoch stimulus parameter {0}={1}", k, v); }
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; }
public bool IsActivated(double[] y0, IStimulus stimulus, double Is) { stimulus.Is = Is; return IsActivated(y0, stimulus); }
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]; }
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)); }
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; } }