public ExtendedProbabilityTable(ProbabilityTable <T> archetype)
        {
            double sum = 0;

            foreach (T key in archetype.Keys.OrderBy(k => k))
            {
                double probability = archetype.GetProbability(key);

                sum += probability;

                ExtentedProbabilityRecord <T> newRecord = new ExtentedProbabilityRecord <T>(key, probability);
                _table[key] = newRecord;
            }

            double cumulative = 0;

            foreach (var tableKey in _table.Keys)
            {
                var record = _table[tableKey];

                record.NormalizedProbability = record.Probability / sum;

                cumulative += record.NormalizedProbability;
                record.CumulativeProbability = cumulative;
            }
        }
示例#2
0
        public ExtendedProbabilityTable <T> GetExtendedProbabilityTable <T>(string name)
        {
            dynamic table;

            if (!_extendedTables.TryGetValue(name, out table))
            {
                dynamic notExtended;

                if (!_probabilityTables.TryGetValue(name, out notExtended))
                {
                    throw new ArgumentException("Cannot found probability table by name:" + name);
                }

                ProbabilityTable <T> archetype = (ProbabilityTable <T>)notExtended;

                table = new ExtendedProbabilityTable <T>(archetype);
                _extendedTables.Add(name, table);
            }

            return(table);
        }
示例#3
0
 public void AddProbabilityTable <T>(string name, ProbabilityTable <T> table)
 {
     _probabilityTables.Add(name, table);
 }