Пример #1
0
        public NNResult GetNearestNodes(float[] sample)
        {
            DataTable dt = GetDataTable();

            double[,] results = NearestNeighbour.GetTwoNearestNeighbours(metric, numThreads, this.insertNodeCount, dt.NumDimensions, sample, dt.GetData());

            int first_index  = (int)results[0, 1];
            int second_index = (int)results[1, 1];

            NNResult nnresult = new NNResult();

            nnresult.nearestNeighbour0 = (GraphNode)dt.GetDataObject(first_index);
            nnresult.distance0         = results[0, 0];
            nnresult.index0            = first_index;

            nnresult.nearestNeightbour1 = (GraphNode)dt.GetDataObject(second_index);
            nnresult.distance1          = results[1, 0];
            nnresult.index1             = second_index;

            return(nnresult);
        }
Пример #2
0
        public static List <int[]> PredictSamples(List <float[]> samples, List <int[]> nodeClusterIndex, List <float[]> positionsList, int maxThreads = 2, int metric = 1)
        {
            var datapointClusterIndex = new List <int[]>(samples.Count);

            int numDims = positionsList[0].Length;

            DataTable dt = new DataTable(numDims, positionsList);

            float[][] positionsData = dt.GetData();

            for (int sampleIndex = 0; sampleIndex < samples.Count; sampleIndex++)
            {
                float[] sample = samples[sampleIndex];
                double[,] nnResults = NearestNeighbour.GetTwoNearestNeighbours(metric, maxThreads, positionsList.Count, numDims, sample, positionsData);
                int firstNearestNeighbourNodeIndex = (int)nnResults[0, 1];
                int clusterIndex = nodeClusterIndex[firstNearestNeighbourNodeIndex][1];
                //datapointClusterIndex[sampleIndex] = new int[] { sampleIndex, clusterIndex };
                int[] row = new int[] { sampleIndex, clusterIndex };
                datapointClusterIndex.Add(row);
            }

            return(datapointClusterIndex);
        }