Exemplo n.º 1
0
 /// <summary>
 /// Set this ArrayEstimator to another ArrayEstimator
 /// </summary>
 /// <param name="value"></param>
 public void SetTo(ArrayEstimator <ItemEstimator, DistributionArray, Distribution, Sample> value)
 {
     if (value.estimators.Length != estimators.Length)
     {
         throw new ArgumentException("value.estimators.Length (" + value.estimators.Length + ") != estimators.Length (" + estimators.Length + ")");
     }
     for (int i = 0; i < estimators.Length; i++)
     {
         estimators[i].SetTo(value.estimators[i]);
     }
 }
Exemplo n.º 2
0
        public GibbsMarginal(TDist distPrototype, int burnIn, int thin, bool estimateMarginal, bool collectSamples, bool collectDistributions)
        {
            this.LastConditional = (TDist)(distPrototype.Clone());
            this.LastSample      = default(T);
            this.resultWorkspace = (TDist)(distPrototype.Clone());
            this.estimator       = null;

            if (collectSamples)
            {
                // The sample list
                Accumulator <T> sampAcc = new SampleList <T>() as Accumulator <T>;
                // Add to the list of sample accumulators.
                // This is this first in the list - do not change as some code depends on this
                this.sampleAccumulators.Accumulators.Add(new BurnInAccumulator <T>(burnIn, thin, sampAcc));
            }
            if (collectDistributions)
            {
                // The conditional list
                Accumulator <TDist> condAcc = new ConditionalList <TDist>() as Accumulator <TDist>;
                // Add to the list of distribution accumulators.
                // This is this first in the list - do not change as some code depends on this
                this.distribAccumulators.Accumulators.Add(new BurnInAccumulator <TDist>(burnIn, thin, condAcc));
            }

            if (estimateMarginal)
            {
                // Try to create an estimator where we can add distributions. This should usually
                // be the case. If not, create an estimator where we add samples
                try
                {
                    this.estimator = ArrayEstimator.CreateEstimator <TDist, T>(distPrototype, true);
                }
                catch (Exception)
                {
                }
                if (this.estimator == null)
                {
                    this.estimator = ArrayEstimator.CreateEstimator <TDist, T>(distPrototype, false);
                    Accumulator <T> acc = this.estimator as Accumulator <T>;
                    // Thinning is always 1 for estimators
                    this.sampleAccumulators.Accumulators.Add(new BurnInAccumulator <T>(burnIn, 1, acc));
                }
                else
                {
                    Accumulator <TDist> acc = this.estimator as Accumulator <TDist>;
                    // Thinning is always 1 for estimators
                    this.distribAccumulators.Accumulators.Add(new BurnInAccumulator <TDist>(burnIn, 1, acc));
                }
            }
            Clear();
        }