public static IList <double> Sample(IList <double> means, IList <double> precs) { SparseList <double> sample = SparseList <double> .FromSize(means.Count); sample.SetToFunction(means, precs, (m, p) => Gaussian.Sample(m, p)); return(sample); }
public static ISparseList <bool> Sample(ISparseList <double> probTrue) { SparseList <bool> sample = SparseList <bool> .FromSize(probTrue.Count); sample.SetToFunction(probTrue, p => Bernoulli.Sample(p)); return(sample); }
public static ISparseList <double> Sample(ISparseList <double> shapes, ISparseList <double> rates) { SparseList <double> sample = SparseList <double> .FromSize(shapes.Count); sample.SetToFunction(shapes, rates, (s, r) => Gamma.Sample(s, r)); return(sample); }
public static IList <TResult> ListZip <TFirst, TSecond, TThird, TResult>( this IList <TFirst> first, IEnumerable <TSecond> second, IEnumerable <TThird> third, Func <TFirst, TSecond, TThird, TResult> fun) { if (first is ISparseEnumerable <TFirst> && second is ISparseEnumerable <TSecond> && third is ISparseEnumerable <TThird> ) { var result = SparseList <TResult> .FromSize(first.Count); result.SetToFunction((SparseList <TFirst>)first, (SparseList <TSecond>)second, (SparseList <TThird>)third, fun); return(result); } else { var result = new List <TResult>(); using (IEnumerator <TFirst> e1 = first.GetEnumerator()) using (IEnumerator <TSecond> e2 = second.GetEnumerator()) using (IEnumerator <TThird> e3 = third.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) { result.Add(fun(e1.Current, e2.Current, e3.Current)); } return(result); } }
public static IList <TResult> ListZip <TFirst, TSecond, TThird, TFourth, TResult>( this IList <TFirst> first, IList <TSecond> second, IList <TThird> third, IList <TFourth> fourth, Func <TFirst, TSecond, TThird, TFourth, TResult> fun) //where TResult : Diffable { if (first is ISparseList <TFirst> && second is ISparseList <TSecond> && third is ISparseList <TThird> && fourth is ISparseList <TFourth> ) { var result = SparseList <TResult> .FromSize(first.Count); //var result = ApproximateSparseList<TResult>.FromSize(first.Count, 1e-6); result.SetToFunction((ISparseList <TFirst>)first, (ISparseList <TSecond>)second, (ISparseList <TThird>)third, (ISparseList <TFourth>)fourth, fun); return(result); } else { var result = new List <TResult>(); using (IEnumerator <TFirst> e1 = first.GetEnumerator()) using (IEnumerator <TSecond> e2 = second.GetEnumerator()) using (IEnumerator <TThird> e3 = third.GetEnumerator()) using (IEnumerator <TFourth> e4 = fourth.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) { result.Add(fun(e1.Current, e2.Current, e3.Current, e4.Current)); } return(result); } }
public static ISparseList <double> Sample(ISparseList <double> trueCounts, ISparseList <double> falseCounts) { SparseList <double> sample = SparseList <double> .FromSize(trueCounts.Count); sample.SetToFunction(trueCounts, falseCounts, (tc, fc) => Beta.Sample(tc, fc)); return(sample); }
/// <summary> /// Similar to LINQ Select, except it takes and returns a list. /// If the supplied list is sparse, the returned list will also be sparse. /// </summary> /// <typeparam name="T">The type of this list</typeparam> /// <typeparam name="T2">The target element type</typeparam> /// <param name="source">This list</param> /// <param name="converter">The converter</param> /// <returns></returns> public static IList <T2> ListSelect <T, T2>(this IList <T> source, Func <T, T2> converter) { if (source is SparseList <T> ) { var target = SparseList <T2> .FromSize(source.Count); target.SetToFunction <T>(source, converter); return(target); } return(source.Select(converter).ToList()); }
/// <summary> /// Samples from this sparse distribution list. /// </summary> /// <returns>A sample from this distribution.</returns> /// <remarks>This method is inefficient in that the result will be dense even though the return type is sparse.</remarks> public ISparseList <TDomain> Sample() { ISparseList <TDomain> sv = SparseList <TDomain> .FromSize(Count); return(this.Sample(sv)); }
/// <summary> /// Samples from this sparse Gaussian list /// </summary> /// <returns></returns> /// <remarks>This method is inefficient in that the result will be dense even though the return type is sparse.</remarks> public IList <double> Sample() { SparseList <double> sv = SparseList <double> .FromSize(Count); return(Sample(sv)); }