public void ReplaceRandomItem() { var randomValue = random.Next(1, 10); var randomIndex = random.Next(0, observableValues.Count - 1); observableValues[randomIndex] = new ObservablePoint(observableValues[randomIndex].X, randomValue); }
public DataModel() { this.ChartValues = new ChartValues <ObservablePoint>(); this.XMax = 360; this.XMin = 0; // Initialize the sine graph for (double x = this.XMin; x <= this.XMax; x++) { var point = new ObservablePoint() { X = x, Y = Math.Sin(x * Math.PI / 180) }; this.ChartValues.Add(point); } this.SeriesCollection = new SeriesCollection { new LineSeries { Configuration = new CartesianMapper <ObservablePoint>() .X(point => point.X) .Y(point => point.Y) .Stroke(point => point.Y > 0.3 ? Brushes.Red : Brushes.LightGreen) .Fill(point => point.Y > 0.3 ? Brushes.Red : Brushes.LightGreen), Title = "Sine Graph", Values = this.ChartValues, PointGeometry = null } }; Task.Run(async() => await StartSineGenerator()); }
private double Quadrature(Func <double, double> function, double a, double b, int n) { List <ObservablePoint> points = new List <ObservablePoint>(); double result = 0, x = 0, fx = 0; double h = (b - a) / n; for (int i = 0; i <= n; i++) { x = a + i * h; fx = function(x); var point = new ObservablePoint(x, fx); if (!_Values.Any(val => val.X == x)) { points.Add(point); } if (i == 0 || i == n) { result += fx; } else if (i % 2 != 0) { result += 4 * fx; } else { result += 2 * fx; } } result *= (h / 3); _Values.AddRange(points); _Nodes.Add(new ChartValues <ObservablePoint>(points)); return(result); }
private SeriesCollection ShowStaticNonLinearResults(Results analysisResults) { var points = new ObservablePoint[analysisResults.NonlinearSolution.Count]; for (int i = 0; i < analysisResults.NonlinearSolution.Count; i++) { points[i] = new ObservablePoint() { X = i, Y = analysisResults.NonlinearSolution[i][analysisResults.SelectedDOF] }; } var mapper = Mappers.Xy <ObservablePoint>() //in this case value is of type <ObservablePoint> .X(value => value.X) //use the X property as X .Y(value => value.Y); //use the Y property as Y SeriesCollection graph = new SeriesCollection { //new LineSeries //{ // Values = new ChartValues<double>(xAxis) //}, new LineSeries { Values = new ChartValues <ObservablePoint>(points) } }; OnShowDiagramInGUI(new ShowDiagramInGUIArgs() { DiagramData = graph }); return(graph); }
private void loadGraph(IList <Objects.Solution> solutions) { SeriesCollection coll = new SeriesCollection(); foreach (var group in solutions.GroupBy(s => s.Shaft)) { ScatterSeries series = new ScatterSeries(); coll.Add(series); series.Title = group.Key; series.Values = new ChartValues <ObservablePoint>(); foreach (var item in group) { ObservablePoint op = new ObservablePoint(item.StaticPressure, item.Cost); series.Values.Add(op); } } cartesianChart1.AxisX.Add(new Axis() { Title = "Static Pressure (in wg)" }); cartesianChart1.AxisY.Add(new Axis() { Title = "Cost $" }); cartesianChart1.Series = coll; cartesianChart1.LegendLocation = LegendLocation.Right; }
private void TransferToChartValuesHelper( List <PacketInfo> packetInfo, GearedValues <DateTimePoint> packetLengthChartValues, GearedValues <ObservablePoint> timeDiffChartValues, PacketInfoWrapper prevPacketInfoWrapper) { int timeDiffStartOffset = timeDiffChartValues.Count; List <DateTimePoint> dateTimePoints = new List <DateTimePoint>(); List <ObservablePoint> timeDiffPoints = new List <ObservablePoint>(); foreach (PacketInfo p in packetInfo) { DateTimePoint dtp = new DateTimePoint(p.time, p.length); dateTimePoints.Add(dtp); if (prevPacketInfoWrapper.p != null) { int diffMs = (int)(p.time - prevPacketInfoWrapper.p.time).TotalMilliseconds; ObservablePoint point = new ObservablePoint(timeDiffPoints.Count + timeDiffStartOffset, diffMs); timeDiffPoints.Add(point); } prevPacketInfoWrapper.p = p; } packetInfo.Clear(); packetLengthChartValues.AddRange(dateTimePoints); timeDiffChartValues.AddRange(timeDiffPoints); }
public void AddToPlotdB(IEnumerable <double> x, IEnumerable <double> y, string title, int index) { //modifying the series collection will animate and update the chart ChartValues <ObservablePoint> nove = new ChartValues <ObservablePoint>(); ObservablePoint[] points = new ObservablePoint[x.Count()]; for (var i = 0; i < x.Count(); ++i) { points[i] = new ObservablePoint { X = x.ElementAt(i), Y = 20 * Math.Log10(y.ElementAt(i)) }; } nove.AddRange(points); if (SeriesCollection.Count < index + 1) { SeriesCollection.Add(new LineSeries()); } SeriesCollection.CurrentSeriesIndex = index; if (index == 0 && SeriesCollection.Count > 1) { SeriesCollection.RemoveAt(1); } SeriesCollection[index] = (new LineSeries { Title = title, Values = nove.AsGearedValues().WithQuality(Quality.Medium), LineSmoothness = 0, //0: straight lines, 1: really smooth lines //PointGeometry = Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"), PointGeometry = DefaultGeometries.Circle, PointGeometrySize = 1, Fill = Brushes.Transparent }); }
private void initializeValues() { for (int i = 0; i < 3; i++) { freqValues[i][0] = 21.7; freqValues[i][1] = 38.6; freqValues[i][2] = 68.8; freqValues[i][3] = 123.0; freqValues[i][4] = 218.0; freqValues[i][5] = 389.0; freqValues[i][6] = 694.0; freqValues[i][7] = 1240.0; freqValues[i][8] = 2200.0; freqValues[i][9] = 3920.0; freqValues[i][10] = 6990.0; freqValues[i][11] = 12500.0; volValues[i] = 0.00; delayValues[i] = 0.00; for (int j = 0; j < 12; j++) { qValues[i][j] = 4.00; gainValues[i][j] = 0.00; typeValues[i][j] = "Parametric"; for (int k = 0; k < plotFrequencies.Length; k++) { ObservablePoint point = new ObservablePoint(plotFrequencies[k], 0); channelPoints[k] = point; } plotValues[j].AddRange(channelPoints); } } }
private void AddData(double microstrain, double stress) { var newData = new ObservablePoint { X = microstrain, Y = stress }; Data.Add(newData); if (newData.X == 0) { _axialData.Add(newData); _radialData.Add(newData); _radialDataPlot.Values.Clear(); _radialDataPlot.Values.AddRange(_radialData); _axialDataPlot.Values.Clear(); _axialDataPlot.Values.AddRange(_axialData.OrderBy(d => d.X)); } else if (newData.X < 0) { _radialData.Add(newData); _radialDataPlot.Values.Clear(); _radialDataPlot.Values.AddRange(_radialData.OrderBy(d => d.X)); } else { _axialData.Add(newData); _axialDataPlot.Values.Clear(); _axialDataPlot.Values.AddRange(_axialData.OrderBy(d => d.X)); } }
private double GetLowValueAt(double x) { double value = 0; ObservablePoint low = new ObservablePoint { X = 0, Y = 0 }; ObservablePoint high = new ObservablePoint { X = 0, Y = 0 }; foreach (ObservablePoint point in SeriesCollection[1].Values) { if (point.X == x) { return(point.Y); } if (point.X < x) { low = point; } if (point.X > x) { high = point; } } value = low.Y + ((x - low.X) / (high.X - low.X)) * (high.Y - low.Y); return(value); }
public void OnEnter(Agent agent) { m_Point = agent.GetCurrentPoint() as ObservablePoint; m_CurrentIndex = 0; m_EndTime = Time.time + m_Point.Duration; }
private async Task StartSineGenerator() { while (true) { // Use Dispatcher.InvokeAsync with DispatcherPriority.Background // to improve UI responsiveness Application.Current.Dispatcher.InvokeAsync( () => { // Shift item data (and not the items) to the left for (var index = 0; index < this.ChartValues.Count - 1; index++) { ObservablePoint currentPoint = this.ChartValues[index]; ObservablePoint nextPoint = this.ChartValues[index + 1]; currentPoint.X = nextPoint.X; currentPoint.Y = nextPoint.Y; } // Add the new reading ObservablePoint newPoint = this.ChartValues[this.ChartValues.Count - 1]; newPoint.X += 1; newPoint.Y = Math.Sin(newPoint.X * Math.PI / 180); // Update axis min/max this.XMax = newPoint.X; this.XMin = this.ChartValues[0].X; }, DispatcherPriority.Background); await Task.Delay(TimeSpan.FromMilliseconds(50)); } }
void FillLine() { LineValues = new ChartValues <ObservablePoint>(); var ctlpt = InputRawDB.ControlPoints; for (int i = 0; i < ctlpt.Count; i++) { double val_in = ctlpt[i].X; double val_out = ctlpt[i].Y; var pt = new ObservablePoint(val_in, val_out); LineValues.Add(pt); } if (this.grpAxisMap.Series.Count == 0) { var line = new LineSeries { ContextMenu = lineNodeMenu, Values = LineValues, DataLabels = false, LabelPoint = point => point.Y.ToString(), LineSmoothness = 0 }; this.grpAxisMap.Series.Add(line); } else { this.grpAxisMap.Series[0].Values = LineValues; } }
public void OnEnter(AiTank aitank) { m_Point = aitank.GetCurrentPoint() as ObservablePoint; m_CurrentIndex = 0; m_EndTime = Time.time + m_Point.Duration; }
public void OnEnter(AiBoss2 aiBoss2) { m_Point = aiBoss2.GetCurrentPoint() as ObservablePoint; m_CurrentIndex = 0; m_EndTime = Time.time + m_Point.Duration; }
public void initializeAlgorithm(string crop) { dataManager.initializeKmeans(crop); SeriesCollection sc = new SeriesCollection() { new ScatterSeries { Title = "Cluster A", Values = new ChartValues <ObservablePoint>(), }, new ScatterSeries { Title = "Cluster B", Values = new ChartValues <ObservablePoint>(), PointGeometry = DefaultGeometries.Diamond }, new ScatterSeries { Title = "Cluster C", Values = new ChartValues <ObservablePoint>(), PointGeometry = DefaultGeometries.Triangle, StrokeThickness = 2, Fill = Brushes.Transparent }, new ScatterSeries { Title = "Cluster D", Values = new ChartValues <ObservablePoint>(), PointGeometry = DefaultGeometries.Cross, StrokeThickness = 2, Fill = Brushes.Transparent }, new ScatterSeries { Title = "Cluster E", Values = new ChartValues <ObservablePoint>(), PointGeometry = DefaultGeometries.Square } }; int index = 0; foreach (var series in sc) { List <Measurement> meas = dataManager.getClusterMeasurementByID(index); List <CropMeasurement> crops = dataManager.getClusterCropsByID(index); for (int i = 0; i < crops.Count; i++) { ObservablePoint p = new ObservablePoint(meas[i].Concentration, crops[i].getTypeCrop(crop)); series.Values.Add(p); } index++; } KmeansChart.Series = sc; KmeansChart.LegendLocation = LegendLocation.Bottom; }
public void ReplaceRandomItem() { var randomValue = _random.Next(1, 10); var randomIndex = _random.Next(0, _observableValues.Count - 1); _observableValues[randomIndex] = new ObservablePoint { X = _observableValues[randomIndex].X, Y = randomValue }; }
// #region IState implementation public void OnEnter(AiBossDargon aitank) { // aitank.am.SetBool("Stand", true); m_Point = aitank.GetCurrentPoint() as ObservablePoint; m_CurrentIndex = 0; m_EndTime = Time.time + m_Point.Duration; }
void InitChart() { LinesDatabase.GetAtmosphereTables(out _tempsList, out _svpList, out _arhToShowList); for (int j = 0; j < LinesDatabase.ARH_LINE_COUNT; j++) { LineSeries ls = new LineSeries { Values = new ChartValues <ObservablePoint> { }, LineSmoothness = 0, Fill = Brushes.Transparent, PointGeometrySize = 0, //DataLabels = true, }; VisualElement ve = new VisualElement { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom, UIElement = new HSVEControl(_arhToShowList[j]) }; double lastX = 0; double lastY = 0; bool hasShowEV = false; for (int i = 0; i < LinesDatabase.TEMP_LENGTH; i++) { //数据计算 double mc = HSAtmosphere.MoistureContent(_svpList[i], _arhToShowList[j], _pressure); var op = new ObservablePoint(mc, _tempsList[i]); //显示线 ls.Values.Add(op); if (!hasShowEV) { if (_tempsList[i] >= LinesDatabase.TEMP_MAX) { hasShowEV = true; lastX = mc; lastY = _tempsList[i]; } else if (mc >= LinesDatabase.MC_MAX) { hasShowEV = true; lastX = LinesDatabase.MC_MAX; lastY = _tempsList[i]; } } } _seriesCollection.Add(ls); //显示标志 ve.X = lastX; ve.Y = lastY; _cartesianVisuals.Add(ve); } }
private static void AddPoint(ISeries series, double x, double?y) { if (y == null || double.IsNaN(y.Value)) { return; } var values = series.Values as List <ObservablePoint>; Debug.Assert(values != null, nameof(values) + " != null"); var point = new ObservablePoint(x, y); values.Add(point); }
private Tuple <int, int> CutWave(GearedValues <ObservablePoint> wave, int cutHeaderLever = 400) { double needSelectData = Math.Round((wave.Select(x => x.Y).Max() + wave.Select(x => x.Y).Min()) / 2, 3); ObservablePoint[] twopoint = new ObservablePoint[2]; double[] tempD = wave.Select(x => Math.Round(x.Y, 3)).ToArray(); double Xmin = 0.00; double Xmax = 300.00; for (int i = 1; i < 6000; i++) { if ((tempD[i - 1] >= needSelectData && tempD[i] <= needSelectData) || (tempD[i] >= needSelectData && tempD[i - 1] <= needSelectData)) { twopoint[0] = wave[i]; Xmin = wave[i].X; break; } } for (int i = 5999; i > 1; i--) { if ((tempD[i - 1] >= needSelectData && tempD[i] <= needSelectData) || (tempD[i] >= needSelectData && tempD[i - 1] <= needSelectData)) { Xmax = wave[i].X; break; } } int skip = 0; int take = 0; if (Xmin < 20) { skip = 0; } else { skip = (int)(Xmin * 20 - cutHeaderLever); } if (Xmax > 280) { take = (int)((300 - Xmin) * 20); } else { take = (int)((Xmax - Xmin) * 20 + cutHeaderLever); } return(new Tuple <int, int>(skip, take)); }
public static Tuple <double, double> GradientDescent(double[,] data, double thetaOne, double thetaTwo, ChartValues <ObservablePoint> hypothesis, double interations) { Debug.OutPut("--- INITIAL ---" + thetaOne + " " + thetaTwo); double m = data.GetLength(0); int count = 0; while (count < interations) { double sumOne = 0; double sumTwo = 0; for (int i = 0; i < m; i++) { Point currentPoint = new Point(data[i, 0], data[i, 1]); double modelValue = SolveRegressionModel(currentPoint.X, thetaOne, thetaTwo); sumOne += modelValue - currentPoint.Y; } double tempThetaOne = thetaOne - LeariningRate * (1 / m) * sumOne; for (int i = 0; i < m; i++) { Point currentPoint = new Point(data[i, 0], data[i, 1]); double modelValue = SolveRegressionModel(currentPoint.X, thetaOne, thetaTwo); sumTwo += (modelValue - currentPoint.Y) * currentPoint.X; } double tempThetaTwo = thetaTwo - LeariningRate * (1 / m) * sumTwo; thetaOne = tempThetaOne; thetaTwo = tempThetaTwo; Debug.OutPut("Iter: " + count + " T0: " + thetaOne + " T1: " + thetaTwo); count++; if (count % 10 == 0) { // Add for first var x = 0; var y = thetaOne + thetaTwo * x; var a = new ObservablePoint(x, y); x = 20; y = thetaOne + thetaTwo * x; var b = new ObservablePoint(x, y); hypothesis.Clear(); hypothesis.Add(a); hypothesis.Add(b); } } return(new Tuple <double, double>(thetaOne, thetaTwo)); }
public void AddRealtimeTemperaturePoint(Token token, ObservablePoint point) { var index = 0; switch (token) { case Token.UpperTemperature: { index = 0; break; } case Token.InnerRingTemperature: { index = 1; break; } case Token.OuterRingTemperature: { index = 2; break; } } this.realtimeTemperautreCurve[index].Values.Add(point); }
public static ObservablePoint[] GetEleOrVolate(List <float> EleXvalue, List <double> EleYvalue) { if (EleXvalue.Count == EleYvalue.Count) { float[] Xva = EleXvalue.ToArray(); double[] Yva = EleYvalue.ToArray(); ObservablePoint[] rtd = new ObservablePoint[EleXvalue.Count]; for (int i = 0; i < EleXvalue.Count; i++) { rtd[i] = new ObservablePoint(Xva[i], Yva[i]); } return(rtd); } return(null); }
private void AddNewPoint(CartesianChart graph, double x, double y) { if (graph.Series?[0].Values != null) { ObservablePoint observablePoint = new ObservablePoint(x, y); graph.Series[0].Values.Add(observablePoint); } else if (graph.Series != null) { graph.Dispatcher.Invoke(() => graph.Series[0].Values = new ChartValues <ObservablePoint> { new ObservablePoint(x, y) }); } }
public ObservablePoint CalculateInPoint(double point) { try { _argument.setArgumentValue(point); var resInPoint = _expression.calculate(); var observablePoint = new ObservablePoint(point, resInPoint); return(observablePoint); } catch (Exception) { return(new ObservablePoint(point, double.NaN)); } }
public GamepadChart() { var lineChartPoints = new List <ObservablePoint> { new ObservablePoint(0, 0), new ObservablePoint(255, 255) }; LineChartValues = new ChartValues <ObservablePoint>(); LineChartValues.AddRange(lineChartPoints); _point = new ObservablePoint(0, 0); PointChartValues = new ChartValues <ObservablePoint> { _point }; ExpoChartValues = new ChartValues <short>(); }
private SeriesCollection ShowDynamicLinearResults(Results analysisResults) { int countVector = analysisResults.DynamicSolution.Count; int step = 0; int line = 0; double[] xAxis = new double[analysisResults.DynamicSolution.Count]; double[] yAxis = new double[analysisResults.DynamicSolution.Count]; var points = new ObservablePoint[analysisResults.DynamicSolution.Count]; while (step < analysisResults.DynamicSolution.Count) { double[] sol = analysisResults.DynamicSolution[step]; xAxis[line] = analysisResults.TimeSteps[step]; yAxis[line] = sol[analysisResults.SelectedDOF]; points[line] = new ObservablePoint() { X = analysisResults.TimeSteps[step], Y = sol[analysisResults.SelectedDOF] }; line = line + 1; step = step + analysisResults.SelectedInterval; //if (step >= solution.Count-1) //{ // break; //} } var mapper = Mappers.Xy <ObservablePoint>() //in this case value is of type <ObservablePoint> .X(value => value.X) //use the X property as X .Y(value => value.Y); //use the Y property as Y SeriesCollection graph = new SeriesCollection { //new LineSeries //{ // Values = new ChartValues<double>(xAxis) //}, new LineSeries { Values = new ChartValues <ObservablePoint>(points) } }; return(graph); }
//chart page object public RiskChart() { var r = new Random(); ObservablePoint RiskPoint = new ObservablePoint(2, 2); ScatterValues = new ChartValues <ObservablePoint>(); ScatterValues.Add(RiskPoint); foreach (ObservablePoint point in ScatterValues) { //Debug.WriteLine("x:{0}, y:{1}", point.X, point.Y); } HeatValues = new ChartValues <HeatPoint>(); for (double X = 1; X <= 3; X += 1) { for (double Y = 1; Y <= 3; Y += 1) { if ((int)X == (int)RiskPoint.X && (int)Y == (int)RiskPoint.Y) { HeatValues.Add(new HeatPoint(X, Y, 2)); } HeatValues.Add(new HeatPoint(X, Y, X * Y)); } } this.DataContext = this; InitializeComponent(); SeriesCollection = new SeriesCollection { new HeatSeries { Title = "MyHeat", Values = HeatValues, }, }; }
private void Calc_And_Plot_DFT(List <byte> values) { if (InvokeRequired) { this.Invoke(new Action <List <byte> >(Calc_And_Plot_DFT), new object[] { values }); return; } byte[] values_Array = values.ToArray(); double[] Input = new double[values.Count + 2]; double[] FreqScale = MathNet.Numerics.IntegralTransforms.Fourier.FrequencyScale(200, Globals.SamplingFreq); string[] FreqScale_labels = new string[FreqScale.Length]; for (int i = 0; i < FreqScale.Length; i++) { FreqScale_labels[i] = FreqScale[i].ToString("0.0"); } AForge.Math.Complex[] complex32 = new AForge.Math.Complex[200]; for (int i = 0; i < 200; i++) { complex32[i] = new AForge.Math.Complex(Convert.ToSingle((values_Array[i])), 0); } AForge.Math.FourierTransform.DFT(complex32, AForge.Math.FourierTransform.Direction.Forward); for (int i = 0; i < 50; i++) { DFT_Values[i] = new ObservablePoint(i, 20 * Math.Log10(complex32[i].Magnitude / complex32[SecondLargestIndex(complex32)].Magnitude)); } for (int i = 0; i < 200; i++) { Phase_Values[i] = new ObservablePoint(i, complex32[i].Phase); } cartesianChart_DFT.AxisX[0].Labels = FreqScale_labels; cartesianChart_phase.AxisX[0].Labels = FreqScale_labels; label_Vpp.Text = string.Format("Vpp = {0}", (((values.Max() - values.Min()) / 255.0) * 3.2).ToString("0.00")); List <double> FreqScaleList = new List <double>(FreqScale); int SLI = SecondLargestIndex(complex32); label_Freq.Text = string.Format("Frequency = {0}", Math.Abs(FreqScaleList[SLI]).ToString("0.00")); label_phase.Text = string.Format("Phase = {0}", complex32[SLI].Phase.ToString("0.00")); }