/** * Compute time derivative of state at current time. * This is used by the time-integration "mod.compute(t)" as the core of the model. * @return vector dt */ protected override IVector Dx(IVector xt, double t) { IVector result = new VectorJ2N(2); // The oscillator model // // simple linear oscilator (e.g. mass-spring system with friction) //% d(x)/d(t) = u // d(u)/d(t) = - omega^2 * x - (2/t_damp) u // double[] x = xt.Values; double omega = Math.Max(0.0, parameterValues[omegaId]); double tDamp = Math.Max(0.0, parameterValues[tDampId]); result.SetValue(0, x[1]); result.SetValue(1, -(omega * omega) * x[0] - (2.0 / tDamp * x[1])); return(result); }
public IVector GetObservedValues(IObservationDescriptions descr) { IVector result = new VectorJ2N(descr.ObservationCount); // TODO: handle TimeSeriesObservationDescriptions IVector obsTimes = descr.GetValueProperties("time"); IVector obsIndex = descr.GetValueProperties("index") ?? descr.GetValueProperties("xPosition"); IVector transformIndex; try { transformIndex = descr.GetValueProperties("transform"); } catch (Exception) { transformIndex = null; } Time tHor = new Time(parameterValues[StartTimeId], parameterValues[StopTimeId]) ; tHor.StepMJD = parameterValues[TimeStepId]; if (storeObs) { //work from stored states for (int i = 0; i < descr.ObservationCount; i++) { // at which timestep is this obs long iObs = Utils.GetTimeStep(tHor, (new Time(obsTimes.GetValue(i)))); // find corresponding storage location int thisTIndex = iStore.IndexOf((int)iObs); //time index in storage if (thisTIndex < 0) { throw (new Exception("model.getValues: time out of range for observation nr. " + i)); } int thisXIndex = (int)obsIndex.GetValue(i); if ((thisXIndex < 0) | (thisXIndex >= state.Size)) { throw (new Exception("model.getValues: index out of range for " + " observation nr. " + i + " index= " + thisXIndex)); } //Console.Out.WriteLine("i="+i+" it="+thisTIndex+" ind= "+thisXIndex); double thisValue = xStore[thisTIndex].GetValue(thisXIndex); // transform values if needed if (transformIndex != null) { if (transformIndex.GetValue(i) == 2) { // magic number for quadratic observations thisValue = thisValue * thisValue; } } result.SetValue(i, thisValue); } } else { // only current state is available for (int i = 0; i < descr.ObservationCount; i++) { int thisXIndex = (int)obsIndex.GetValue(i); //TODO if(){ //check time double thisValue = state.GetValue(thisXIndex); // transform values if needed if (transformIndex != null) { if (transformIndex.GetValue(i) == 2) { // magic number for quadratic observations thisValue = thisValue * thisValue; } } result.SetValue(i, thisValue); } } return(result); }