コード例 #1
0
#pragma warning restore 162
#endif

#if SpecializeArrays
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="Replicate2BufferOp"]/message_doc[@name="UsesAverageConditional{T}(T[], T, T, int, T)"]/*'/>
        /// <typeparam name="T">The type of the messages.</typeparam>
        //[SkipIfAllUniform]
        public static T UsesAverageConditional <T>(
            [MatchingIndex, IgnoreDependency] T[] Uses, // Uses dependency must be ignored for Sequential schedule
            [IgnoreDependency, SkipIfUniform] T Def,
            [Fresh, SkipIfUniform] T marginal,
            int resultIndex,
            T result)
            where T : SettableToRatio <T>, SettableToProduct <T>, SettableTo <T>
        {
            if (resultIndex < 0 || resultIndex >= Uses.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(resultIndex));
            }
            if (Uses.Length == 1)
            {
                result.SetTo(Def);
                return(result);
            }
            try
            {
                result.SetToRatio(marginal, Uses[resultIndex]);
                return(result);
            }
            catch (DivideByZeroException)
            {
                return(ReplicateOp_NoDivide.UsesAverageConditional(Uses, Def, resultIndex, result));
            }
        }
コード例 #2
0
 public static TDist DefGibbs <TDist>(
     [SkipIfAllUniform] TDist[] Uses,
     TDist result)
     where TDist : IDistribution <T>, Sampleable <T>, SettableToProduct <TDist>, SettableTo <TDist>
 {
     return(ReplicateOp_NoDivide.DefAverageConditional(Uses, result));
 }
コード例 #3
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ReplicateMaxOp"]/message_doc[@name="MarginalMaxConditional{T}(IList{T}, T, T)"]/*'/>
        /// <typeparam name="T">The type of the distribution over the replicated variable.</typeparam>
        public static T MarginalMaxConditional <T>(IReadOnlyList <T> Uses, [SkipIfUniform] T Def, T result)
            where T : SettableToProduct <T>, SettableTo <T>
        {
            T res = ReplicateOp_NoDivide.MarginalAverageConditional <T>(Uses, Def, result);

            if (res is UnnormalizedDiscrete)
            {
                ((UnnormalizedDiscrete)(object)res).SetMaxToZero();
            }
            return(res);
        }
コード例 #4
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ReplicateMaxOp"]/message_doc[@name="UsesMaxConditional{T}(IList{T}, T, int, T)"]/*'/>
        /// <typeparam name="T">The type of the distribution o0ver the replicated variable.</typeparam>
        public static T UsesMaxConditional <T>([AllExceptIndex] IList <T> Uses, [SkipIfUniform] T Def, int resultIndex, T result)
            where T : SettableToProduct <T>, SettableTo <T>
        {
            T res = ReplicateOp_NoDivide.UsesAverageConditional <T>(Uses, Def, resultIndex, result);

            if (res is UnnormalizedDiscrete)
            {
                ((UnnormalizedDiscrete)(object)res).SetMaxToZero();
            }
            return(res);
        }
コード例 #5
0
#pragma warning disable 162
#endif

        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="Replicate2BufferOp"]/message_doc[@name="UsesAverageConditional{T}(IList{T}, T, T, int, T)"]/*'/>
        /// <typeparam name="T">The type of the messages.</typeparam>
        //[SkipIfAllUniform]
        public static T UsesAverageConditional <T>(
            [MatchingIndex, IgnoreDependency] IReadOnlyList <T> Uses, // Uses dependency must be ignored for Sequential schedule
            [IgnoreDependency, SkipIfUniform] T Def,
            [Fresh, SkipIfUniform] T marginal,
            int resultIndex,
            T result)
            where T : SettableToRatio <T>, SettableToProduct <T>, SettableTo <T>
        {
            if (resultIndex < 0 || resultIndex >= Uses.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(resultIndex));
            }
            if (Uses.Count == 1)
            {
                result.SetTo(Def);
                return(result);
            }
            if (true)
            {
                try
                {
                    result.SetToRatio(marginal, Uses[resultIndex]);
                    return(result);
                }
                catch (DivideByZeroException)
                {
                    return(ReplicateOp_NoDivide.UsesAverageConditional(Uses, Def, resultIndex, result));
                }
            }
            else
            {
                // check that ratio is same as product
                result.SetToRatio(marginal, Uses[resultIndex]);
                T result2 = (T)((ICloneable)result).Clone();
                ReplicateOp_NoDivide.UsesAverageConditional(Uses, Def, resultIndex, result2);
                double err = ((Diffable)result).MaxDiff(result2);
                if (err > 1e-4)
                {
                    Console.WriteLine(err);
                }
                return(result);
            }
        }
コード例 #6
0
 /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ReplicateBufferOp"]/message_doc[@name="UsesAverageConditional{T}(T[], T, T, int, T)"]/*'/>
 /// <typeparam name="T">The type of the distribution over the replicated variable.</typeparam>
 //[SkipIfAllUniform]
 public static T UsesAverageConditional <T>([AllExceptIndex] T[] Uses, [SkipIfUniform] T Def, [SkipIfUniform, Fresh] T to_marginal, int resultIndex, T result)
     where T : SettableToRatio <T>, SettableToProduct <T>, SettableTo <T>
 {
     if (resultIndex < 0 || resultIndex >= Uses.Length)
     {
         throw new ArgumentOutOfRangeException(nameof(resultIndex));
     }
     if (Uses.Length == 1)
     {
         result.SetTo(Def);
         return(result);
     }
     try
     {
         result.SetToRatio(to_marginal, Uses[resultIndex]);
         return(result);
     }
     catch (DivideByZeroException)
     {
         return(ReplicateOp_NoDivide.UsesAverageConditional(Uses, Def, resultIndex, result));
     }
 }
コード例 #7
0
 /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ReplicateMaxOp"]/message_doc[@name="DefMaxConditional{T}(IList{T}, T)"]/*'/>
 /// <typeparam name="T">The type of the distribution o0ver the replicated variable.</typeparam>
 public static T DefMaxConditional <T>([SkipIfAllUniform] IReadOnlyList <T> Uses, T result)
     where T : SettableToProduct <T>, SettableTo <T>, SettableToUniform
 {
     return(ReplicateOp_NoDivide.DefAverageConditional <T>(Uses, result));
 }
コード例 #8
0
 public static T DefAverageLogarithm <T>([SkipIfAllUniform] T[] Uses, T result)
     where T : SettableToProduct <T>, SettableTo <T>, SettableToUniform
 {
     return(ReplicateOp_NoDivide.DefAverageConditional(Uses, result));
 }
コード例 #9
0
 public static T Marginal <T>(IReadOnlyList <T> Uses, T Def, T result)
     where T : SettableToProduct <T>, SettableTo <T>
 {
     return(ReplicateOp_NoDivide.MarginalAverageConditional(Uses, Def, result));
 }