Exemple #1
0
        private void PopulateTree(double blue, double green, double red, int frequency)
        {
            if (subTreesBlue.Exists(bt => bt.Intensity == blue))
            {
                int indexBlue = subTreesBlue.FindIndex(bt => bt.Intensity == blue);

                // next find if the specific green exists in a subtree of blue
                // such that Gn | Bn

                if (subTreesBlue[indexBlue].subTreesGreen.
                    Exists(gt => gt.Intensity == green))
                {
                    int    indexGreen = subTreesBlue[indexBlue].subTreesGreen.FindIndex(gt => gt.Intensity == green);
                    RedFIP pairRedFI  = new RedFIP();
                    pairRedFI.Intensity = red;
                    pairRedFI.Frequency = frequency;
                    subTreesBlue[indexBlue].subTreesGreen[indexGreen].redNodes.Add(pairRedFI);
                }
                else
                {
                    GreenTree gt = new GreenTree();
                    gt.Intensity = green;
                    RedFIP pairRedFI = new RedFIP();
                    pairRedFI.Intensity = red;
                    pairRedFI.Frequency = frequency;

                    gt.redNodes.Add(pairRedFI);
                    subTreesBlue[indexBlue].subTreesGreen.Add(gt);
                }
            }
            else
            {
                BlueTree  bt        = new BlueTree();
                GreenTree gt        = new GreenTree();
                RedFIP    pairRedFI = new RedFIP();

                pairRedFI.Intensity = red;
                pairRedFI.Frequency = frequency;

                gt.Intensity = green;
                bt.Intensity = blue;

                gt.redNodes.Add(pairRedFI);
                bt.subTreesGreen.Add(gt);
                subTreesBlue.Add(bt);
            }
        }
Exemple #2
0
        public double GetProb(Bgr bgr)
        {
            double result = 0.0;
            double blue   = BringDown(bgr.Blue);
            double green  = BringDown(bgr.Green);
            double red    = BringDown(bgr.Red);

            int blueIndex = BinSearchBlue(blue);

            if (blueIndex < 0)
            {
                return(result);
            }
            else
            {
                int greenIndex = BinSearchGreen(blueIndex, green);

                if (greenIndex < 0)
                {
                    return(result);
                }
                else
                {
                    RedFIP redFIP = subTreesBlue[blueIndex].
                                    subTreesGreen[greenIndex].
                                    redNodes.Find(prfi => prfi.Intensity == red);

                    if (redFIP == null)
                    {
                        return(result);
                    }
                    else
                    {
                        return(redFIP.Probabilty);
                    }
                }
            }
        }