Esempio n. 1
0
        private double DetermineBarrier(List <CRFLabelling> Combinations, IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> vertex, bool needBarrier, int MaximalCombinationsUnderConsideration, int RunsToDetermineBarrier)
        {
            if (!needBarrier)
            {
                return(double.MinValue);
            }

            var surviveRatio = ((double)MaximalCombinationsUnderConsideration) / (Combinations.Count * NumberLabels);

            if (surviveRatio >= 1.0)
            {
                return(double.MinValue);
            }

            var sample = Combinations.RandomTake(RunsToDetermineBarrier, Random).ToList();

            double barrier     = 0.0;
            int    sampleCount = sample.Count;

            int survivors = (int)(surviveRatio * sampleCount) + 1;
            LinkedList <double> Scores = new LinkedList <double>();

            Random rand = new Random();

            var scoringEdges = vertex.Edges.Where(e => vertex.Neighbour(e).Data.IsChosen).ToList();

            foreach (var item in sample)
            {
                int label = Random.Next(NumberLabels);
                var score = item.Score + vertex.Data.Score(label);
                foreach (var edge in scoringEdges)
                {
                    if (edge.Foot.Equals(vertex))
                    {
                        score += edge.Score(item.AssignedLabels[edge.Head.GraphId], label);
                    }
                    else
                    {
                        score += edge.Score(label, item.AssignedLabels[edge.Foot.GraphId]);
                    }
                }
                LinkedListHandler.SortedInsert(Scores, score, survivors);
            }
            barrier = (Scores.Last.Value + Scores.Last.Previous.Value) / 2.0;

            return(barrier);
        }
Esempio n. 2
0
        public double Do(IList <T> Sample, Func <T, double> scoringFunction, double desiredSurvivorRate)
        {
            double barrier     = 0.0;
            int    sampleCount = Sample.Count;

            int survivors = (int)(desiredSurvivorRate * sampleCount);
            LinkedList <double> Scores = new LinkedList <double>();

            Random rand = new Random();

            foreach (var item in Sample)
            {
                LinkedListHandler.SortedInsert(Scores, scoringFunction(item), survivors);
            }
            barrier = Scores.Last.Value;

            return(barrier);
        }
        private double DetermineBarrierStep2(List <Combination> Combinations, int MaximalCombinationsUnderConsideration, int RunsToDetermineBarrier)
        {
            var surviveRatio = ((double)MaximalCombinationsUnderConsideration) / (Combinations.Count);

            var sample = Combinations.RandomTake(RunsToDetermineBarrier, Random).ToList();

            double barrier     = 0.0;
            int    sampleCount = sample.Count;

            int survivors = (int)(surviveRatio * sampleCount) + 1;
            LinkedList <double> Scores = new LinkedList <double>();

            Random rand = new Random();


            foreach (var item in sample)
            {
                LinkedListHandler.SortedInsert(Scores, item.Score, survivors);
            }
            barrier = (Scores.Last.Value + Scores.Last.Previous.Value) / 2.0;

            return(barrier);
        }