Beispiel #1
0
        virtual public int Compare(Object a, Object b)
        {
            NeighbourCount a1 = (NeighbourCount)a;
            NeighbourCount b1 = (NeighbourCount)b;

            int countDiff = b1.count - a1.count;

            if (0 == countDiff)
            {
                // Sort on Distance
                double distDiff = a1.distance - b1.distance;
                if (distDiff == 0.0)
                {
                    countDiff = 0;
                }
                else if (distDiff > 0)
                {
                    countDiff = 1;
                }
                else
                {
                    countDiff = -1;
                }
            }

            return(countDiff);
        }
Beispiel #2
0
        public Dictionary <int, NeighbourCount> ClosestNeighbours(int count)
        {
            count = Math.Min(count, _distances.Length);

            Dictionary <int, NeighbourCount> accum = new Dictionary <int, NeighbourCount>();

            int i = 0;

            for ( ; i < count; ++i)
            {
                int id = _distances[i].face.GroupId;

                if (accum.ContainsKey(id))
                {
                    NeighbourCount n = accum[id];
                    n.count++;
                    n.distance += _distances[i].Distance;
                    accum[id]   = n;
                }
                else
                {
                    NeighbourCount n = new NeighbourCount();
                    n.count    = 1;
                    n.distance = _distances[i].Distance;
                    accum.Add(id, n);
                }
            }

            return(accum);
        }
Beispiel #3
0
        public NeighbourCount[] CountNeighbours(Dictionary <int, NeighbourCount> accum)
        {
            NeighbourCount[] ret = new NeighbourCount[accum.Count];
            int i = 0;

            foreach (KeyValuePair <int, NeighbourCount> keyVal in accum)
            {
                ret[i].count    = keyVal.Value.count;
                ret[i].id       = keyVal.Key;
                ret[i].distance = keyVal.Value.distance;
                ++i;
            }

            NeighbourCountSorter neighSorter = new NeighbourCountSorter();

            Array.Sort(ret, neighSorter);
            return(ret);
        }
        static void ReportResultComb(int kVal, double rejectThresh, List <TestCollection> testUnLabels, int verbose)
        {
            int winCount = (int)Math.Round(Math.Max(1.0, kVal * rejectThresh));
            Dictionary <int, NeighbourCount> accum = new Dictionary <int, NeighbourCount>();

            for (int iFace = 0; iFace < testUnLabels[0].Faces.Count; ++iFace)
            {
                accum.Clear();
                Face face   = null;
                int  idBest = -1;
                int  agree  = 1;

                foreach (TestCollection testUnlabel in testUnLabels)
                {
                    face = testUnlabel.Faces[iFace];
                    Dictionary <int, NeighbourCount> neigh = face.ClosestNeighbours(kVal);
                    int iid = face.Distances[0].face.GroupId;
                    if (idBest == -1)
                    {
                        idBest = iid;
                    }

                    if (iid != idBest)
                    {
                        agree = 0;
                    }

                    foreach (KeyValuePair <int, NeighbourCount> keyVal in neigh)
                    {
                        if (true == accum.ContainsKey(keyVal.Key))
                        {
                            NeighbourCount n = accum[keyVal.Key];
                            n.count          += keyVal.Value.count;
                            n.distance       += keyVal.Value.distance;
                            accum[keyVal.Key] = n;
                        }
                        else
                        {
                            NeighbourCount n = new NeighbourCount();
                            n.count    = keyVal.Value.count;
                            n.distance = keyVal.Value.distance;
                            accum.Add(keyVal.Key, n);
                        }
                    }
                }


                NeighbourCount[] neighCount = face.CountNeighbours(accum);
                int pred          = (neighCount[0].count >= winCount || agree == 1) ? neighCount[0].id : 0;
                int verboseThresh = 1;

                if (verbose < verboseThresh++)
                {
                    Console.WriteLine("{0} {1} {2}", face.ID, face.GroupId, pred);
                }
                else
                {
                    Console.Write("{0} {1} {2} {3} ", face.ID, face.GroupId, pred, agree);
                    foreach (NeighbourCount n in neighCount)
                    {
                        Console.Write("[ {0} {1} ] ", n.id, n.count);
                    }
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
        }