コード例 #1
0
        private void SanityCheckCumulativeFrequencies()
        {
            GPUDecisionLearnerContext context = Context.ContextBuffer.Read()[0];

            GPUAttributeDataPoint[] attributePoints   = _sortedDataPointsPerAxis.Read();
            float[] cumulativeFrequenciesPerAxisArray = _cumulativeFrequenciesPerAxis.Read();
            for (int openNodeIndex = 0; openNodeIndex < context.NumOpenNodes; ++openNodeIndex)
            {
                int nodeId = Context.OpenNodeIds[openNodeIndex];
                if (nodeId == -1)
                {
                    continue;
                }

                GPUNode node = Context.Nodes[nodeId];
                for (int axisId = 0; axisId < Context.NumAttributeAxes; ++axisId)
                {
                    double[] cumulativeFrequencies = new double[GPUConstants.MaxClasses];
                    for (int i = 0; i < node.RangeLength; ++i)
                    {
                        int index = node.RangeStart + i;
                        GPUAttributeDataPoint attributePoint = attributePoints[axisId * Context.DataPoints.Count + index];
                        cumulativeFrequencies[attributePoint.Class] += attributePoint.Weight;
                        for (int classId = 0; classId < GPUConstants.MaxClasses; ++classId)
                        {
                            double cumulativeFrequency = cumulativeFrequenciesPerAxisArray[
                                axisId * Context.DataPoints.Count * GPUConstants.MaxClasses +
                                index * GPUConstants.MaxClasses +
                                classId];
                            Assert.AreEqual(cumulativeFrequencies[classId], cumulativeFrequency, 1.0);
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void SanityCheckSplit(CudaArray <GPUSplit> bestSplits)
        {
            GPUSplit[] bestSplitsArray        = bestSplits.Read();
            GPUDecisionLearnerContext context = Context.ContextBuffer.Read()[0];

            int[] dataPointIds = Context.DataPointIds.Read();
            for (int openNodeIndex = 0; openNodeIndex < context.NumOpenNodes; ++openNodeIndex)
            {
                int nodeId = Context.OpenNodeIds[openNodeIndex];
                if (nodeId == -1)
                {
                    continue;
                }

                GPUSplit bestSplit = bestSplitsArray[openNodeIndex];
                if (bestSplit.SplitType != GPUConstants.SplitType_Categorical)
                {
                    continue;
                }

                GPUNode parentNode = Context.Nodes[nodeId];
                GPUNode leftNode   = Context.Nodes[parentNode.LeftChild];
                GPUNode rightNode  = Context.Nodes[parentNode.RightChild];
                Assert.AreEqual(parentNode.RangeStart, leftNode.RangeStart);
                Assert.AreEqual(leftNode.RangeStart + leftNode.RangeLength, rightNode.RangeStart);
                Assert.AreEqual(parentNode.RangeLength, leftNode.RangeLength + rightNode.RangeLength);

                for (int i = 0; i < parentNode.RangeLength; ++i)
                {
                    int        index     = parentNode.RangeStart + i;
                    IDataPoint dataPoint = Context.DataPoints[dataPointIds[index]];
                    bool       goRight   = (dataPoint.Categories[bestSplit.Axis] & bestSplit.SplitCategories) != 0;
                    if (goRight)
                    {
                        Assert.IsTrue(rightNode.RangeStart <= index && index <= rightNode.RangeStart + rightNode.RangeLength);
                    }
                    else
                    {
                        Assert.IsTrue(leftNode.RangeStart <= index && index <= leftNode.RangeStart + leftNode.RangeLength);
                    }
                }
            }
        }