コード例 #1
0
        public void Add(IDistribution d, double w)
        {
            if (_completed)
            {
                throw new Exception("Attempt to add a distribution to a Mixture that is marked completed");
            }
            if (d.SampleSpace != this.SampleSpace)
            {
                throw new Exception("Incompatible IDistribution added to Mixture");
            }

            //if (!_component.ContainsKey(d)) {
            // if (!_component.Contains(d)) {
            if (!Contains(d))
            {
                MixtureComponent mc = new MixtureComponent();
                mc.Distribution = d;
                mc.Weight       = w;
                mc.MinWeight    = 0.0;
                mc.MaxWeight    = 1.0;

                _component.Add(mc);

                // the parameters of the component distribution
                this.addParams(d.Params);
                // the weight of the component distribution in NOT a parameter in an immutable mixture
                // this.addParams(AdditionalPerComponentParameters);
            }
            else
            {
                throw new Exception("Duplicate IDistribution added to Mixture");
            }
        }
コード例 #2
0
        private void normalize()
        {
            double total = totalWeight();

            // Dictionary<IDistribution, double> component2 = new Dictionary<IDistribution, double>();
            // C5.HashDictionary<IDistribution, double> component2 = new C5.HashDictionary<IDistribution, double>();
            List <MixtureComponent> component2 = new List <MixtureComponent>();

            foreach (MixtureComponent mc in _component)
            {
                IDistribution d = mc.Distribution;
                double        w = mc.Weight;

                MixtureComponent mc2 = new MixtureComponent();
                mc2.Distribution = d;
                mc2.Weight       = w / total;

                component2.Add(mc2);
            }

            _component = component2;
        }