Exemplo n.º 1
0
        /// <summary>
        /// Create a list of items where the last item loops back
        /// to one of the previous item in the list
        /// </summary>
        /// <param name="count"></param>
        /// <param name="nItemToLoopBackto">the previous nth item to be looped back to by the last item.</param>
        /// <returns></returns>
        static public LinkedListItem CreateLoopBackItems(int count, int nItemToLoopBackto)
        {
            if (count < 1)
            {
                throw new ArgumentException("count must be greater than 0");
            }
            if (nItemToLoopBackto > count)
            {
                throw new ArgumentException("nItemToLoopBackto must be less than count");
            }

            var head = CreateItems(count);

            var handler = new LinkedListHandler(head);

            var last  = handler.GetLastItem();
            var nItem = handler.GetNthItem(nItemToLoopBackto);

            handler.Clear();

            // create loop back
            last.Next = nItem;

            return(head);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="length"></param>
        /// <param name="nItem">first item = 1</param>
        static void Clone_LoopBack_List_Test(int length, int nItem)
        {
            var item = Helper.CreateLoopBackItems(length, nItem);

            var clonedItem = (LinkedListItem)DeepClone.Clone(item);

            var originalHandler = new LinkedListHandler(item);
            var clonedHandler   = new LinkedListHandler(clonedItem);

            var isUnique = originalHandler.IsUnique(clonedHandler);
            var areEqual = originalHandler.AreEqual(clonedHandler);

            var s = $"Cloning Loopback list - (length={length}, loopback Item={nItem})...is unique? = {isUnique}, are equal? = {areEqual}";

            Console.WriteLine(s);
            Console.WriteLine();
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        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);
        }