public void TestAccumulatorAddRemove()
        {
            Accumulator accumulator = new Accumulator();

            for(int i = 0; i <= 10; i++)
            {
                accumulator.Add(i);
            }

            Assert.That(accumulator.Mean, NumericIs.AlmostEqualTo((double) 5), "A Mean");
            Assert.That(accumulator.Variance, NumericIs.AlmostEqualTo((double) 11), "A Variance");
            Assert.That(accumulator.Sum, NumericIs.AlmostEqualTo((double) 55), "A Sum");

            accumulator.Remove(9);
            accumulator.Remove(4);

            Assert.That(accumulator.Mean, NumericIs.AlmostEqualTo(14d / 3), "B Mean");
            Assert.That(accumulator.Variance, NumericIs.AlmostEqualTo(23d / 2), "B Variance");
            Assert.That(accumulator.Sum, NumericIs.AlmostEqualTo((double) 42), "B Sum");

            accumulator.Add(9);
            accumulator.Add(4);

            Assert.That(accumulator.Mean, NumericIs.AlmostEqualTo((double) 5), "C Mean");
            Assert.That(accumulator.Variance, NumericIs.AlmostEqualTo((double) 11), "C Variance");
            Assert.That(accumulator.Sum, NumericIs.AlmostEqualTo((double) 55), "C Sum");
        }
        public void TestAccumulatorNumericStability()
        {
            /* NOTE: Statistically it is possible that this test fails even
              * if everything works as expected. However, it's very unlikely to happen,
              * and even more unlikely to happen in a series. */

            Accumulator accumulator = new Accumulator();
            NormalDistribution gaussian = new NormalDistribution();

            // Test around 0, no stability issues expected
            gaussian.SetDistributionParameters(0, 1);
            for(int i = 0; i < 10000; i++)
            {
                accumulator.Add(gaussian.NextDouble());
            }

            Assert.That(accumulator.Mean, NumericIs.AlmostEqualTo((double) 0, 0.2), "Mean of (0,1)");
            Assert.That(accumulator.Variance, NumericIs.AlmostEqualTo((double) 1, 0.5), "Variance of (0,1)");

            // Test around 10^9, potential stability issues
            accumulator.Clear();
            gaussian.SetDistributionParameters(1e+9, 1);
            for(int i = 0; i < 10000; i++)
            {
                accumulator.Add(gaussian.NextDouble());
            }

            Assert.That(accumulator.Mean, NumericIs.AlmostEqualTo(1e+9, 0.2), "Mean of (1e+9,1)");
            Assert.That(accumulator.Variance, NumericIs.AlmostEqualTo((double) 1, 0.5), "Variance of (1e+9,1)");
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Dictionary<string, Accumulator> vals = new Dictionary<string, Accumulator>();

              Model m = new Model(args[0]);

              JupiterXL JXL = new JupiterXL(args[1]);
              JXL.ReadWells(true, false);
              JXL.ReadInLithology();

              foreach (var geo in JXL.LITHSAMP)
              {
            if (!geo.IsROCKSYMBOLNull() && !geo.IsBOTTOMNull() && !geo.IsTOPNull() && geo.ROCKSYMBOL.Trim() != "")
            {
              var Boring = JXL.BOREHOLE.FindByBOREHOLENO(geo.BOREHOLENO);

              if (Boring != null && !Boring.IsXUTMNull() && !Boring.IsYUTMNull())
              {
            int Column = m.GridInfo.GetColumnIndex(Boring.XUTM);
            int row = m.GridInfo.GetRowIndex(Boring.YUTM);
            if (row >= 0 & Column >= 0)
            {
              int Layer = m.GridInfo.GetLayer(Column, row, m.GridInfo.SurfaceTopography.Data[row, Column] - (geo.TOP + geo.BOTTOM) / 2);
              if (Layer >= 0)
              {
                Accumulator Ledningsevner;
                if (!vals.TryGetValue(geo.ROCKSYMBOL, out Ledningsevner))
                {
                  Ledningsevner = new Accumulator();
                  vals.Add(geo.ROCKSYMBOL, Ledningsevner);
                }
                Ledningsevner.Add(Math.Log10(m.Processed.HorizontalConductivity.Data[row, Column, Layer]));
              }

            }
              }
            }
              }//End of loop

              Accumulator all = new Accumulator();
              for (int lay = 0; lay < m.GridInfo.NumberOfLayers; lay++)
            for (int row = 0; row < m.GridInfo.NumberOfRows; row++)
              for (int col = 0; col < m.GridInfo.NumberOfColumns; col++)
            if (m.GridInfo.ModelDomainAndGrid.Data[row, col] == 1)
              all.Add(Math.Log10(m.Processed.HorizontalConductivity.Data[row, col, lay]));

              vals.Add("All", all);

              using (StreamWriter sw = new StreamWriter(@"F:\temp\out.txt", false, Encoding.Default))
              {
            sw.WriteLine("Rocksymbol\tNoOfEntries\tMean\tVariance\tStandard Deviation");
            foreach (KeyValuePair<string, Accumulator> KVP in vals.OrderByDescending((acc) => acc.Value.Count))
            {
              sw.WriteLine(KVP.Key + "\t" + KVP.Value.Count + "\t" + KVP.Value.Mean + "\t" + KVP.Value.Variance + "\t" + KVP.Value.Sigma);
            }
              }
              JXL.Dispose();
        }
Ejemplo n.º 4
0
 public double EstimateMeanSquaredError()
 {
     Accumulator accu = new Accumulator();
     foreach(Sample s in _provider)
     {
         double v = EvaluateFunction(s.Coordinate);
         accu.Add(v - s.Value);
     }
     return accu.MeanSquared;
 }
 EstimateDistributionParameters(
     IEnumerable<double> samples
     )
 {
     Accumulator accumulator = new Accumulator(samples);
     SetDistributionParameters(accumulator.Mean, accumulator.Sigma);
 }