예제 #1
0
        public ISampleSelector MakeThreePSampleSelector(SamplerInfo samplerInfo)
        {
            if (samplerInfo is null)
            {
                throw new ArgumentNullException(nameof(samplerInfo));
            }

            var state = Dataservice.GetSamplerState(samplerInfo.StratumCode, samplerInfo.SampleGroupCode);

            if (state != null)
            {
                var selector = new ThreePSelecter(samplerInfo.KZ,
                                                  samplerInfo.InsuranceFrequency,
                                                  state.Counter,
                                                  state.InsuranceIndex,
                                                  state.InsuranceCounter);
                selector.StratumCode     = samplerInfo.StratumCode;
                selector.SampleGroupCode = samplerInfo.SampleGroupCode;
                return(selector);
            }
            else
            {
                var selector = new ThreePSelecter(samplerInfo.KZ, samplerInfo.InsuranceFrequency);
                selector.StratumCode     = samplerInfo.StratumCode;
                selector.SampleGroupCode = samplerInfo.SampleGroupCode;
                return(selector);
            }
        }
        public void TestThreePSelecter()
        {
            double tolarance = .5;

            int iFrequency = 5;
            int aveKpi     = 20;
            int freq       = 500;
            int popSize    = 10_000;
            int numSamples = popSize / freq;
            //int numIsamples = (iFrequency > 0) ? numSamples / iFrequency : 0; // same as other implementation but less consistant with how i test other methods
            int numIsamples = (iFrequency > 0) ? popSize / (iFrequency * freq) : 0;

            int popVol = aveKpi * popSize;
            int kz     = popVol / numSamples;

            var selecter = new ThreePSelecter(kz, iFrequency);

            int sampleCounter  = 0;
            int iSampleCounter = 0;

            for (int i = 0; i < popSize; i++)
            {
                var result = selecter.Sample(aveKpi);

                if (result == SampleResult.M)
                {
                    sampleCounter++;
                }
                else if (result == SampleResult.I)
                {
                    iSampleCounter++;
                }
            }

            // taking the double sided binomial probability with the number of samples recieved against our frequency
            // will tell us the liklyhood of recieving the number of samples we recieved
            // check that probability against our tolarance

            var likelihood_twoSided = 2 * BinomialProbability(popSize, sampleCounter, 1 / (double)freq);

            likelihood_twoSided.Should().BeLessThan(tolarance);


            if (iFrequency > 1)
            {
                // because insurance trees should be generated for x number of
                // regular samples. We should know exactly how many insurance samples
                // to expect give or take one
                var actualExpectediSamples = sampleCounter / (double)(iFrequency);

                var iSampleDiff = Math.Abs(iSampleCounter - numIsamples);

                iSampleDiff.Should().BeLessOrEqualTo(1);
            }
        }
예제 #3
0
 public SampleResult Sample(int kpi, out int rand)
 {
     return(ThreePSelecter.Sample(kpi, out rand));
 }
예제 #4
0
 public S3PSelector(int freq, int kz, int count, string blockState)
 {
     _blockSelecter  = new BlockSelecter(freq, 0, blockState, count, 0, 0);
     _threePSelecter = new ThreePSelecter(kz, 0);
 }
예제 #5
0
 public S3PSelector(int freq, int kz)
 {
     _blockSelecter  = new BlockSelecter(freq, 0);
     _threePSelecter = new ThreePSelecter(kz, 0);
 }