Пример #1
0
 public World(Vector3 <decimal> center, Vector3 <decimal> size, Vector3 <decimal> drawBoundingBox)
     : base(center, size, drawBoundingBox)
 {
     Grid           = new UnboundedGrid3D <Tile>(ChunkSize.To <long>());
     MeshRenderer   = new MeshRenderer <BasicMeshVertex>($"{nameof(World)}.{nameof(MeshRenderer)}");
     DiffuseSampler = Sampler.Create($"{nameof(World)} Mesh Diffuse Sampler");
 }
Пример #2
0
 private static void Register(ContainerBuilder builder)
 {
     //log4net.Config.XmlConfigurator.Configure();
     builder.Register(c => Sampler.Create(1.0F)).As <Sampler>().SingleInstance();
     builder.RegisterType <ZipkinSpanWriter>();
     builder.RegisterType <DbSpanStore>().As <ISpanStore>();
 }
Пример #3
0
        public void Gaussian_Bernoulli_Mean()
        {
            // arrange
            Uncertain <double> X = new Gaussian(1.0, 1.0);
            Uncertain <double> Y = new Gaussian(3.0, 2.0);
            var Z       = X > Y;
            var sampler = Sampler.Create(Z);
            int k       = 0;

            // act

            foreach (var s in sampler.Take(100))
            {
                if (s.Value)
                {
                    k += 1;
                }
            }
            // assert
            // Y - X is Gaussian(1, sqrt(5)), and has a 32.74% chance of being < 0
            // (i.e. 32.74% chance that X > Y)
            // The normal approximation to the binomial distribution says that the
            // 99.9997% confidence interval with n=100, p=0.3274 is +/- 0.1883.
            // So the confidence interval is roughly [0.13, 0.52].
            Assert.IsTrue(k >= 13 && k < 52); // flaky at N = 100!
        }
Пример #4
0
        public static Uncertain <T> SampledInference <T>(this Uncertain <T> source, int samplesize, IEqualityComparer <T> comparer = null)
        {
            var sampler = Sampler.Create(source);
            // cache data
            var data = sampler.Take(samplesize).ToList();

            return(RunInference(data, comparer));
        }
Пример #5
0
        public void Constant_Sample()
        {
            // arrange
            Uncertain <double> X = 5.0;
            var sampler          = Sampler.Create(X);
            // act
            var S = sampler.First();

            // assert
            Assert.AreEqual(S.Value, 5.0);
        }
Пример #6
0
        public void Gaussian_Sample()
        {
            // arrange
            Uncertain <double> X = new Gaussian(5.0, 2.0);
            var sampler          = Sampler.Create(X);

            foreach (var s in sampler.Take(100))
            {
                // assert
                Assert.IsTrue(s.Value >= -3 && s.Value <= 13);
            }
        }
Пример #7
0
        public void Constant_Bernoulli_Sample()
        {
            // arrange
            Uncertain <double> X = new Constant <double>(5.0);
            Uncertain <double> Y = new Constant <double>(6.0);
            var Z       = X > Y;
            var sampler = Sampler.Create(Z);
            // act
            var S = sampler.First();

            // assert
            Assert.AreEqual(S.Value, false);
        }
Пример #8
0
        public void Uniform_Sample()
        {
            // arrange
            double             Start = 4.0, End = 6.0;
            Uncertain <double> X = new Uniform <double>(Start, End);
            var sampler = Sampler.Create(X);

            foreach (var p in sampler.Take(100))
            {
                double s = p.Value;
                // assert
                Assert.IsTrue(s >= Start && s <= End);
            }
        }
Пример #9
0
        public void Constant_BNN_Sample()
        {
            // arrange
            Uncertain <double> X = new Constant <double>(5.0);
            Uncertain <double> Y = new Constant <double>(6.0);
            Uncertain <double> Z = from x in X
                                   from y in Y
                                   select x + y;
            var sampler = Sampler.Create(Z);
            // act
            var S = sampler.First();

            // assert
            Assert.AreEqual(S.Value, 11.0);
        }
Пример #10
0
        public void Base_Implicit()
        {
            // arrange
            Uncertain <double> X = 5.0;
            Uncertain <double> Y = 6.0;
            // act
            Uncertain <double> Z = from x in X
                                   from y in Y
                                   select x + y;
            var sampler = Sampler.Create(Z);
            var s       = sampler.First();

            // assert
            Assert.AreEqual(s.Value, 11.0);
        }
Пример #11
0
        public void Uniform_Bernoulli_Sample()
        {
            // arrange
            Uncertain <double> X = new Uniform <double>(1.0, 3.0);
            Uncertain <double> Y = new Uniform <double>(4.0, 5.0);
            var Z       = X > Y;
            var sampler = Sampler.Create(Z);

            foreach (var p in sampler.Take(100))
            {
                // act
                bool s = p.Value;
                // assert
                Assert.IsFalse(s);
            }
        }
Пример #12
0
        public void Gaussian_BNN_Sample()
        {
            // arrange
            Uncertain <double> X = new Gaussian(1.0, 1.0);
            Uncertain <double> Y = new Gaussian(4.0, 1.0);
            Uncertain <double> Z = from x in X
                                   from y in Y
                                   select x + y;
            var sampler = Sampler.Create(Z);

            foreach (var s in sampler.Take(100))
            {
                // assert
                Assert.IsTrue(s.Value >= -3 && s.Value <= 13.0);
            }
        }
Пример #13
0
        public void Uniform_BNN_Sample()
        {
            // arrange
            Uncertain <double> X = new Uniform <double>(1.0, 3.0);
            Uncertain <double> Y = new Uniform <double>(4.0, 5.0);
            Uncertain <double> Z = from x in X from y in Y select x + y;
            var sampler          = Sampler.Create(Z);

            // act
            foreach (var p in sampler.Take(100))
            {
                // act
                double s = p.Value;
                // assert
                Assert.IsTrue(s >= 1.0 && s <= 8.0);
            }
        }
Пример #14
0
        public void Gaussian_Mean()
        {
            // arrange
            double             Sum = 0.0;
            Uncertain <double> X   = new Gaussian(5.0, 1.0);
            var sampler            = Sampler.Create(X);

            // act
            foreach (var s in sampler.Take(100))
            {
                Sum += s.Value;
            }
            Sum /= 100;
            // assert
            // If everything is working, this has about a 0.003% chance of a false positive
            // (99.9997% confidence interval with n=100, sigma=1.0 is +/- 0.4)
            Assert.IsTrue(Sum >= 4.6 && Sum <= 5.4);
        }
Пример #15
0
        public void Base_Sample()
        {
            Uncertain <GeoLocation> roads = null;
            Uncertain <GeoLocation> gps   = null;
            Func <GeoLocation, GeoLocation, double> Likelihood = (a, b) => 1.0;
            var p =
                from pos in gps
                from road in roads
                let prob = Likelihood(pos, road)
                           select new Weighted <GeoLocation>(pos, prob);

            // arrange
            Uncertain <double> X = 5.0;
            // act
            var sampler = Sampler.Create(X);
            var S       = sampler.First();

            // assert
            Assert.AreEqual(S.Value, 5.0);
        }
Пример #16
0
        public void Gaussian_BNN_Mean()
        {
            // arrange
            Uncertain <double> X = new Gaussian(1.0, 1.0);
            Uncertain <double> Y = new Gaussian(4.0, 2.0);
            Uncertain <double> Z = from x in X
                                   from y in Y
                                   select x + y;
            double Sum = 0.0;
            // act
            var sampler = Sampler.Create(Z);

            foreach (var s in sampler.Take(100))
            {
                Sum += s.Value;
            }
            Sum /= 100.0;
            // assert
            // Z is known to be Gaussian(5.0, sqrt(5))
            // If everything is working, this has about a 0.003% chance of a false positive
            // (99.9997% confidence interval with n=100, sigma=sqrt(5) is +/- 0.89)
            Assert.IsTrue(Sum >= 4.11 && Sum <= 5.89);
        }
Пример #17
0
        internal OpenCLFractalEngine(OpenTK.Graphics.IGraphicsContext graphicsContext, Platform platform, Device device)
        {
            if (graphicsContext == null || !(graphicsContext is OpenTK.Graphics.IGraphicsContextInternal))
            {
                throw new ArgumentException("Invalid graphics context for OpenCLFractalEngine.", "graphicsContext");
            }

            if (platform == null)
            {
                throw new ArgumentException("Invalid platform for OpenCLFractalEngine", "platform");
            }

            if (device == null)
            {
                throw new ArgumentException("Invalid device for OpenCLFractalEngine", "device");
            }

            this.platform = platform;
            this.device   = device;

            useLowProfile = !device.ImageSupport;

            IntPtr curDC = wglGetCurrentDC();

            OpenTK.Graphics.IGraphicsContextInternal gCtx = (OpenTK.Graphics.IGraphicsContextInternal)graphicsContext;

            context = OpenCL.Context.Create(new Device[] { device },
                                            new ContextParam(ContextProperties.Platform, platform),
                                            new ContextParam(ContextProperties.GlContext, gCtx.Context.Handle),
                                            new ContextParam(ContextProperties.WglHdc, curDC));

            iterBlockCount = Util.Clamp((int)device.MaxComputeUnits * 2, 2, 64);

            string source = null;

            if (useLowProfile)
            {
                source = Kernels.KernelResources.kernels_low_cl;
            }
            else
            {
                source = Kernels.KernelResources.kernels_cl;
            }

            string opts = "";

            try{
                program = OpenCL.Program.CreateFromSource(context, new string[] { source });
                program.Build(new Device[] { device }, opts);
            }
            catch (OpenCLCallFailedException ex)
            {
                if (ex.ErrorCode == OpenCL.ErrorCode.BuildProgramFailure)
                {
                    ex.Data.Add("build_log", program.GetBuildLog(device));
                }
                throw ex;
            }

            initIteratorsKernel  = Kernel.Create(program, "init_iterators_kernel");
            resetIteratorsKernel = Kernel.Create(program, "reset_iterators_kernel");
            iterateKernel        = Kernel.Create(program, "iterate_kernel");
            updateStatsKernel    = Kernel.Create(program, "update_stats_kernel");
            resetOutputKernel    = Kernel.Create(program, "reset_output_kernel");
            updateOutputKernel   = Kernel.Create(program, "update_output_kernel");
            glOutputBufferID     = 0;

            queue = CommandQueue.Create(context, device, CommandQueueFlags.ProfilingEnable);

            fractalBuffer    = context.CreateBuffer(MemFlags.ReadOnly, Marshal.SizeOf(typeof(NativeFractal)));
            branchBuffer     = context.CreateBuffer(MemFlags.ReadOnly, Marshal.SizeOf(typeof(NativeBranch)) * NativeFractal.MaxBranches);
            variWeightBuffer = context.CreateBuffer(MemFlags.ReadOnly, 4 * NativeFractal.MaxBranches * NativeFractal.MaxVariations);

            iterPosStateBuffer   = context.CreateBuffer(MemFlags.ReadWrite, (8 * IteratorCount));
            iterColorStateBuffer = context.CreateBuffer(MemFlags.ReadWrite, (8 * IteratorCount));
            iterStatBuffer       = context.CreateBuffer(MemFlags.ReadWrite, Marshal.SizeOf(typeof(NativeIterStatEntry)) * IteratorCount);
            globalStatBuffer     = context.CreateBuffer(MemFlags.ReadWrite, Marshal.SizeOf(typeof(NativeGlobalStatEntry)));

            entropyXBuffer    = context.CreateBuffer(MemFlags.ReadWrite, (16 * IteratorCount));
            entropyCBuffer    = context.CreateBuffer(MemFlags.ReadWrite, (4 * IteratorCount));
            entropySeedBuffer = context.CreateBuffer(MemFlags.ReadWrite, (4 * IteratorCount));

            uint[] seeds = new uint[IteratorCount];
            for (int i = 0; i < IteratorCount; i++)
            {
                seeds[i] = (uint)rand.Next(65536);
            }
            entropySeedBuffer.Write(queue, seeds);

            paletteSize   = new Size(0, 0);
            paletteImage  = null;
            paletteBuffer = null;
            if (!useLowProfile)
            {
                paletteSampler = Sampler.Create(context, true, AddressingMode.ClampToEdge, FilterMode.Linear);
            }

            initIteratorsKernel.SetArgs(entropyXBuffer, entropyCBuffer, entropySeedBuffer);
            Event initEvt;

            initIteratorsKernel.EnqueueLaunch(queue, IteratorCount, IterGroupSize, null, out initEvt);
            initEvt.Wait();
            disposeAndNullify(ref initEvt);

            queue.Finish();
        }
Пример #18
0
        private void Register(ContainerBuilder builder)
        {
            log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Global));
            builder.RegisterInstance(logger).SingleInstance();
            var spanCollector = new HttpSpanCollector("http://192.168.1.232:9411");

            ZipkinWrapper.Builder zipkinBuilder = new ZipkinWrapper.Builder("ZipkinTracerIntegration")
                                                  .SpanCollector(spanCollector).TraceSampler(Sampler.Create(0.5F));
            var wrapper = zipkinBuilder.Build();

            ZipkinTracer.Initialize(wrapper);
            builder.RegisterInstance(wrapper.ServerTracer()).SingleInstance();
            builder.RegisterInstance(wrapper.ClientTracer()).SingleInstance();
            builder.RegisterInstance(wrapper.LocalTracer()).SingleInstance();
            builder.RegisterInstance(wrapper.ServerRequestInterceptor()).SingleInstance();
            builder.RegisterInstance(wrapper.ServerResponseInterceptor()).SingleInstance();
            builder.RegisterInstance(wrapper.ClientRequestInterceptor()).SingleInstance();
            builder.RegisterInstance(wrapper.ClientResponseInterceptor()).SingleInstance();
            builder.RegisterInstance(wrapper.ServerSpanThreadBinder()).SingleInstance();
            builder.RegisterInstance(wrapper.ClientSpanThreadBinder()).SingleInstance();

            builder.RegisterType <DefaultSpanNameProvider>().As <ISpanNameProvider>().SingleInstance();
            builder.RegisterType <ZipkinTraceModule>().As <IHttpModule>().SingleInstance();
        }