public static RF Prob(IDensity <G, M, RF> d, Func <M, bool> cond) { var rf = d.RealField; var resSum = rf.Sum(d.GetKeys().Where(cond).Select(k => d[k])); return(resSum); }
public static IList <M> SortedKeys <G, M, RF>(this IDensity <G, M, RF> d) where G : IBaseStructure <M>, IComparer <M> { return(d.GetKeys().OrderBy(k => k, d.BaseStructure).ToList()); }
public static RF BinaryProb(IDensity <G, M, RF> d1, IDensity <G, M, RF> d2, Func <M, M, bool> cond) { var resSum = default(RF); var rf = d1.RealField; foreach (var key1 in d1.GetKeys()) { foreach (var key2 in d2.GetKeys()) { if (cond(key1, key2)) { resSum = rf.Add(resSum, rf.Multiply(d1[key1], d2[key2])); } } } return(resSum); }
protected static IDictionary <N, RF> GetOpDictionary <N>( IDensity <G, M, RF> d, Func <M, N> op) { var resDensity = new Dictionary <N, RF>(); var rf = d.RealField; foreach (var key in d.GetKeys()) { var resKey = op(key); if (!resDensity.ContainsKey(resKey)) { resDensity[resKey] = default(RF); } resDensity[resKey] = rf.Add(resDensity[resKey], d[key]); } return(resDensity); }
protected static IDictionary <M, RF> GetConditionalDensityDictionary( IDensity <G, M, RF> d, Func <M, bool> cond) { var resDict = new Dictionary <M, RF>(); var rf = d.RealField; foreach (var key in d.GetKeys().Where(cond)) { resDict[key] = d[key]; } var conditionalProbability = rf.Sum(resDict.Values); foreach (var key in resDict.Keys) { resDict[key] = rf.Divide(resDict[key], conditionalProbability); } return(resDict); }
protected static IDictionary <N, RF> GetBinaryOpDictionary <N>( IDensity <G, M, RF> d1, IDensity <G, M, RF> d2, Func <M, M, N> op) { var resDensity = new Dictionary <N, RF>(); var rf = d1.RealField; foreach (var key1 in d1.GetKeys()) { foreach (var key2 in d2.GetKeys()) { var resKey = op(key1, key2); if (!resDensity.ContainsKey(resKey)) { resDensity[resKey] = default(RF); } resDensity[resKey] = rf.Add(resDensity[resKey], rf.Multiply(d1[key1], d2[key2])); } } return(resDensity); }
public static IList <RF> GetValues <G, M, RF>(this IDensity <G, M, RF> d) { return(d.GetKeys().Select(k => d.Dictionary[k]).ToList()); }