Exemplo n.º 1
0
        public void VectorSquaredEuclideanDistance()
        {
            var distribution = new Normal(0, 5);

            var a        = _cpu.CreateVector(5000, i => Convert.ToSingle(distribution.Sample())).AsIndexable();
            var b        = _cpu.CreateVector(5000, i => Convert.ToSingle(distribution.Sample())).AsIndexable();
            var distance = a.SquaredEuclidean(b);

            float distance2;

            using (var gpuA = _cuda.CreateVector(a))
                using (var gpuB = _cuda.CreateVector(b))
                    distance2 = gpuA.SquaredEuclidean(gpuB);

            Assert.IsTrue(FloatingPointHelper.AlmostEqual2sComplement(distance, distance2, 11));
        }
Exemplo n.º 2
0
        public void VectorCosineDistance()
        {
            var rand = new Random(0);

            var a        = _cpu.CreateVector(5000, i => Convert.ToSingle(rand.NextDouble())).AsIndexable();
            var b        = _cpu.CreateVector(5000, i => Convert.ToSingle(rand.NextDouble())).AsIndexable();
            var distance = a.CosineDistance(b);

            float distance2;

            using (var gpuA = _cuda.CreateVector(a))
                using (var gpuB = _cuda.CreateVector(b))
                    distance2 = gpuA.CosineDistance(gpuB);

            Assert.IsTrue(FloatingPointHelper.AlmostEqual2sComplement(distance, distance2, 10));
        }
Exemplo n.º 3
0
        public void VectorMeanSquaredDistance()
        {
            Load();
            var   distribution = new Normal(0, 5);
            var   a            = _cpu.CreateVector(5000, i => Convert.ToSingle(distribution.Sample())).AsIndexable();
            var   b            = _cpu.CreateVector(5000, i => Convert.ToSingle(distribution.Sample())).AsIndexable();
            var   distance     = a.MeanSquaredDistance(b);
            float distance2;

            using (var gpuA = _cuda.CreateVector(a))
            {
                using var gpuB = _cuda.CreateVector(b);
                distance2      = gpuA.MeanSquaredDistance(gpuB);
            }

            Assert.IsTrue(FloatingPointHelper.AlmostEqual2sComplement(distance, distance2, 11));
            Cleanup();
        }