private void CreateNewBeliefDataSet(Dict <string, EvidenceTable> mergedDataSet) { if (this.BeliefsData.Count == 0 || this.BeliefsData[this.BeliefsData[0].Key].Count < mergedDataSet.Values[0].Count) { var evidenceDateTime = mergedDataSet.Values[0].DateTimes; var noOfEvidenceRows = mergedDataSet.Values[0].Count; this.BeliefsData = new Dict <string, EvidenceTable>(); foreach (var vertex in this.Network.Vertices) { var beliefTable = new EvidenceTable(evidenceDateTime); var i = 0; while (i < noOfEvidenceRows) { var beliefRow = new EvidenceRow { From = mergedDataSet[0].Value[i].From, To = mergedDataSet[0].Value[i].To }; beliefTable.Add(beliefRow); i++; } this.BeliefsData.Add(vertex.Key, beliefTable); } } }
public CellEditCommand(EvidenceRow row, string colName, Vertex selVertex, object newData, object oldData) { this.Row = row; this.ColumnName = colName; this.SelectedVertex = selVertex; this.NewData = newData; this.OldData = oldData; }
private static bool Contains(this Dict <string, EvidenceTable> evidenceSet, EvidenceRow evidenceRow) { var values = new ObservableCollection <EvidenceTable>(); foreach (var kvp in evidenceSet) { values.Add(kvp.Value); } return(values.Any(table => table.Any(row => row.From == evidenceRow.From && row.To == evidenceRow.To))); }
private Dict <string, EvidenceTable> CaptureInterpolatedData(Dict <string, EvidenceTable> mergedDataSet) { var interpolatedData = new Dict <string, EvidenceTable>(); //if (this.SelectedInterpolationData == null) //{ // return interpolatedData; //} foreach (var kvp in this.PipeLineData.UserDataObj) { var interpolatedTable = new EvidenceTable(this.dates); interpolatedData.Add(kvp.Key, interpolatedTable); foreach (var column in kvp.Value.InterpolatedNodeData) { if (column.Value.Points == null) { continue; } this.SelectedInterpolationData = column.Value; if (interpolatedTable.Count == 0) { foreach (var mergedEvidenceRow in mergedDataSet.Values[0]) { var interpolatedRow = new EvidenceRow { From = mergedEvidenceRow.From, To = mergedEvidenceRow.To }; interpolatedTable.Add(interpolatedRow); } } // interpolatedData.Add(kvp.Key, interpolatedTable); foreach (var interpolatedRow in interpolatedTable) { var midRangeValue = (interpolatedRow.From + interpolatedRow.To) / 2; var evidenceString = this.SelectedInterpolationData.GetEvidenceString(midRangeValue, this.VerticalAxis.Equals(LinearAxis)?VertexAxisType.Linear: VertexAxisType.Logarithmic); interpolatedRow[column.Key] = this.Network.Vertices[kvp.Key].States.ParseEvidenceString(evidenceString); } } Console.WriteLine(); } return(interpolatedData); }
public bool Contains(EvidenceRow other) { if (!other.From.Equals(other.To)) { return(this.From <= other.From && other.To <= this.To); } // Ex: section such as 0-12/12-24 should not be picked up for point value 12-12 var pointValue = other.From; if (this.From.Equals(pointValue) || this.To.Equals(pointValue)) { return(this.From.Equals(other.From) && this.To.Equals(other.To)); } return(this.From <= other.From && other.To <= this.To); }
public static void AddRangeAnnotation(this RadCartesianChart chart, EvidenceRow dataRow, string columnName) { var from = (double)dataRow["From"]; var to = (double)dataRow["To"]; var vertexEvidence = dataRow[columnName] as VertexEvidence; chart.Annotations.Add(new CartesianMarkedZoneAnnotation { Fill = new SolidColorBrush(Colors.Goldenrod), HorizontalFrom = @from, HorizontalTo = to, Stroke = new SolidColorBrush(Colors.Goldenrod), Tag = dataRow, VerticalFrom = vertexEvidence.Params[0], VerticalTo = vertexEvidence.Params[1], ZIndex = -200, }); }
public static void UpdateCommentBlocks(this RadCartesianChart chart, EvidenceRow row, NumericalAxis verticalAxis) { var fillBrush = new SolidColorBrush(Color.FromRgb(236, 236, 236)); var strokeBrush = new SolidColorBrush(Colors.LightGray); var from = (double)row["From"]; var to = (double)row["To"]; var comment = (string)row["Comment"]; chart.Annotations.Remove(annotation => ReferenceEquals(annotation.Tag, row)); if (from == to) { chart.Annotations.Add(new CartesianCustomLineAnnotation { HorizontalFrom = @from, HorizontalTo = to, Stroke = strokeBrush, StrokeThickness = 2, Tag = row, VerticalFrom = verticalAxis.Minimum, VerticalTo = verticalAxis.Maximum, ZIndex = -500 }); } else { chart.Annotations.Add(new CartesianMarkedZoneAnnotation { Fill = fillBrush, HorizontalFrom = @from, HorizontalTo = to, Stroke = strokeBrush, Tag = row, VerticalFrom = verticalAxis.Minimum, VerticalTo = verticalAxis.Maximum, ZIndex = -500 }); } }
public static void AddLineAnnotation(this RadCartesianChart chart, EvidenceRow dataRow, string columnName) { var from = (double)dataRow["From"]; var to = (double)dataRow["To"]; var vertexEvidence = dataRow[columnName] as VertexEvidence; var verticalValue = vertexEvidence.Type == VertexEvidenceType.Number ? vertexEvidence.Params[0] : vertexEvidence.Params[vertexEvidence.Value.IndexOf(val => val == 1)]; chart.Annotations.Add(new CartesianCustomLineAnnotation { HorizontalFrom = @from, HorizontalTo = to, Stroke = new SolidColorBrush(Colors.Goldenrod), StrokeThickness = 2, Tag = dataRow, VerticalFrom = verticalValue, VerticalTo = verticalValue, ZIndex = -200 }); }
public static Dict <string, EvidenceTable> Merge(Dict <string, NodeData> userDataObj, List <double> baseRowsList, Network network) { var unmergedEvidenceSet = new Dict <string, EvidenceTable>(); var mergedEvidenceSet = new Dict <string, EvidenceTable>(); var newList = new List <double>(); if (baseRowsList != null) { newList = baseRowsList.ToList(); } foreach (var kvp in userDataObj) { foreach (var row in kvp.Value.UserTable) { var colNames = row.GetDynamicMemberNames().ToList(); foreach (var colName in colNames) { if (row[colName] == "") { row[colName] = new VertexEvidence { Type = VertexEvidenceType.Null }; } } } } // Remove Empty EvidenceTables var deleteNodes = new List <string>(); foreach (var kvp in userDataObj) { if (!kvp.Value.UserTable.Any()) { deleteNodes.Add(kvp.Key); } else { var isEmpty = true; foreach (var row in kvp.Value.UserTable) { foreach (var colName in row.GetDynamicMemberNames().ToList()) { if ((row[colName] as VertexEvidence).Type != VertexEvidenceType.Null) { isEmpty = false; } if ((row[colName] as VertexEvidence).Type == VertexEvidenceType.Invalid) { row[colName] = new VertexEvidence { Type = VertexEvidenceType.Null }; } } } if (isEmpty) { deleteNodes.Add(kvp.Key); } } } foreach (var key in deleteNodes) { userDataObj.Remove(key); } foreach (var kvp in userDataObj) { unmergedEvidenceSet.Add(kvp.Key, kvp.Value.UserTable); } // Generate a list which holds the modified section ranges foreach (var kvp in unmergedEvidenceSet) { var evidenceTable = kvp.Value; foreach (var evidenceRow in evidenceTable) { newList.Add(evidenceRow.From); newList.Add(evidenceRow.To); } } newList.Sort(); // sorting the new list foreach (var kvp in unmergedEvidenceSet) { var unmergeEvidenceTableKey = kvp.Key; var unmergedEvidenceTable = kvp.Value; if (unmergedEvidenceTable.Count == 0) { continue; } var mergedEvidenceTable = new EvidenceTable(unmergedEvidenceTable.DateTimes); for (var i = 0; i < newList.Count - 1; i++) { var evidenceRow = new EvidenceRow { From = newList[i], To = newList[i + 1] }; // If this is a point feature and no table contains it, then don't add. if (!unmergedEvidenceSet.Contains(evidenceRow) && newList[i] == newList[i + 1]) { continue; } // multiple inputs for a single point feature are allowed if (unmergedEvidenceSet.Contains(evidenceRow) && newList[i] == newList[i + 1]) { mergedEvidenceTable.Add(evidenceRow); } else { mergedEvidenceTable.AddUnique(evidenceRow); } } EvidenceRow uniqueRow = null; var deleteRows = new ObservableCollection <EvidenceRow>(); foreach (var mergedEvidenceRow in mergedEvidenceTable) { if (uniqueRow == null) { uniqueRow = mergedEvidenceRow; continue; } if (mergedEvidenceRow.From == uniqueRow.From && mergedEvidenceRow.To == uniqueRow.To) { deleteRows.Add(mergedEvidenceRow); } else { uniqueRow = mergedEvidenceRow; } } mergedEvidenceTable.Remove(deleteRows); foreach (var mergedEvidenceRow in mergedEvidenceTable) { var unmergedEvidenceRows = unmergedEvidenceTable.Where(row => row.Contains(mergedEvidenceRow)).ToList(); var columnNames = mergedEvidenceRow.GetDynamicMemberNames().ToList(); if (unmergedEvidenceRows.Count() > 1) // merged section has multiple input values { var avgEvidenceValues = GetEvidenceAverage(unmergedEvidenceRows, network.Vertices[unmergeEvidenceTableKey].States.Count()); foreach (var columnName in columnNames) { var evidenceString = avgEvidenceValues[columnName].ValueToDistribution(); mergedEvidenceRow[columnName] = network.Vertices[unmergeEvidenceTableKey].States.ParseEvidenceString(evidenceString); } } else { foreach (var columnName in columnNames) { mergedEvidenceRow[columnName] = !unmergedEvidenceRows.Any() ? new VertexEvidence { Type = VertexEvidenceType.Null } : unmergedEvidenceRows.FirstOrDefault()[columnName]; } } } mergedEvidenceSet.Add(unmergeEvidenceTableKey, mergedEvidenceTable); } return(mergedEvidenceSet); }
public static void AddInterpolatedDistributionAnnotation(this RadCartesianChart chart, Vertex selectedVertex, EvidenceRow dataRow, string columnName) { var from = (double)dataRow["From"]; var to = (double)dataRow["To"]; var vertexEvidence = dataRow[columnName] as VertexEvidence; foreach (var state in selectedVertex.States) { var stateIndex = selectedVertex.States.IndexOf(state); var gammaAdjustedValue = Math.Pow(vertexEvidence.Value[stateIndex], 0.7); chart.Annotations.Add(new CartesianMarkedZoneAnnotation { Fill = new SolidColorBrush(Color.FromArgb((byte)(gammaAdjustedValue * 255), 218, 165, 32)), HorizontalFrom = @from, HorizontalTo = to, Stroke = new SolidColorBrush(Color.FromArgb((byte)(gammaAdjustedValue * 255), 218, 165, 32)), Tag = dataRow, VerticalFrom = state.SafeMin, VerticalTo = state.SafeMax, ZIndex = -200 }); } }
public static void AddTriangularDistributionAnnotation(this RadCartesianChart chart, Vertex selectedVertex, EvidenceRow dataRow, string columnName) { var from = (double)dataRow["From"]; var to = (double)dataRow["To"]; var vertexEvidence = dataRow[columnName] as VertexEvidence; var fill1 = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = new Point(0, 1) }; fill1.GradientStops.Add(new GradientStop { Offset = 0, Color = Color.FromArgb(255, 218, 165, 32) }); fill1.GradientStops.Add(new GradientStop { Offset = 1, Color = Color.FromArgb(50, 218, 165, 32) }); chart.Annotations.Add(new CartesianMarkedZoneAnnotation { Fill = fill1, HorizontalFrom = @from, HorizontalTo = to, Stroke = new SolidColorBrush(Colors.Goldenrod), Tag = dataRow, VerticalFrom = vertexEvidence.Params[1], VerticalTo = vertexEvidence.Params[0], ZIndex = -200 }); var fill2 = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = new Point(0, 1) }; fill2.GradientStops.Add(new GradientStop { Offset = 0, Color = Color.FromArgb(0, 218, 165, 32) }); fill2.GradientStops.Add(new GradientStop { Offset = 1, Color = Color.FromArgb(255, 218, 165, 32) }); chart.Annotations.Add(new CartesianMarkedZoneAnnotation { Fill = fill2, HorizontalFrom = @from, HorizontalTo = to, Stroke = new SolidColorBrush(Colors.Goldenrod), Tag = dataRow, VerticalFrom = vertexEvidence.Params[2], VerticalTo = vertexEvidence.Params[1], ZIndex = -200 }); }
public static void AddPointAnnotation(this RadCartesianChart chart, EvidenceRow dataRow, string columnName) { var from = (double)dataRow["From"]; var to = (double)dataRow["To"]; var comment = (string)dataRow["Comment"]; var vertexEvidence = dataRow[columnName] as VertexEvidence; var verticalValue = vertexEvidence.Type == VertexEvidenceType.Number ? vertexEvidence.Params[0] : vertexEvidence.Params[vertexEvidence.Value.IndexOf(val => val == 1)]; var commentTextBlock = new TextBlock { Text = comment, Margin = new Thickness(8, 0, 0, 0) }; var ellipse = new Ellipse { Fill = new SolidColorBrush(Colors.Goldenrod), Height = 8, Stroke = new SolidColorBrush(Colors.Goldenrod), Width = 8, }; chart.Annotations.Add(new CartesianCustomAnnotation { Content = ellipse, HorizontalAlignment = HorizontalAlignment.Center, HorizontalValue = (from + to) / 2, Tag = dataRow, VerticalAlignment = VerticalAlignment.Center, VerticalValue = verticalValue, ZIndex = -200 }); if (comment == null || comment.Equals("")) { return; } if (chart.VerticalAxis as LinearAxis == null) { chart.Annotations.Add(new CartesianCustomAnnotation { Content = commentTextBlock, HorizontalAlignment = (from + to) / 2 > 0.9 * (chart.HorizontalAxis as LinearAxis).Maximum ? HorizontalAlignment.Left : HorizontalAlignment.Right, HorizontalValue = (from + to) / 2, Tag = dataRow, VerticalAlignment = verticalValue > 0.9 * (chart.VerticalAxis as LogarithmicAxis).Maximum ? VerticalAlignment.Bottom : VerticalAlignment.Top, VerticalValue = verticalValue, ZIndex = -200 }); } else { chart.Annotations.Add(new CartesianCustomAnnotation { Content = commentTextBlock, HorizontalAlignment = (from + to) / 2 > 0.9 * (chart.HorizontalAxis as LinearAxis).Maximum ? HorizontalAlignment.Left : HorizontalAlignment.Right, HorizontalValue = (from + to) / 2, Tag = dataRow, VerticalAlignment = verticalValue > 0.9 * (chart.VerticalAxis as LinearAxis).Maximum ? VerticalAlignment.Bottom : VerticalAlignment.Top, VerticalValue = verticalValue, ZIndex = -200 }); } }
private void Plot(EvidenceRow dataRow, string columnName) { var fillBrush = new SolidColorBrush(Colors.Goldenrod); var strokeBrush = new SolidColorBrush(Colors.Goldenrod); var from = (double)dataRow["From"]; var to = (double)dataRow["To"]; var vertexEvidence = dataRow[columnName] as VertexEvidence; if (vertexEvidence == null) { this.Chart.Annotations.Remove(annotation => ReferenceEquals(annotation.Tag, dataRow)); return; } if (vertexEvidence.Type == VertexEvidenceType.Invalid) { // MessageBox.Show("Invalid input entered"); dataRow[columnName] = new VertexEvidence { Type = VertexEvidenceType.Null }; return; } // Remove older annotations this.Chart.Annotations.Remove(annotation => ReferenceEquals(annotation.Tag, dataRow)); this.Chart.AddNodeStateLines(this.SelectedVertex, this.PipeLineData.BaseTableMax, this.PipeLineData.BaseTableMin, this.VerticalAxis); if (selectedTheme == DataTheme.User) { if (vertexEvidence.Type == VertexEvidenceType.Number) { if (from == to) { this.Chart.AddPointAnnotation(dataRow, columnName); } else { this.Chart.AddLineAnnotation(dataRow, columnName); } } else if (vertexEvidence.Type == VertexEvidenceType.Range) { this.Chart.AddRangeAnnotation(dataRow, columnName); } else if (vertexEvidence.Type == VertexEvidenceType.State) { if (from == to) { this.Chart.AddPointAnnotation(dataRow, columnName); } else { this.Chart.AddLineAnnotation(dataRow, columnName); } } else if (vertexEvidence.Type == VertexEvidenceType.Triangular) { this.Chart.AddTriangularDistributionAnnotation(this.SelectedVertex, dataRow, columnName); } else if (vertexEvidence.Type != VertexEvidenceType.Null) { this.Chart.AddInterpolatedDistributionAnnotation(this.SelectedVertex, dataRow, columnName); } } else if (vertexEvidence.Type != VertexEvidenceType.Null) { this.Chart.AddInterpolatedDistributionAnnotation(this.SelectedVertex, dataRow, columnName); } }