private void RecalculateInternalDataset() { if (sharedFixedVariables == null) { return; } var factorValues = new List <string>(variableValues); var variables = sharedFixedVariables.VariableNames.ToList(); var values = new List <IList>(); foreach (var varName in variables) { if (varName == FreeVariable) { values.Add(factorValues); } else if (sharedFixedVariables.VariableHasType <double>(varName)) { values.Add(Enumerable.Repeat(sharedFixedVariables.GetDoubleValue(varName, 0), factorValues.Count).ToList()); } else if (sharedFixedVariables.VariableHasType <string>(varName)) { values.Add(Enumerable.Repeat(sharedFixedVariables.GetStringValue(varName, 0), factorValues.Count).ToList()); } } internalDataset = new ModifiableDataset(variables, values); }
private void RecalculateInternalDataset() { if (sharedFixedVariables == null) { return; } // we expand the range in order to get nice tick intervals on the x axis double xmin, xmax, xinterval; ChartUtil.CalculateAxisInterval(trainingMin, trainingMax, XAxisTicks, out xmin, out xmax, out xinterval); if (FixedXAxisMin.HasValue) { xmin = FixedXAxisMin.Value; } if (FixedXAxisMax.HasValue) { xmax = FixedXAxisMax.Value; } double step = (xmax - xmin) / drawingSteps; var xvalues = new List <double>(); for (int i = 0; i < drawingSteps; i++) { xvalues.Add(xmin + i * step); } var variables = sharedFixedVariables.DoubleVariables.ToList(); internalDataset = new ModifiableDataset(variables, variables.Select(x => x == FreeVariable ? xvalues : Enumerable.Repeat(sharedFixedVariables.GetDoubleValue(x, 0), xvalues.Count).ToList() ) ); }
private void RecalculateInternalDataset() { if (sharedFixedVariables == null) { return; } // we expand the range in order to get nice tick intervals on the x axis double xmin, xmax, xinterval; //guard if only one distinct value is present if (trainingMin.IsAlmost(trainingMax)) { ChartUtil.CalculateAxisInterval(trainingMin - 0.5, trainingMin + 0.5, XAxisTicks, out xmin, out xmax, out xinterval); } else { ChartUtil.CalculateAxisInterval(trainingMin, trainingMax, XAxisTicks, out xmin, out xmax, out xinterval); } if (FixedXAxisMin.HasValue) { xmin = FixedXAxisMin.Value; } if (FixedXAxisMax.HasValue) { xmax = FixedXAxisMax.Value; } double step = (xmax - xmin) / drawingSteps; var xvalues = new List <double>(); for (int i = 0; i < drawingSteps; i++) { xvalues.Add(xmin + i * step); } if (sharedFixedVariables == null) { return; } var variables = sharedFixedVariables.VariableNames.ToList(); var values = new List <IList>(); foreach (var varName in variables) { if (varName == FreeVariable) { values.Add(xvalues); } else if (sharedFixedVariables.VariableHasType <double>(varName)) { values.Add(Enumerable.Repeat(sharedFixedVariables.GetDoubleValue(varName, 0), xvalues.Count).ToList()); } else if (sharedFixedVariables.VariableHasType <string>(varName)) { values.Add(Enumerable.Repeat(sharedFixedVariables.GetStringValue(varName, 0), xvalues.Count).ToList()); } } internalDataset = new ModifiableDataset(variables, values); }
public void Configure(IEnumerable <IRegressionSolution> solutions, ModifiableDataset sharedFixedVariables, string freeVariable, int drawingSteps, bool initializeAxisRanges = true) { if (!SolutionsCompatible(solutions)) { throw new ArgumentException("Solutions are not compatible with the problem data."); } this.freeVariable = freeVariable; this.drawingSteps = drawingSteps; this.solutions.Clear(); this.solutions.AddRange(solutions); // add an event such that whenever a value is changed in the shared dataset, // this change is reflected in the internal dataset (where the value becomes a whole column) if (this.sharedFixedVariables != null) { this.sharedFixedVariables.ItemChanged -= sharedFixedVariables_ItemChanged; this.sharedFixedVariables.Reset -= sharedFixedVariables_Reset; } this.sharedFixedVariables = sharedFixedVariables; this.sharedFixedVariables.ItemChanged += sharedFixedVariables_ItemChanged; this.sharedFixedVariables.Reset += sharedFixedVariables_Reset; RecalculateTrainingLimits(initializeAxisRanges); RecalculateInternalDataset(); chart.Series.Clear(); seriesCache.Clear(); ciSeriesCache.Clear(); foreach (var solution in this.solutions) { var series = CreateSeries(solution); seriesCache.Add(solution, series.Item1); if (series.Item2 != null) { ciSeriesCache.Add(solution, series.Item2); } } // Set cursor and x-axis // Make sure to allow a small offset to be able to distinguish the vertical line annotation from the axis var defaultValue = sharedFixedVariables.GetDoubleValue(freeVariable, 0); var step = (trainingMax - trainingMin) / drawingSteps; var minimum = chart.ChartAreas[0].AxisX.Minimum; var maximum = chart.ChartAreas[0].AxisX.Maximum; if (defaultValue <= minimum) { VerticalLineAnnotation.X = minimum + step; } else if (defaultValue >= maximum) { VerticalLineAnnotation.X = maximum - step; } else { VerticalLineAnnotation.X = defaultValue; } if (ShowCursor) { chart.Titles[0].Text = FreeVariable + " : " + defaultValue.ToString("G5", CultureInfo.CurrentCulture); } ResizeAllSeriesData(); OrderAndColorSeries(); }
public void Configure(IEnumerable<IRegressionSolution> solutions, ModifiableDataset sharedFixedVariables, string freeVariable, int drawingSteps, bool initializeAxisRanges = true) { if (!SolutionsCompatible(solutions)) throw new ArgumentException("Solutions are not compatible with the problem data."); this.freeVariable = freeVariable; this.drawingSteps = drawingSteps; this.solutions.Clear(); this.solutions.AddRange(solutions); // add an event such that whenever a value is changed in the shared dataset, // this change is reflected in the internal dataset (where the value becomes a whole column) if (this.sharedFixedVariables != null) this.sharedFixedVariables.ItemChanged -= sharedFixedVariables_ItemChanged; this.sharedFixedVariables = sharedFixedVariables; this.sharedFixedVariables.ItemChanged += sharedFixedVariables_ItemChanged; RecalculateTrainingLimits(initializeAxisRanges); RecalculateInternalDataset(); chart.Series.Clear(); seriesCache.Clear(); ciSeriesCache.Clear(); foreach (var solution in this.solutions) { var series = CreateSeries(solution); seriesCache.Add(solution, series.Item1); if (series.Item2 != null) ciSeriesCache.Add(solution, series.Item2); } // Set cursor and x-axis // Make sure to allow a small offset to be able to distinguish the vertical line annotation from the axis var defaultValue = sharedFixedVariables.GetDoubleValue(freeVariable, 0); var step = (trainingMax - trainingMin) / drawingSteps; var minimum = chart.ChartAreas[0].AxisX.Minimum; var maximum = chart.ChartAreas[0].AxisX.Maximum; if (defaultValue <= minimum) VerticalLineAnnotation.X = minimum + step; else if (defaultValue >= maximum) VerticalLineAnnotation.X = maximum - step; else VerticalLineAnnotation.X = defaultValue; if (ShowCursor) chart.Titles[0].Text = FreeVariable + " : " + defaultValue.ToString("N3", CultureInfo.CurrentCulture); ResizeAllSeriesData(); OrderAndColorSeries(); }