/// <summary> /// Generate next path. /// </summary> /// <returns> /// An array containing a single <see cref="Path"/>, /// wrapped in a (possibly weighted) <see cref="Sample"/>. /// </returns> public override Sample Next() { var paths = new Path[1]; var sample = ArrayGenerator.NextSample(); // get a weighted SparseVector paths[0] = new Path(Times, Drift[0], (SparseVector)sample.Value); return(new Sample(paths, sample.Weight)); }
/// <summary> /// Generate next paths. /// </summary> /// <returns> /// An array containing <see cref="PathGenerator.Count"/> <see cref="Path"/>s, /// wrapped in a (possibly weighted) <see cref="Sample"/>. /// </returns> public override Sample Next() { Matrix diffusion = new Matrix(Count, TimeSteps); double weight = 1.0; for (int i = 0; i < TimeSteps; i++) { Sample sample = ArrayGenerator.NextSample(); // get a weighted SparseVector weight *= sample.Weight; SparseVector v = (SparseVector)sample.Value; v.Multiply(Math.Sqrt(TimeDelays.Data[i])); v.Copy(diffusion.Column(i)); } Path[] paths = new Path[Count]; for (int j = 0; j < Count; j++) { paths[j] = new Path(Times, Drift[j], diffusion.Row(j)); } return(new Sample(paths, weight)); }