Ejemplo n.º 1
0
        public LinkedList <CRFLabelling> CreateNextGeneration(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> chosenVertex,
                                                              CRFLabelling oldCombination)
        {
            LinkedList <CRFLabelling> newCombinations = new LinkedList <CRFLabelling>();

            for (int counter = 0; counter < NumberLabels; counter++)
            {
                CRFLabelling newCombination = default(CRFLabelling);
                if (counter == NumberLabels - 1)
                {
                    newCombination                = new CRFLabelling();
                    newCombination.Score          = oldCombination.Score;
                    newCombination.AssignedLabels = oldCombination.AssignedLabels;
                }
                else
                {
                    newCombination       = new CRFLabelling(oldCombination);
                    newCombination.Score = oldCombination.Score;
                }
                newCombination.AddScore(chosenVertex, counter);
                newCombinations.AddLast(newCombination);
            }

            return(newCombinations);
        }
Ejemplo n.º 2
0
        public void Do(IList <Combination> Combinations, IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> chosenVertex, LinkedList <IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> > NewInnerVertices, IList <IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> > border)
        {
            bool hasNewInnerVertices  = NewInnerVertices.Count > 0;
            var  validNewCombinations = new Dictionary <long, Combination>();

            foreach (Combination combination in Combinations)
            {
                LinkedList <Combination> newCombinations = CreateNextGeneration(chosenVertex, combination);


                foreach (Combination newCombination in newCombinations)
                {
                    if (!CombinationFilter(newCombination))
                    {
                        continue;
                    }

                    BitArray array = new BitArray(border.Count);
                    byte[]   ar2   = new byte[2];

                    long fp = 0;
                    for (int index = 0; index < border.Count; index++)
                    {
                        fp  = fp << 1;
                        fp += newCombination.Assignment[border[index].GraphId];
                    }
                    newCombination.BorderFingerPrint = fp;

                    //newCombination.BorderFingerPrint = "";
                    //int indexer = 0;
                    //foreach (var node in border)
                    //{
                    //    if (node.Data.IsChosen && node.Data.UnchosenNeighboursTemp > 0)
                    //    {
                    //        newCombination.BorderFingerPrint += newCombination.Assignment[node.Data.Ordinate] > 0 ? "1" : "0";
                    //        indexer++;
                    //    }
                    //}
                    if (validNewCombinations.ContainsKey(fp))
                    {
                        if (newCombination.Score > validNewCombinations[fp].Score)
                        {
                            validNewCombinations[fp] = newCombination;
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        validNewCombinations.Add(fp, newCombination);
                    }
                }
            }

            foreach (var comb in validNewCombinations.Values)
            {
                AnnounceNewCombination.Enter(comb);
            }
        }
Ejemplo n.º 3
0
        public LinkedList <Combination> CreateNextGeneration(IGWNode <ICRFNodeDataBinary, ICRFEdgeDataBinary, ICRFGraphData> chosenVertex,
                                                             Combination oldCombination)
        {
            LinkedList <Combination> newCombinations = new LinkedList <Combination>();

            //for (int counter = 0; counter < PossibleStatesForVertices; counter++)
            {
                Combination newCombination = default(Combination);
                //if (counter == PossibleStatesForVertices - 1)
                {
                    newCombination            = new Combination();
                    newCombination.Score      = oldCombination.Score;
                    newCombination.Assignment = oldCombination.Assignment;
                    //newCombination.AddScore(chosenVertex, 1);
                    newCombinations.AddLast(newCombination);
                }
                //else
                {
                    newCombination       = new Combination(oldCombination);
                    newCombination.Score = oldCombination.Score;
                    //newCombination.AddScore(chosenVertex, 0);
                    newCombinations.AddLast(newCombination);
                    //Buffer.BlockCopy(oldCombination.Assignment, 0, newCombination.Assignment, 0, oldCombination.Assignment.Length * 4);

                    //newCombination = new Combination();
                    //newCombination.Score = oldCombination.Score;
                    //newCombination.Assignment = oldCombination.Assignment.ToArray();
                }
            }

            return(newCombinations);
        }
Ejemplo n.º 4
0
        public void AddScore(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> chosenVertex, int state)
        {
            var addedScore = 0.0;

            Assignment[chosenVertex.GraphId] = state;

            addedScore += chosenVertex.Data.Score(state);
            //Console.WriteLine("Vertex " + chosenVertex.Id + ":  " + chosenVertex.Score(state));
            foreach (var edge in chosenVertex.Edges)
            {
                //var otherVertex = chosenVertex.Neighbour(edge);
                var headData = edge.Head.Data;
                var footData = edge.Foot.Data;
                if (!headData.IsChosen || !footData.IsChosen)
                {
                    continue;
                }

                addedScore += edge.Score(Assignment[edge.Head.GraphId], Assignment[edge.Foot.GraphId]);
            }
            Score         += (addedScore);
            LastAddedScore = (addedScore);
            LastNodeAdded  = chosenVertex;
            //checkState();
        }
Ejemplo n.º 5
0
 public static IGWNode Neighbour(this IGWNode node, IGWEdge edge)
 {
     if (edge.Head.GraphId == node.GraphId)
     {
         return(edge.Foot);
     }
     return(edge.Head);
 }
Ejemplo n.º 6
0
 public override double Score(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> node, int label)
 {
     if (label == Classification && node.Data.Characteristics[Characteristic] >= LowerBoundary && node.Data.Characteristics[Characteristic] <= UpperBoundary)
     {
         return(1);
     }
     return(0);
 }
Ejemplo n.º 7
0
 public override double Score(IGWNode <CRFNodeData, CRFEdgeData, CRFGraphData> node, int label)
 {
     if (node.Data.Characteristics[0] < 0.5 && label == 1)
     {
         return(1);
     }
     return(0);
 }
Ejemplo n.º 8
0
 private void addNode(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> node)
 {
     patchNodes.Add(node);
     border.Add(node);
     nodes.Remove(node);
     // remove outside edges to avoid that one node will be added multiple times
     updateOutsideEdges(outsideEdges, node);
     // inner?
     checkInner(border, inner, outsideEdges);
 }
Ejemplo n.º 9
0
        public static ICRFNodeData convertNodeData(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> arg)
        {
            var newData = new CRFNodeData();

            newData.Scores         = arg.Data.Scores;
            newData.ReferenceLabel = arg.Data.ReferenceLabel;
            newData.Id             = arg.Data.Id;

            return(newData);
        }
Ejemplo n.º 10
0
        public static ICRFNodeData IGWNodeDataConvert(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> node)
        {
            var newData = new CRFNodeData();

            newData.Id          = node.Data.Id;
            newData.Scores      = node.Data.Scores;
            newData.Observation = node.Data.Observation;

            return(newData);
        }
Ejemplo n.º 11
0
 public override double Score(IGWNode <RASACRFNodeData, RASACRFEdgeData, ProteinCRFGraphData> node, int label)
 {
     if (label == Label)
     {
         if (node.Data.RASA > LowerBoundary && node.Data.RASA <= UpperBoundary)
         {
             return(1.0);
         }
     }
     return(0.0);
 }
Ejemplo n.º 12
0
        public static SGLNodeData SGLNodeDataConvert(IGWNode <SGLNodeData, SGLEdgeData, SGLGraphData> node)
        {
            var newData = new SGLNodeData();

            newData.Id          = node.Data.Id;
            newData.Scores      = node.Data.Scores;
            newData.Observation = node.Data.Observation;
            newData.Category    = node.Data.Category;

            return(newData);
        }
Ejemplo n.º 13
0
        public static CGNodeData CGNodeDataConvert(IGWNode <CGNodeData, CGEdgeData, CGGraphData> node)
        {
            var newData = new CGNodeData();

            newData.Category              = node.Data.Category;
            newData.NumberNodes           = node.Data.NumberNodes;
            newData.NumberEdges           = node.Data.NumberEdges;
            newData.ObservationProbabilty = node.Data.ObservationProbabilty;
            //newData.Nodes = node.Data.Nodes;
            //newData.InterEdges = node.Data.InterEdges;
            return(newData);
        }
Ejemplo n.º 14
0
 public override double Score(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> node, int label)
 {
     if (label == Label)
     {
         // Characteristics[0] contains Zellner Score
         if (node.Data.Characteristics[0] > LowerBoundary && node.Data.Characteristics[0] <= UpperBoundary)
         {
             return(1.0);
         }
     }
     return(0.0);
 }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public void Do(IList <CRFLabelling> Combinations, IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> chosenVertex, LinkedList <IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> > NewInnerVertices, IList <IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> > border)
        {
            bool hasNewInnerVertices  = NewInnerVertices.Count > 0;
            var  validNewCombinations = new Dictionary <long, CRFLabelling>();

            foreach (CRFLabelling combination in Combinations)
            {
                LinkedList <CRFLabelling> newCombinations = CreateNextGeneration(chosenVertex, combination);


                foreach (CRFLabelling newCombination in newCombinations)
                {
                    if (!CombinationFilter(newCombination))
                    {
                        continue;
                    }

                    BitArray array = new BitArray(border.Count);
                    byte[]   ar2   = new byte[2];

                    long fp = 0;
                    for (int index = 0; index < border.Count; index++)
                    {
                        fp  = fp << 1;
                        fp += newCombination.AssignedLabels[border[index].GraphId];
                    }
                    newCombination.BorderFingerPrint = fp;

                    if (validNewCombinations.ContainsKey(fp))
                    {
                        if (newCombination.Score > validNewCombinations[fp].Score)
                        {
                            validNewCombinations[fp] = newCombination;
                        }
                    }
                    else
                    {
                        validNewCombinations.Add(fp, newCombination);
                    }
                }
            }

            foreach (var comb in validNewCombinations.Values)
            {
                AnnounceNewCombination.Enter(comb);
            }
        }
Ejemplo n.º 17
0
        public void AddScore(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> chosenVertex, int state)
        {
            var addedScore = 0.0;

            AssignedLabels[chosenVertex.GraphId] = state;

            addedScore += chosenVertex.Data.Score(state);
            foreach (var edge in chosenVertex.Edges)
            {
                var headData = edge.Head.Data;
                var footData = edge.Foot.Data;
                if (!headData.IsChosen || !footData.IsChosen)
                {
                    continue;
                }

                addedScore += edge.Score(AssignedLabels[edge.Head.GraphId], AssignedLabels[edge.Foot.GraphId]);
            }
            Score         += (addedScore);
            LastAddedScore = (addedScore);
            LastNodeAdded  = chosenVertex;
        }
Ejemplo n.º 18
0
 public MinBorderActionData(MinBorderPositionData position, IGWNode node, MinBorderOperations operation)
 {
     Node      = node;
     Operation = operation;
 }
Ejemplo n.º 19
0
 public static IGWNode <NodeData, EdgeData, GraphData> Neighbour <NodeData, EdgeData, GraphData>(this IGWNode <NodeData, EdgeData, GraphData> node, IGWEdge <NodeData, EdgeData, GraphData> edge)
 {
     if (edge.Head.GraphId == node.GraphId)
     {
         return(edge.Foot);
     }
     return(edge.Head);
 }
Ejemplo n.º 20
0
 public void Do(IList <Combination> Combinations, IGWNode <ICRFNodeDataBinary, ICRFEdgeDataBinary, ICRFGraphData> chosenVertex, LinkedList <IGWNode <ICRFNodeDataBinary, ICRFEdgeDataBinary, ICRFGraphData> > NewInnerVertices, Func <Combination, bool> combinationFilter, IList <IGWNode <ICRFNodeDataBinary, ICRFEdgeDataBinary, ICRFGraphData> > border)
 {
     CombinationFilter = combinationFilter;
     Do(Combinations, chosenVertex, NewInnerVertices, border);
 }
Ejemplo n.º 21
0
        private LinkedList <IGWNode <ICRFNodeDataBinary, ICRFEdgeDataBinary, ICRFGraphData> > ComputeNewBoundaryVertices(IGWNode <ICRFNodeDataBinary, ICRFEdgeDataBinary, ICRFGraphData> chosenVertex)
        {
            var NewInnerVertices = new LinkedList <IGWNode <ICRFNodeDataBinary, ICRFEdgeDataBinary, ICRFGraphData> >();

            foreach (var edge in chosenVertex.Edges)
            {
                var otherVertex = chosenVertex.Neighbour(edge);
                //if (otherVertex.IsChosen)
                //    continue;
                otherVertex.Data.UnchosenNeighboursTemp--;
                if (otherVertex.Data.UnchosenNeighboursTemp == 0)
                {
                    BoundaryVertices.Remove(otherVertex);
                    NewInnerVertices.AddLast(otherVertex);
                }
            }

            if (chosenVertex.Data.UnchosenNeighboursTemp > 0)
            {
                BoundaryVertices.Add(chosenVertex);
            }
            else
            {
                NewInnerVertices.AddLast(chosenVertex);
            }



            return(NewInnerVertices);
        }
Ejemplo n.º 22
0
 public abstract double Score(IGWNode <NodeData, EdgeData, GraphData> node, int label);
Ejemplo n.º 23
0
 private void updateOutsideEdges(List <IGWEdge <ICRFNodeData, ICRFEdgeData, ICRFGraphData> >[] outsideEdges, IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> node)
 {
     foreach (IGWEdge <ICRFNodeData, ICRFEdgeData, ICRFGraphData> edge in node.Edges)
     {
         outsideEdges[node.Neighbour(edge).GraphId].Remove(edge);
     }
 }
Ejemplo n.º 24
0
 public override double Score(IGWNode <RASACRFNodeData, RASACRFEdgeData, ProteinCRFGraphData> node, int label)
 {
     return(0.0);
 }
Ejemplo n.º 25
0
 public override double Score(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> node, int label)
 {
     return(0.0);
 }
Ejemplo n.º 26
0
 public override double Score(IGWNode <ICRFNodeData, ICRFEdgeData, ICRFGraphData> node, int label)
 {
     //+1 oder -1
     return(node.Data.Observation == label ? 1 : -1);
 }