/// <summary> /// Returns a new instance of the <see cref="SparseDistributionList{TDist,TDomain,TThis}"/> class from a sparse list of distributions. /// </summary> /// <param name="distributions">The sparse list of distributions.</param> /// <returns>The new instance.</returns> public static TThis FromSparseList(ISparseList <TDist> distributions) { var result = new TThis(); result.SetTo(distributions); return(result); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="SparseGaussianListOp"]/message_doc[@name="LogEvidenceRatio(SparseGaussianList, ISparseList{double}, SparseGammaList, SparseGaussianList, SparseGammaList)"]/*'/> public static double LogEvidenceRatio( [SkipIfUniform] SparseGaussianList sample, ISparseList <double> mean, [SkipIfUniform] SparseGammaList precision, [Fresh] SparseGaussianList to_sample, SparseGammaList to_precision) { Func <Gaussian, double, Gamma, Gaussian, Gamma, double> f = GaussianOp.LogEvidenceRatio; return(f.Map(sample, mean, precision, to_sample, to_precision).EnumerableSum(x => x)); }
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 ISparseList <bool> Sample(ISparseList <double> probTrue) { SparseList <bool> sample = SparseList <bool> .FromSize(probTrue.Count); sample.SetToFunction(probTrue, p => Bernoulli.Sample(p)); return(sample); }
/// <summary>VMP message to <c>sample</c>.</summary> /// <param name="probTrue">Constant value for <c>probTrue</c>.</param> /// <param name="result">Modified to contain the outgoing message.</param> /// <returns> /// <paramref name="result" /> /// </returns> /// <remarks> /// <para>The outgoing message is the factor viewed as a function of <c>sample</c> conditioned on the given values.</para> /// </remarks> public static BernoulliIntegerSubset SampleAverageLogarithm(ISparseList <double> probTrue, BernoulliIntegerSubset result) { Func <double, Bernoulli> f = BernoulliFromBetaOp.SampleAverageLogarithm; result.SetTo(f.Map(probTrue)); return(result); }
public static ISparseList <double> Sample(ISparseList <double> means, ISparseList <double> precs) { SparseList <double> sample = SparseList <double> .FromSize(means.Count); sample.SetToFunction(means, precs, (m, p) => Gaussian.Sample(m, p)); return(sample); }
/// <summary>Gibbs message to <c>sample</c>.</summary> /// <param name="probTrue">Constant value for <c>probTrue</c>.</param> /// <param name="result">Modified to contain the outgoing message.</param> /// <returns> /// <paramref name="result" /> /// </returns> /// <remarks> /// <para>The outgoing message is the factor viewed as a function of <c>sample</c> conditioned on the given values.</para> /// </remarks> public static BernoulliIntegerSubset SampleConditional(ISparseList <double> probTrue, BernoulliIntegerSubset result) { Func <double, Bernoulli> f = BernoulliFromBetaOp.SampleConditional; result.SetTo(f.Map(probTrue)); 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> /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class from a sparse list of Bernoulli distributions. /// </summary> /// <param name="bernoullis">The sparse list of Bernoulli distributions.</param> /// <param name="tolerance">The tolerance.</param> /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns> public static BernoulliIntegerSubset FromSparseList(ISparseList <Bernoulli> bernoullis, double tolerance) { var result = new BernoulliIntegerSubset(); result.SparseBernoulliList = SparseBernoulliList.FromSparseList(bernoullis, tolerance); return(result); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="SparseGaussianListOp"]/message_doc[@name="LogAverageFactor(SparseGaussianList, ISparseList{double}, SparseGammaList, SparseGammaList)"]/*'/> public static double LogAverageFactor( [SkipIfUniform] SparseGaussianList sample, ISparseList <double> mean, [SkipIfUniform] SparseGammaList precision, SparseGammaList to_precision) { Func <Gaussian, double, Gamma, Gamma, double> f = GaussianOp.LogAverageFactor; return(f.Map(sample, mean, precision, to_precision).EnumerableSum(x => x)); }
/// <summary> /// CReturns a new instance of the <see cref="SparseGammaList"/> class /// from sparse lists of shapes and scales. /// </summary> /// <param name="shape">The shape values.</param> /// <param name="scale">The scale values.</param> /// <param name="tolerance">The tolerance for the approximation.</param> /// <returns>The new <see cref="SparseGammaList"/> instance.</returns> public static SparseGammaList FromShapeAndScale( ISparseList <double> shape, ISparseList <double> scale, double tolerance) { var result = FromSize(shape.Count, tolerance); result.SetToFunction(shape, scale, (s, sc) => Gamma.FromShapeAndScale(s, sc)); return(result); }
/// <summary> /// Returns a new instance of the <see cref="SparseGaussianList"/> class from sparse mean and precision lists. /// </summary> /// <param name="mean">The desired mean.</param> /// <param name="precision">The desired precision.</param> /// <param name="tolerance">The tolerance for the approximation.</param> /// <returns>The new <see cref="SparseGaussianList"/> instance.</returns> public static SparseGaussianList FromMeanAndPrecision( ISparseList <double> mean, ISparseList <double> precision, double tolerance) { var result = FromSize(mean.Count, tolerance); result.SetToFunction(mean, precision, (m, p) => Gaussian.FromMeanAndPrecision(m, p)); return(result); }
/// <summary> /// Returns a new instance of instance of the <see cref="SparseBetaList"/> class /// from sparse lists of true and false counts. /// </summary> /// <param name="trueCounts">The true counts.</param> /// <param name="falseCounts">The false counts.</param> /// <param name="tolerance">The tolerance for the approximation.</param> /// <returns>A new instance of the <see cref="SparseBetaList"/> class.</returns> public static SparseBetaList FromCounts( ISparseList <double> trueCounts, ISparseList <double> falseCounts, double tolerance) { var result = FromSize(trueCounts.Count, tolerance); result.SetToFunction(trueCounts, falseCounts, (tc, fc) => new Beta(tc, fc)); return(result); }
/// <summary> /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given size /// from a sparse list of probability true. /// </summary> /// <param name="probTrue">The sparse list of probability of true.</param> /// <param name="tolerance">The tolerance for the approximation.</param> /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns> public static BernoulliIntegerSubset FromProbTrue( ISparseList <double> probTrue, double tolerance) { BernoulliIntegerSubset result = new BernoulliIntegerSubset(); result.SparseBernoulliList = SparseBernoulliList.FromProbTrue(probTrue, tolerance); return(result); }
/// <summary> /// Returns a new instance of the <see cref="SparseBernoulliList"/> class /// of a given size from a sparse list of probability true. /// </summary> /// <param name="probTrue">The sparse list of probability of true.</param> /// <param name="tolerance">The tolerance for the approximation.</param> /// <returns>The new <see cref="SparseBernoulliList"/> instance.</returns> public static SparseBernoulliList FromProbTrue( ISparseList <double> probTrue, double tolerance) { var result = FromSize(probTrue.Count, tolerance); result.SetToFunction(probTrue, pt => new Bernoulli(pt)); return(result); }
/// <summary> /// Returns a new instance of the <see cref="SparseBernoulliList"/> class /// of a given size from a sparse list of log odds. /// </summary> /// <param name="logOdds">The sparse list of log odds.</param> /// <param name="tolerance">The tolerance for the approximation.</param> /// <returns>The new <see cref="SparseBernoulliList"/> instance.</returns> public static SparseBernoulliList FromLogOdds( ISparseList <double> logOdds, double tolerance) { var result = FromSize(logOdds.Count, tolerance); result.SetToFunction(logOdds, lodds => Bernoulli.FromLogOdds(lodds)); return(result); }
/// <summary> /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given size /// from a sparse list of log odds. /// </summary> /// <param name="logOdds">The sparse list of log odds.</param> /// <param name="tolerance">The tolerance for the approximation.</param> /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns> public static BernoulliIntegerSubset FromLogOdds( ISparseList <double> logOdds, double tolerance) { BernoulliIntegerSubset result = new BernoulliIntegerSubset(); result.SparseBernoulliList = SparseBernoulliList.FromLogOdds(logOdds, tolerance); return(result); }
/// <summary> /// Returns a new instance of the <see cref="SparseDistributionList{TDist,TDomain,TThis}"/> class from a sparse list of distributions. /// </summary> /// <param name="distributions">The sparse list of distributions.</param> /// <param name="tolerance">The tolerance.</param> /// <returns>The new instance.</returns> public static TThis FromSparseList(ISparseList <TDist> distributions, double tolerance) { var result = new TThis(); result.Count = distributions.Count; result.Tolerance = tolerance; result.SetTo(distributions); return(result); }
/// <summary> /// Samples from this sparse distribution list. /// </summary> /// <param name="result">Where to put the result.</param> /// <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> result) { Argument.CheckIfValid(result.Count == this.Dimension, string.Format("Result list does not match dimension of this distribution. Expected {0}, got {1}.", this.Dimension, result.Count)); IEnumerator <TDist> e = GetEnumerator(); int i = 0; while (e.MoveNext()) { result[i++] = e.Current.Sample(); } return(result); }
/// <summary> /// Gets the variance as a sparse list. /// </summary> /// <returns>The variance of this distribution.</returns> public ISparseList <double> GetVariance() { ISparseList <double> result = SparseList <double> .Constant(Count, CommonValue.GetVariance()); var sen = GetSparseEnumerator(); while (sen.MoveNext()) { result[sen.CurrentIndex] = sen.Current.GetVariance(); } return(result); }
public static IList <int> Sample(ISparseList <double> probTrue) { var result = new bool[probTrue.Count]; var list = new List <int>(); int i = 0; foreach (double d in probTrue) { if (Bernoulli.Sample(d)) { list.Add(i); } i++; } return(list); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="SparseBernoulliFromBetaOp"]/message_doc[@name="ProbTrueAverageConditional(ISparseList{bool}, SparseBetaList)"]/*'/> public static SparseBetaList ProbTrueAverageConditional(ISparseList <bool> sample, SparseBetaList result) { result.SetToFunction(sample, s => BernoulliFromBetaOp.ProbTrueAverageConditional(s)); return(result); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="SparseBernoulliFromBetaOp"]/message_doc[@name="SampleAverageConditional(ISparseList{double}, SparseBernoulliList)"]/*'/> public static SparseBernoulliList SampleAverageConditional(ISparseList <double> probTrue, SparseBernoulliList result) { result.SetToFunction(probTrue, pt => BernoulliFromBetaOp.SampleAverageConditional(pt)); return(result); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="SparseBernoulliFromBetaOp"]/message_doc[@name="LogEvidenceRatio(ISparseList{bool}, ISparseList{double})"]/*'/> public static double LogEvidenceRatio(ISparseList <bool> sample, ISparseList <double> probTrue) { Func <bool, double, double> f = BernoulliFromBetaOp.LogEvidenceRatio; return(f.Map(sample, probTrue).EnumerableSum(x => x)); }
public static double LogEvidenceRatio(SparseBernoulliList sample, ISparseList <double> probTrue) { return(0.0); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="SparseBernoulliFromBetaOp"]/message_doc[@name="LogAverageFactor(ISparseList{bool}, SparseBetaList)"]/*'/> public static double LogAverageFactor(ISparseList <bool> sample, SparseBetaList probTrue) { Func <bool, Beta, double> f = BernoulliFromBetaOp.LogAverageFactor; return(f.Map(sample, probTrue).EnumerableSum(x => x)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="SparseBernoulliFromBetaOp"]/message_doc[@name="AverageLogFactor(ISparseList{bool}, ISparseList{double})"]/*'/> public static double AverageLogFactor(ISparseList <bool> sample, ISparseList <double> probTrue) { Func <bool, double, double> f = BernoulliFromBetaOp.AverageLogFactor; return(f.Map(sample, probTrue).EnumerableSum(x => x)); }
/// <summary> /// Returns a new instance of the <see cref="SparseBernoulliList"/> class of a given size /// from a sparse list of log odds. /// </summary> /// <param name="logOdds">The sparse list of log odds.</param> /// <returns>The new <see cref="SparseBernoulliList"/> instance.</returns> public static SparseBernoulliList FromLogOdds( ISparseList <double> logOdds) { return(SparseBernoulliList.FromLogOdds(logOdds, SparseBernoulliList.DefaultTolerance)); }
/// <summary> /// Returns a new instance of the <see cref="SparseBernoulliList"/> class of a given size /// from a sparse list of probability true. /// </summary> /// <param name="probTrue">The sparse list of probability of true.</param> /// <returns>The new <see cref="SparseBernoulliList"/> instance.</returns> public static SparseBernoulliList FromProbTrue( ISparseList <double> probTrue) { return(SparseBernoulliList.FromProbTrue(probTrue, SparseBernoulliList.DefaultTolerance)); }
/// <summary> /// Initializes a new instance of the <see cref="BernoulliIntegerSubset"/> class from a sparse list of <see cref="Bernoulli"/> distributions. /// </summary> /// <param name="bernoullis">The sparse list of Bernoulli distributions.</param> protected BernoulliIntegerSubset(ISparseList <Bernoulli> bernoullis) { SparseBernoulliList = SparseBernoulliList.FromSparseList(bernoullis); }