public void TestTwoAttributeAxes()
        {
            List <DataPoint> dataPoints = new List <DataPoint> {
                new DataPoint {
                    Class      = 1,
                    Attributes = new float[] { 123, 987 },
                    Categories = new uint[] { },
                    Weight     = 1.0f,
                },
                new DataPoint {
                    Class      = 0,
                    Attributes = new float[] { 123, 876 },
                    Categories = new uint[] { },
                    Weight     = 1.0f,
                },
                new DataPoint {
                    Class      = 1,
                    Attributes = new float[] { 456, 765 },
                    Categories = new uint[] { },
                    Weight     = 1.0f,
                },
                new DataPoint {
                    Class      = 1,
                    Attributes = new float[] { 456, 543 },
                    Categories = new uint[] { },
                    Weight     = 1.0f,
                },
            };

            using (CudaManager cudaManager = Provider.CudaManagerPool.GetCudaManagerForThread(Provider.Logger))
                using (DecisionLearner decisionLearner = new DecisionLearner(cudaManager, dataPoints)) {
                    IDataNode root = decisionLearner.FitDecisionTree().Node;
                    Assert.AreEqual(1.0, Accuracy(root, dataPoints));
                }
        }
Exemplo n.º 2
0
    static void Main()
    {
        cuda   = new CUDA(true);
        cublas = new CUBLAS(cuda);
        //allocate vector on cuda device in main thread
        CudaManager.CallMethod(AllocateVectors);
        //changing first vector from other thread
        Thread changeThread = new Thread(ChangeVectorOnDevice_ThreadRun)
        {
            IsBackground = false
        };

        changeThread.Start();
        //wait for changeThread to finish
        autoResetEvent.WaitOne();
        //getting vector from device in another one thread
        Thread getThread = new Thread(GetVectorFromDevice_ThreadRun)
        {
            IsBackground = false
        };

        getThread.Start();
        //wait for getThread to finish
        autoResetEvent.WaitOne();
        Console.WriteLine("({0}, {1}, {2}, {3}, {4})", vector2[0], vector2[1], vector2[2], vector2[3], vector2[4]);
        Console.ReadKey(true);
    }
 public DecisionLearnerContext(CudaManager cudaManager, IEnumerable <IDataPoint> dataPoints)
 {
     CudaManager = cudaManager;
     DataPoints  = dataPoints.ToList();
     TotalWeight = DataPoints.Sum(dp => dp.Weight);
     if (DataPoints.Count > 0)
     {
         NumAttributeAxes   = DataPoints[0].Attributes.Length;
         NumCategoricalAxes = DataPoints[0].Categories.Length;
     }
 }
        public void TestSum()
        {
            int[] numbers = Enumerable.Range(999, 10000).ToArray();
            using (CudaManager cudaManager = Provider.CudaManagerPool.GetCudaManagerForThread(Provider.Logger))
                using (CudaArray <int> numbersBuffer = numbers)
                    using (CudaArray <int> outputBuffer = new[] { 0 }) {
                        KernelManager kernels = new KernelManager(cudaManager);

                        for (int nBlocks = 1; nBlocks <= 1024; nBlocks *= 2)
                        {
                            for (int threadsPerBlock = 1; threadsPerBlock <= 1024; threadsPerBlock *= 2)
                            {
                                kernels["setIntKernel"].Arguments(outputBuffer, 0).ExecuteTask();
                                Assert.AreEqual(0, outputBuffer.Read()[0]);
                                kernels["sumToOutputKernel"].Arguments(numbersBuffer, numbers.Length, outputBuffer, SharedBuffer.Ints(threadsPerBlock)).Execute(nBlocks * threadsPerBlock, threadsPerBlock);
                                Assert.AreEqual(numbers.Sum(), outputBuffer.Read()[0]);
                            }
                        }
                    }
        }
        public void TestSimpleAttributeSplit()
        {
            List <DataPoint> dataPoints = new List <DataPoint> {
                new DataPoint {
                    Class      = 0,
                    Attributes = new float[] { 123 },
                    Categories = new uint[] { },
                    Weight     = 1.0f,
                },
                new DataPoint {
                    Class      = 1,
                    Attributes = new float[] { 456 },
                    Categories = new uint[] { },
                    Weight     = 1.0f,
                },
            };

            using (CudaManager cudaManager = Provider.CudaManagerPool.GetCudaManagerForThread(Provider.Logger))
                using (DecisionLearner decisionLearner = new DecisionLearner(cudaManager, dataPoints)) {
                    IDataNode root = decisionLearner.FitDecisionTree().Node;

                    AttributeSplit attributeSplit = (AttributeSplit)root;
                    Assert.AreEqual(0, attributeSplit.Axis);
                    Assert.AreEqual(456, attributeSplit.SplitValue);

                    DataLeaf left = (DataLeaf)attributeSplit.Left;
                    Assert.AreEqual(1, left.ClassDistribution[0]);
                    Assert.AreEqual(0, left.ClassDistribution[1]);

                    DataLeaf right = (DataLeaf)attributeSplit.Right;
                    Assert.AreEqual(0, right.ClassDistribution[0]);
                    Assert.AreEqual(1, right.ClassDistribution[1]);

                    Assert.AreEqual(1.0, Accuracy(root, dataPoints));
                }
        }
        public void TestCategoryPlusAttributeSplit()
        {
            List <DataPoint> dataPoints = new List <DataPoint> {
                new DataPoint {
                    Class      = 1,
                    Attributes = new float[] { 99, 987 },
                    Categories = new uint[] { 0x3, 0x1 },
                    Weight     = 1.0f,
                },
                new DataPoint {
                    Class      = 0,
                    Attributes = new float[] { 99, 987 },
                    Categories = new uint[] { 0x3, 0x1 | 0x2 },
                    Weight     = 1.0f,
                },
                new DataPoint {
                    Class      = 1,
                    Attributes = new float[] { 99, 765 },
                    Categories = new uint[] { 0x3, 0x1 | 0x2 },
                    Weight     = 1.0f,
                },
                new DataPoint {
                    Class      = 1,
                    Attributes = new float[] { 99, 765 },
                    Categories = new uint[] { 0x3, 0x1 },
                    Weight     = 1.0f,
                },
            };

            using (CudaManager cudaManager = Provider.CudaManagerPool.GetCudaManagerForThread(Provider.Logger))
                using (DecisionLearner decisionLearner = new DecisionLearner(cudaManager, dataPoints)) {
                    IDataNode root = decisionLearner.FitDecisionTree().Node;

                    Assert.AreEqual(1.0, Accuracy(root, dataPoints));
                }
        }
 public DecisionLearner(CudaManager cudaManager, IEnumerable <IDataPoint> dataPoints)
 {
     Context              = new DecisionLearnerContext(cudaManager, dataPoints);
     _attributeSplitter   = new AttributeSplitter(Context);
     _categoricalSplitter = new CategoricalSplitter(Context);
 }
 public GPUPolicyLearner()
 {
     _cudaManager = Provider.CudaManagerPool.GetCudaManagerForThread(Provider.Logger);
 }
Exemplo n.º 9
0
 private static void GetVectorFromDevice_ThreadRun()
 {
     CudaManager.CallMethod(GetVectorFromDevice);
     //releasing main thread
     autoResetEvent.Set();
 }
Exemplo n.º 10
0
 private static void ChangeVectorOnDevice_ThreadRun()
 {
     CudaManager.CallMethod(ChangeVectorOnDevice);
     //releasing main thread
     autoResetEvent.Set();
 }