// Retrieve end of day price data from yahoo finance public void GetData(string symbol, int period, int observations) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://ichart.yahoo.com/table.csv?s=" + symbol); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream()); DataPointCollection logReturns = new DataPointCollection(); int i = 0; string line = sr.ReadLine();// skip first line (header) string[] m = sr.ReadLine().Split(','); // The # of items we need to retrieve (make sure right amount) int j = period*4 + 1; if (j <= observations*4+1) { j = ((observations * 4) + 1); } while (i < j) { string[] n = sr.ReadLine().Split(','); double l = Convert.ToDouble(m[4]); double k = Convert.ToDouble(n[4]); DataPoint t = new DataPoint(Math.Log(l / k), Convert.ToDateTime(m[0])); logReturns.Add(t); m = n; i++; } // Calculate volatilities double annualFactor = Math.Sqrt(252); for (i = 0; i < j / 2; ++i) { double vol = StandardDeviation(logReturns.GetRange(i, period)) * annualFactor; DataPoint t = new DataPoint(vol, logReturns[i].Date); _vols.Add(t); } // Calculate std-dev of all volatilities for(i = 0; i < observations; ++i) { double stdDev = StandardDeviation(_vols.GetRange(i, period)); DataPoint t = new DataPoint(stdDev, _vols[i].Date); _volStdDev.Add(t); } // Take subset so we can plot on graph _vols = _vols.GetRange(0, observations); }
public HistogramRGB(int [,] array) { InitializeComponent(); DataPointCollection list1 = chart1.Series[0].Points; DataPointCollection list2 = chart1.Series[1].Points; DataPointCollection list3 = chart1.Series[2].Points; for (int i = 0; i < 256; i++) { list1.AddXY(i, array[0, i]); list2.AddXY(i, array[1, i]); list3.AddXY(i, array[2, i]); } chart1.Series[0].Color = Color.Blue; chart1.Series[1].Color = Color.Green; chart1.Series[2].Color = Color.Red; chart1.ChartAreas[0].AxisX.Maximum = 255; chart1.ChartAreas[0].AxisX.Minimum = 0; chart1.ChartAreas[0].AxisX.Title = "Intensidade"; chart1.ChartAreas[0].AxisY.Title = "Numero Pixeis"; chart1.ResumeLayout(); }
/// <summary> /// Initializes a new instance of the Visifire.Charts.DataSeries class /// </summary> public DataSeries() { ToolTipText = ""; //IsZIndexSet = false; // Apply default style from generic #if WPF if (!_defaultStyleKeyApplied) { DefaultStyleKeyProperty.OverrideMetadata(typeof(DataSeries), new FrameworkPropertyMetadata(typeof(DataSeries))); _defaultStyleKeyApplied = true; } #else DefaultStyleKey = typeof(DataSeries); #endif // Initialize DataPoints list DataPoints = new DataPointCollection(); // Initialize InternalDataPoints list InternalDataPoints = new List<DataPoint>(); // Attach event handler for the Title collection changed event DataPoints.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(DataPoints_CollectionChanged); }
/// <summary> /// Export the line series to an oxyplot series. /// </summary> /// <param name="series">The line series to be exported.</param> /// <param name="labels">Existing axis labels.</param> protected override (Series, AxisLabelCollection) Export(LineSeries series, AxisLabelCollection labels) { LineSeriesWithTracker result = new LineSeriesWithTracker(); DataPointCollection data = GetDataPoints(series.X, series.Y, labels); result.ItemsSource = data.Points; if (series.ShowOnLegend) { result.Title = series.Title; } // Line style/thickness result.LineStyle = series.LineConfig.Type.ToOxyPlotLineStyle(); result.StrokeThickness = series.LineConfig.Thickness.ToOxyPlotThickness(); // tbi: line colour configuration // result.Stroke = series.LineConfig.Colour.ToOxyPlotColour(); // Marker type/thickness result.MarkerType = series.MarkerConfig.Type.ToOxyPlotMarkerType(); result.MarkerSize = series.MarkerConfig.Size.ToOxyPlotMarkerSize() * series.MarkerConfig.SizeModifier; if (series.MarkerConfig.IsFilled()) { result.MarkerFill = series.Colour.ToOxyColour(); } else { result.MarkerFill = OxyColors.Undefined; } // Colour result.Color = series.Colour.ToOxyColour(); return(result, data.Labels); }
/// <summary> /// Тоже найти точку, но уже из списка точек серии /// </summary> /// <param name="PointList"></param> /// <param name="Dt"></param> /// <returns></returns> public static DataPoint FindPoint(DataPointCollection PointList, DateTime Dt) { if (DateTime.FromOADate(PointList[0].XValue).Subtract(Dt).TotalMilliseconds > 0 || DateTime.FromOADate(PointList[PointList.Count - 1].XValue).Subtract(Dt).TotalMilliseconds < 0) { MessageBox.Show("Усреднение не произвено. Выбран интервал усреднения, заходящий за начало данных"); return(new DataPoint()); } else { double FrecvencyRegistration = DateTime.FromOADate(PointList[1].XValue).Subtract(DateTime.FromOADate(PointList[0].XValue)).TotalMilliseconds; TimeSpan MyTS; foreach (var item in PointList) { //if (DateTime.FromOADate(item.XValue).Hour == Dt.Hour && DateTime.FromOADate(item.XValue).Minute == Dt.Minute && Math.Abs(DateTime.FromOADate(item.XValue).Second - Dt.Second) <= FrecvencyRegistration/2) MyTS = DateTime.FromOADate(item.XValue).Subtract(Dt); if (Math.Abs(MyTS.TotalMilliseconds) <= FrecvencyRegistration) { return(item); } } MessageBox.Show("Не найдено совпадение времени с курсором"); } return(new DataPoint()); }
public void GetChar() { CharTitName = "XXX物料统计图表"; YCharTitName = "数量/个"; XCharTitName = "物料"; DataPointCollection salist = new DataPointCollection(); DataTable table = new DataTable(); table.Columns.Add("Name", Type.GetType("System.String")); //添加Name列,存储数据类型为string table.Columns.Add("Id", Type.GetType("System.Int32")); //添加Id列,存储数据类型为Int table.Columns.Add("Number", Type.GetType("System.Int32")); //添加Id列,存储数据类型为Int Random random = new Random(); for (int i = 0; i < 5; i++) { int number = random.Next(10, 100); DataRow newRow = table.NewRow(); newRow["Name"] = $"物料{i}"; newRow["Id"] = i; newRow["Number"] = i + number; table.Rows.Add(newRow); } foreach (DataRow item in table.Rows) { var datapoint = new DataPoint { AxisXLabel = item["Name"].ToString(), YValue = double.Parse(item["Number"].ToString()) }; salist.Add(datapoint); } Chardatas = salist; }
public void Add(string xname, string yname, bool error, DataPointCollection points) { bool register_x = false; int xindex = -1, yindex; if (Xname.IndexOf(xname) < 0) { register_x = true; Xname.Add(xname); Name.Add(xname); Data.Add(new List <double>()); xindex = Data.Count - 1; } Name.Add(yname); Data.Add(new List <double>()); yindex = Data.Count - 1; foreach (DataPoint p in points) { if (register_x && xindex >= 0) { Data[xindex].Add(p.XValue); } if (error) { Data[yindex].Add(Math.Abs(p.YValues[0] - p.YValues[1])); } else { Data[yindex].Add(p.YValues[0]); } } }
public static Boolean isStatic(DataPointCollection arr) { int shag = arr.Count / 10; double[] means = new double[10]; double[] meansquares = new double[10]; double[] deviations = new double[10]; for (int i = 0; i < 10; i++) { means[i] = ExpectedValue(arr.Skip(shag * i).Take(shag)); // meansquares[i] = MeanSquare(arr.Skip(shag * i).Take(shag)); deviations[i] = StandartDeviation(arr.Skip(shag * i).Take(shag)); } for (int i = 0; i < means.Length; i++) { for (int j = 0; j < means.Length; j++) { if (means[i] / means[j] < 0.8) { return(false); } /* if (meansquares[i] / meansquares[j] < 0.9) * { * return false; * }*/ if (deviations[i] / deviations[j] < 0.8) { return(false); } } } return(true); }
public HistogramAll(int [] array, int [,] array2) { InitializeComponent(); DataPointCollection listGray = chart1.Series[0].Points; DataPointCollection listBlue = chart1.Series[1].Points; DataPointCollection listGreen = chart1.Series[2].Points; DataPointCollection listRed = chart1.Series[3].Points; for (int i = 0; i < 256; i++) { listGray.AddXY(i, array[i]); } for (int i = 0; i < 256; i++) { listBlue.AddXY(i, array2[0, i]); listGreen.AddXY(i, array2[1, i]); listRed.AddXY(i, array2[2, i]); } chart1.Series[0].Color = Color.Gray; chart1.Series[1].Color = Color.Blue; chart1.Series[2].Color = Color.Green; chart1.Series[3].Color = Color.Red; chart1.ChartAreas[0].AxisX.Maximum = 255; chart1.ChartAreas[0].AxisX.Minimum = 0; chart1.ChartAreas[0].AxisX.Title = "Intensidade"; chart1.ChartAreas[0].AxisY.Title = "Numero Pixeis"; chart1.ResumeLayout(); }
/// <summary> /// Exporta los puntos visibles en la gráfica a un .CVS desde el menú. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Exportar_GraficatoolStripMenuItem_Click(object sender, EventArgs e) { try { DataPointCollection data = chart_DataOutput.Series[0].Points; SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "CSV | *.csv"; dialog.Title = "Exportar"; dialog.ShowDialog(); using (FileWriter writer = new FileWriter(dialog.FileName)) { int i = 0; StringBuilder sb = new StringBuilder(); foreach (DataPoint item in data) { sb.AppendLine(i++ + "," + item.YValues.GetValue(0)); } writer.WriteLine(sb.ToString()); writer.Flush(); data.Dispose(); } ToolStripStatusLabel_Status_Write(toolStripStatusLabel_ProgramStatus, "Gráfica exportada"); } catch (Exception ex) { string windowTitle = "Error al guardar como"; MessageBox.Show(ex.Message, windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// 显示 PlugRTData private DataPointCollection GetPlugRTDataPointByDateTime(Int64 plugid, DateTime startDateTime, DateTime endDateTime, string itemStr) { try { bool success = false; DataTable dt = SmartPlugDAL.GetSelectedPlugRTDataByPlugIDandDateTime(plugid, startDateTime, endDateTime, itemStr + ",DateTime", SqliteDBPath, ref success); DataPointCollection dpc = new DataPointCollection(); if (success == true) { int dtrowcount = dt.Rows.Count; for (int i = 0; i < dtrowcount; i++) { DataPoint dp = new DataPoint() { XValue = dt.Rows[i]["DateTime"], YValue = Convert.ToDouble(dt.Rows[i][itemStr]) }; dpc.Add(dp); } return(dpc); } return(dpc); } catch (Exception ex) { //Do any logging operation here if necessary throw new Exception(ex.Message); } }
private void FindMinMax(DataPointCollection collection, out double minX, out double maxX, out double minY, out double maxY) { minX = 9999.0; maxX = -9999.0; minY = 9999.0; maxY = -9999.0; foreach (DataPoint data in collection) { if (minX > data.XValue) { minX = data.XValue; } if (maxX < data.XValue) { maxX = data.XValue; } if (minY > data.YValues[0]) { minY = data.YValues[0]; } if (maxY < data.YValues[0]) { maxY = data.YValues[0]; } } }
/// <summary> /// Procedure to build random graphics /// </summary> /// <param name="points">series to fill</param> /// <param name="location">in which chartarea build</param> /// <param name="seed">seed for random initialization</param> internal static void Random(DataPointCollection points, string location, int seed = 1) { Random r = new Random(seed); CustomRandom cr = new CustomRandom(seed); switch (location) { case "ChartAreaTopLeft": points.Clear(); for (int i = minX; i < maxX; i++) { points.AddXY(i, r.NextDouble()); } break; case "ChartAreaBottomLeft": points.Clear(); for (int i = minX; i < maxX; i++) { points.AddXY(i, cr.Next()); } break; default: break; } }
void HeapsortMax(DataPointCollection input, int heapSize, int index) { int left = (index + 1) * 2 - 1; int right = (index + 1) * 2; int largest = 0; HighlightLabel(Form1.ps1); if (left < heapSize && input.ElementAt(left).YValues.First() > input.ElementAt(index).YValues.First()) { largest = left; } else { HighlightLabel(Form1.ps2); largest = index; HighlightLabel(Form1.ps3); } HighlightLabel(Form1.ps4); if (right < heapSize && input.ElementAt(right).YValues.First() > input.ElementAt(largest).YValues.First()) { largest = right; } HighlightLabel(Form1.ps5); if (largest != index) { HighlightLabel(Form1.ps6); swapChartIndices(index, largest); HighlightLabel(Form1.ps7); //System.Threading.Thread.Sleep(50); HeapsortMax(input, heapSize, largest); } }
public static double[] AntiSpike(DataPointCollection points, double num = 4) { double disp = Statistics.CalcRMS(points); double mean = Statistics.CalcAVG(points); double[] values = points.Select(y => y.YValues[0]).ToArray(); for (int i = 0; i < values.Length; i++) { if (values[i] > mean + Math.Sqrt(num * disp) || values[i] < -(mean + Math.Sqrt(num * disp))) { if (i != 0 && i != values.Length - 1) { values[i] = (values[i - 1] + values[i + 1]) / 2; } else if (i == 0) { values[i] = (values[i + 1] + values[i + 2]) / 2; } else { values[i] = (values[i - 1] + values[i - 2]) / 2; } } } return(values); }
public static void DPF(DataPointCollection points, string location) { switch (location) { case "ChartAreaTopLeft": break; case "ChartAreaTopRight": points.Clear(); for (int i = minX; i < maxX; i++) { points.AddXY(i, FourierArr[i].C); } break; case "ChartAreaBottomLeft": points.Clear(); for (int i = minX; i < maxX; i++) { points.AddXY(i, FourierArr[i].Re); } break; case "ChartAreaBottomRight": points.Clear(); for (int i = minX; i < maxX - 5; i++) { points.AddXY(i, FourierArr[i].C); } break; default: break; } }
private void CalculateFrequencies(List <double> residualValues, Series series) { double roundedMax, intervalWidth; CalculateResidualParameters(residualValues, out roundedMax, out intervalWidth); IEnumerable <double> relevantResiduals = residualValues; IRegressionProblemData problemdata = Content.ProblemData; if (series.Name.Equals(TRAINING_SAMPLES)) { relevantResiduals = residualValues.Skip(problemdata.TrainingPartition.Start).Take(problemdata.TrainingPartition.Size); } else if (series.Name.Equals(TEST_SAMPLES)) { relevantResiduals = residualValues.Skip(problemdata.TestPartition.Start).Take(problemdata.TestPartition.Size); } double intervalCenter = intervalWidth / 2.0; double sampleCount = relevantResiduals.Count(); double current = -roundedMax; DataPointCollection seriesPoints = series.Points; for (int i = 0; i <= bins; i++) { IEnumerable <double> help = relevantResiduals.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter)); seriesPoints.AddXY(current, help.Count() / sampleCount); seriesPoints[seriesPoints.Count - 1]["from"] = (current - intervalCenter).ToString(); seriesPoints[seriesPoints.Count - 1]["to"] = (current + intervalCenter).ToString(); current += intervalWidth; } }
void OnUnloaded(object sender, RoutedEventArgs e) { DataContext = null; archimedianSpiral = null; cardioid = null; cartesianFolium = null; }
public SpareSeriesPrimaryCpu() { InitializeComponent(); SeriesNewCycleRecvDataPoints = new DataPointCollection(); SeriesInputRecvDataPoints = new DataPointCollection(); SeriesResultRecvDataPoints = new DataPointCollection(); SeriesHeartBeatRecvDataPoints = new DataPointCollection(); EeuRecvDataPoints = new DataPointCollection(); SeriesNewCycle.DataPoints = SeriesNewCycleRecvDataPoints; SeriesInput.DataPoints = SeriesInputRecvDataPoints; SeriesResult.DataPoints = SeriesResultRecvDataPoints; SeriesHeartBeat.DataPoints = SeriesHeartBeatRecvDataPoints; CiCycle.DataPoints = CiCycleDataPoints; Interrupt.DataPoints = InterruptDataPoints; CpuNewCycle.DataPointsSend = CpuNewCycleSendDataPoints; CpuNewCycle.DataPointsRecv = CpuNewCycleRecvDataPoints; CpuInput.DataPointsSend = CpuInputSendDataPoints; CpuInput.DataPointsRecv = CpuInputRecvDataPoints; CpuResult.DataPointsSend = CpuResultSendDataPoints; CpuResult.DataPointsRecv = CpuResultRecvDataPoints; CpuHeartBeat.DataPointsSend = CpuHeartBeatSendDataPoints; CpuHeartBeat.DataPointsRecv = CpuHeartBeatRecvDataPoints; EeuRecv.DataPoints = EeuRecvDataPoints; }
private void RenderData(int index, Chart target) { if (target.Series.Count.Equals(0)) { target.Series.Add(_src.Series[index]); } if (target.Titles.Count.Equals(0)) { target.Titles.Add(_src.Series[index]); } if (target.Series[0].ChartType != SeriesChartType.Pie) { target.Series[0].ChartType = SeriesChartType.Pie; } target.Series[0].Name = _src.Series[index]; DataPointCollection dpc = target.Series[0].Points; dpc.Clear(); foreach (PieChartDataPoint dp in _src[index]) { dpc[dpc.AddXY(dp.SliceName, dp.Value)].LegendText = dp.SliceName; if (_legends.ContainsKey(dp.SliceName)) { dpc[dpc.Count - 1].Color = _legends[dp.SliceName].Color; } else { // _legends.Add(dp.SliceName, dpc[dpc.Count - 1].Color); } } }
void BindYearChart() { ChartArea chArea = Chart1.ChartAreas[0]; DataPointCollection dpc = Chart1.Series[0].Points; chArea.AxisX.Title = "Year"; chArea.AxisY.Title = "Sale Amt"; chArea.AxisY.LabelStyle.Format = "##,###"; using (DBSampleEntities context = new DBSampleEntities()) { var data = (from item in context.SaleInfoes group item by item.SaleDate.Value.Year into g select new { Year = g.Key, SaleAmt = g.Sum(x => x.SaleAmt) }); foreach (var item in data) { dpc.AddXY(item.Year, item.SaleAmt); } } Series series = Chart1.Series[0]; series.IsValueShownAsLabel = true; series.PostBackValue = "#VALX"; series.LabelFormat = "##,###"; series.LabelBackColor = Color.White; ViewState["ChartMode"] = "Year"; }
void OnMove(int?_x) { if (OnCursorMove == null) { return; } if (_x == null) { OnCursorMove(null, 0, Color.Black); } else { if (_x < 0) { OnCursorMove(null, 0, Color.Black); } else { DataPointCollection p = chart1.Series[0].Points; if (_x >= p.Count()) { OnCursorMove(null, 0, Color.Black); } else { OnCursorMove(p[(int)_x].Tag as PointSubj, p[(int)_x].YValues[0], p[(int)_x].Color); } } } }
public void updateGraphs() { DataPointCollection chart1Points = this.chart1.Series["Series1"].Points; DataPointCollection chart2Points = this.chart2.Series["Series1"].Points; chart1Points.Clear(); chart2Points.Clear(); for (int i = Math.Min(graph1ValuesToShow, dataList.Count); i > 0; i--) { if (chart1_x.SelectedIndex >= 0 && chart1_y.SelectedIndex >= 0) { double chart1XVal = dataList[dataList.Count - i].getValue((String)this.chart1_x.SelectedItem); double chart1YVal = dataList[dataList.Count - i].getValue((String)this.chart1_y.SelectedItem); chart1Points.AddXY(chart1XVal, chart1YVal); } } for (int i = Math.Min(graph2ValuesToShow, dataList.Count); i > 0; i--) { if (chart2_x.SelectedIndex >= 0 && chart2_y.SelectedIndex >= 0) { double chart2XVal = dataList[dataList.Count - i].getValue((String)this.chart2_x.SelectedItem); double chart2YVal = dataList[dataList.Count - i].getValue((String)this.chart2_y.SelectedItem); chart2Points.AddXY(chart2XVal, chart2YVal); } } }
private void CheckBoxCheckedChanged(object sender, EventArgs e) { CheckBox checkBox = sender as CheckBox; if (checkBox != null) { if (checkBox.Tag != null) { CheckBoxTag tag = checkBox.Tag as CheckBoxTag; if (tag != null) { AppManager.ConfigManager.SetConfigData(tag); if (checkBox.Checked) { FillSeriesWithNewData(tag, fromDateTime, toDateTime); } else { Chart chartMain = AppManager.MainForm.ChartControl.ChartMain; chartMain.BeginInit(); DataPointCollection points = tag.Series.Points; points.ClearFast(); //MsChartExtension if (chartMain.Series.Contains(tag.Series)) { chartMain.Series.Remove(tag.Series); } chartMain.EndInit(); } } } } }
private void GetMinAndMax(DataPointCollection <CategoricalDataPoint> dataPoints, out double min, out double max) { min = double.NaN; max = double.NaN; foreach (CategoricalDataPoint dp in dataPoints) { if (dp.Value.HasValue) { if (double.IsNaN(min) || dp.Value.Value < min) { min = dp.Value.Value; } if (double.IsNaN(max) || max < dp.Value.Value) { max = dp.Value.Value; } } } if (double.IsNaN(min) || double.IsNaN(max)) { return; } double expansion = (max - min) / 10; min -= expansion; max += expansion; if (min >= 0 && 0.16 < (max - min) / max) { min = 0; } }
public List <DataPoint> CheckAndCorrectConsecutiveXValues(DataPointCollection points) { List <DataPoint> dcp = new List <DataPoint>(); int i = 0; double currentmax = 0; List <int> badPoints = new List <int>(); foreach (DataPoint dp in points) { if (dp.XValue > currentmax) { currentmax = dp.XValue; dcp.Add(dp); } else { badPoints.Add(i); //for (int x = 0; x < points.Count; x++) //{ // if(points[x].XValue < ) //} } i++; } return(dcp); //foreach (int I in badPoints) //{ // points.RemoveAt(I); //} }
private void addValues(DataPointCollection dataPointCollection, double[] p) { for (int i = 0; i < p.Length; i++) { dataPointCollection.AddXY(i + 1, p[i]); } }
/// <summary> /// the constructor of the chartseries /// </summary> /// <param name="document"></param> /// <param name="node"></param> public ChartSeries(IDocument document, XElement node) { Document = document; Node = node; DataPointCollection = new DataPointCollection(); InitStandards(); }
public static void AddY(this DataPointCollection points, double y, double increment) { double x = points.Last().XValue + increment; DataPoint dp = new DataPoint(x, y); points.Add(dp); }
/// <summary> /// Среднее вправо-лево от указанного количества времени. /// </summary> /// <param name="PointList"></param> /// <param name="Dat"></param> /// <param name="SecCount_for_Aver"></param> /// <returns></returns> double FindAverage(DataPointCollection PointList, DateTime Dat, int SecCount_for_Aver) { double aver_Start = 0; double aver_End = 0; double aver = 0; int pointcount = 0; TimeSpan ts = new TimeSpan(0, 0, 0, SecCount_for_Aver, 0); aver_Start = FindPoint(PointList, Dat.Subtract(ts)).XValue; aver_End = FindPoint(PointList, Dat.Add(ts)).XValue; foreach (var item in PointList) { if (item.XValue > aver_Start && item.XValue < aver_End) { pointcount++; aver += item.YValues[0]; } } aver = aver / pointcount; return(aver); }
/* Clicks windowing button. */ private void windowing_Click(object sender, EventArgs e) { DataPointCollection wholePoints = chart1.Series["wave"].Points; // gets all the points on the time domain chart. double[] selectedPoints = new double[endPosition - startPosition + 1]; // gets all the points in the selected area. for (int i = 0; i < endPosition - startPosition + 1; i++) { selectedPoints[i] = wholePoints[i].YValues[0]; // stores all selected points. } double[] weighted = new double[selectedPoints.Length]; // stores points from windowing. for (int i = 0; i < weighted.Length; i++) // applies triangle windowing. { weighted[i] = (1 - Math.Abs(((double)i - ((weighted.Length - 1) / 2)) / (weighted.Length - 1) / 2)) * selectedPoints[i]; } double[] weightedA = Class1.DFT(weighted); // applies DFT after windowing. chart2.Series["frequency"].Points.Clear(); //clears out all points on frequency domain. for (int i = 0; i < weightedA.Length; i++) // draws new points on the frequency domain. { chart2.Series["frequency"].Points.AddXY(i, weightedA[i]); } }
void AddChartPoint(DataPointCollection chartPoints, Double value) { chartPoints.AddY(value); if (chartPoints.Count > MAX_GRAPH_VALUES) chartPoints.RemoveAt(0); }
/// <summary>Adds a System.Windows.Forms.DataVisualization.Charting.DataPoint object to the end of the collection, with the specified X-value and Y-value.</summary> /// <param name="dataPointCollection">The System.Windows.Forms.DataVisualization.Charting.DataPointCollection instance to add a DataPoint to.</param> /// <param name="xValue">X-value of the data point.</param> /// <param name="yValue">Y-value of the data point.</param> /// <returns>The new System.Windows.Forms.DataVisualization.Charting.DataPoint object.</returns> public static DataPoint AddXYDataPoint(this DataPointCollection dataPointCollection, double xValue, double yValue) { int dataPointIndex = dataPointCollection.AddXY(xValue, yValue); DataPoint dataPoint = dataPointCollection[dataPointIndex]; return(dataPoint); }
public void DataPointCollection() { var dataSource = new DataPointCollection { new DataPoint(2, 3, null), new DataPoint(4, 5, null), new DataPoint(6, 7, null) }; var chartDataSource = ChartDataHelper.CreateChartDataSource(dataSource, null, null, null, null, null, null); Assert.AreEqual(3, chartDataSource.Count); Assert.AreEqual(new DataPoint(new Point(2, 3), null), chartDataSource[0]); Assert.AreEqual(new DataPoint(new Point(4, 5), null), chartDataSource[1]); Assert.AreEqual(new DataPoint(new Point(6, 7), null), chartDataSource[2]); }
public static DataPointCollection GetDataPointCollection( List<double> list) { DataPointCollection dpc = new DataPointCollection(); double allCount = 100; double value = allCount / list.Count; for (int i = 0; i < list.Count; i++) { DataPoint dp = new DataPoint() { YValue = System.Math.Abs(list[i]) * 0.1, XValue = i * value }; dpc.Add(dp); } return dpc; }
/// <summary> /// Turns off the label on the chart of any data point that has no value to be displayed /// -leaving the label in the legend /// </summary> /// <param name="dpcPointsToRefine">The data points collection to be refined</param> private void UpdatePoints(DataPointCollection dpcPointsToRefine) { // Goes over every data point in the collection given foreach (DataPoint CurrPoint in dpcPointsToRefine) { // If the value of the data point is nothing if (CurrPoint.YValues[0] == 0.0) { // Turns off the label that sits on top of the chart CurrPoint.CustomProperties = "PieLabelStyle=Disabled"; } } }
public MonitorChart(Chart c, string name) { m_chart = c; // some shortcuts m_area = m_chart.ChartAreas[0]; m_series = m_chart.Series[0]; m_points = m_series.Points; m_axisX = m_area.AxisX; m_axisY = m_area.AxisY; m_annotations = new Dictionary<int, List<Annotation>>(); m_name = name; Init(); }
public NetworkTrainer(BackPropagationNetwork network, DataPointCollection dataSet) { Nudge = true; NudgeTolerance = 0.0001; NudgeScale = 0.4; NudgeWindow = 100; TargetError = 0.001; MaxIterations = 100000; TrainingRate = 0.15; Momentum = 0.10; Network = network; DataSet = dataSet; Initialize(); }
public void DataPoint_CanSerailize() { DataPoint point1 = new DataPoint(new[] { 1.0, 1.1 }, new[] { 2.0, 2.2 }); DataPoint point2 = new DataPoint(new[] { 2.0, 2.1 }, new[] { 4.0, 2.2 }); DataPoint point3 = new DataPoint(new[] { 3.0, 3.1 }, new[] { 6.0, 2.2 }); DataPoint point4 = new DataPoint(new[] { 4.0, 4.1 }, new[] { 8.0, 2.2 }); DataPoint point5 = new DataPoint(new[] { 5.0, 5.1 }, new[] { 10.0, 2.2 }); DataPointCollection dataPointCollection = new DataPointCollection(); dataPointCollection.Add(point1); dataPointCollection.Add(point2); dataPointCollection.Add(point3); dataPointCollection.Add(point4); dataPointCollection.Add(point5); XmlSerializer serializer = new XmlSerializer(typeof(DataPointCollection)); serializer.Serialize(Console.Out, dataPointCollection); }
public void CanTrainNetwork() { //XOR data DataPoint _dp1 = new DataPoint(new[] { 1.0, 1.0 }, new[] { 0.0 }); DataPoint _dp2 = new DataPoint(new[] { 1.0, 0.0 }, new[] { 1.0 }); DataPoint _dp3 = new DataPoint(new[] { 0.0, 1.0 }, new[] { 1.0 }); DataPoint _dp4 = new DataPoint(new[] { 0.0, 0.0 }, new[] { 0.0 }); DataPointCollection _dataPointCollection = new DataPointCollection(); _dataPointCollection.Add(_dp1); _dataPointCollection.Add(_dp2); _dataPointCollection.Add(_dp3); _dataPointCollection.Add(_dp4); int[] _layerSizes = new int[3] { 2, 2, 1 }; TransferFunction[] _transferFunctions = new TransferFunction[3] { TransferFunction.None, TransferFunction.Sigmoid, TransferFunction.Linear }; BackPropagationNetwork _bpn = new BackPropagationNetwork(_layerSizes, _transferFunctions); SimpleNetworkTrainer _networkTrainer = new SimpleNetworkTrainer(_bpn, _dataPointCollection); _networkTrainer.TargetError = 0.0001; _networkTrainer.MaxIterations = 1000000; _networkTrainer.NudgeScale = 0.8; _networkTrainer.NudgeWindow = 100; _networkTrainer.TrainNetwork(); Assert.IsTrue(true, "Never Reached Minimum Error"); for (int i = _networkTrainer.ErrorHistory.Count - 100; i < _networkTrainer.ErrorHistory.Count; i++) { Console.WriteLine("{0}: {1:0.00000000}", i, _networkTrainer.ErrorHistory[i]); } }
public ChartLineUC(DataPointCollection DataPoints, string str, string strtitle) { InitializeComponent(); chartC.DataPointWidth = 2; Title title = new Title(); title.Text = strtitle; chartC.Titles.Add(title); chartC.Series[0].DataPoints = DataPoints; chartC.Series[0].LegendText = str; chartC.Series[0].ShowInLegend = true; chartC.Series[0].ToolTipText = string.Format("名称:#AxisXLabel {0}数值:#YValue {0}", System.Environment.NewLine); chartC.Series[0].AutoFitToPlotArea = true; chartC.Series[0].LabelEnabled = false; chartC.Series[0].Bevel = false; chartC.Series[0].ShadowEnabled = true; chartC.Series[0].YValueFormatString = "######.## "; chartC.Series[0].LightingEnabled = true; chartC.Series[0].LabelText = " #AxisXLabel"; chartC.Series[0].LabelFontSize = 13; chartC.Series[0].IncludePercentageInLegend = true; }
private double[] findRange(DataPointCollection collection) { double[] range = new double[4]; double minX=0, maxX=0, minY=0, maxY=0; int i = 0; foreach (DataPoint item in collection) { if (i==0) { minX = item.XValue; maxX = item.XValue; minY = item.YValues[0]; maxY = item.YValues[0]; i++; } if (minX>item.XValue) { minX = item.XValue; } if (maxX<item.XValue) { maxX = item.XValue; } if (minY>item.YValues[0]) { minY = item.YValues[0]; } if (maxY<item.YValues[0]) { maxY = item.YValues[0]; } } range[0] = minX; range[1] = maxX; range[2] = minY; range[3] = maxY; return range; }
public BasicNeuralNetworkTrainerWrapper(DataPointCollection dataSet) { DataSet = dataSet; int[] layerSizes = new int[10] { DataSet.DataPointBound, 5, 5, 5, 5, 5, 5, 5, 3, 1 }; TransferFunction[] transferFunctions = new TransferFunction[10] { TransferFunction.None, TransferFunction.RationalSigmoid, TransferFunction.RationalSigmoid, TransferFunction.Sigmoid, TransferFunction.Sigmoid, TransferFunction.Sigmoid, TransferFunction.Sigmoid, TransferFunction.Gaussian, TransferFunction.Gaussian, TransferFunction.Linear }; Network.Initialize(layerSizes, transferFunctions); _network = new BackPropagationNetwork(layerSizes, transferFunctions); _networkTrainer = new SimpleNetworkTrainer(_network, DataSet); }
// workaround as per http://stackoverflow.com/questions/5744930/datapointcollection-clear-performance private static void ClearPointsQuick(DataPointCollection points) { points.SuspendUpdates(); while (points.Count > 0) points.RemoveAt(points.Count - 1); points.ResumeUpdates(); }
private static CategoricalDataPoint GetDataPoint(DataPointCollection<CategoricalDataPoint> dataPoints, object xCategory) { foreach (var dp in dataPoints) { if (object.Equals(xCategory, dp.Category)) { return dp; } } return null; }
/// <summary> /// Extracts the <see cref="Point"/>s from a collection. /// </summary> /// <param name="dataSource">The data source (can be <see langword="null"/>).</param> /// <param name="xyPath">The binding path for the (x, y) value.</param> /// <param name="culture"> /// The <see cref="CultureInfo"/> object that provides culture-specific formatting /// information. /// </param> /// <returns>The chart data as a list of data points.</returns> private static IList<DataPoint> ExtractPointsFromCollection(IEnumerable dataSource, PropertyPath xyPath, CultureInfo culture) { var pointValueExtractor = new PointValueExtractor { Collection = dataSource, Culture = culture, ValuePath = xyPath, }; var points = pointValueExtractor.Extract(); int index = 0; var chartDataSource = new DataPointCollection(); foreach (var data in dataSource) { chartDataSource.Add(new DataPoint(points[index], data)); index++; } return chartDataSource; }
private string GetCSV(DataPointCollection dpc) { var s = (from a in dpc where a.YValues.Length > 0 select a.YValues[0].ToString()); return s.Aggregate((a, b) => a + "," + b); }
/// <summary> /// Extracts the points from collection. /// </summary> /// <param name="dataSource">The data source (can be <see langword="null"/>).</param> /// <param name="xPath">The binding path for the x value.</param> /// <param name="yPath">The binding path for the y value.</param> /// <param name="xLabels"> /// The collection of text labels used for x values. Can be <see langword="null"/>. This /// parameter is only relevant when one chart axis shows text labels and the data source /// contains <see cref="String"/> values instead of <see cref="Double"/> values. /// </param> /// <param name="yLabels"> /// The collection of text labels used for y values. Can be <see langword="null"/>. This /// parameter is only relevant when one chart axis shows text labels and the data source /// contains <see cref="String"/> values instead of <see cref="Double"/> values. /// </param> /// <param name="culture"> /// The <see cref="CultureInfo"/> object that provides culture-specific formatting /// information. /// </param> /// <returns>The chart data as a list of data points.</returns> private static IList<DataPoint> ExtractPointsFromCollection( IEnumerable dataSource, PropertyPath xPath, PropertyPath yPath, CultureInfo culture, IList<TextLabel> xLabels, IList<TextLabel> yLabels) { var xValueExtractor = new DoubleValueExtractor { Collection = dataSource, Culture = culture, TextLabels = xLabels, ValuePath = xPath, }; var xValues = xValueExtractor.Extract(); var yValueExtractor = new DoubleValueExtractor { Collection = dataSource, Culture = culture, TextLabels = yLabels, ValuePath = yPath, }; var yValues = yValueExtractor.Extract(); Debug.Assert(xValues.Count == yValues.Count, "Number of x values in data source does not match the number of y values?!"); int index = 0; var chartDataSource = new DataPointCollection(); foreach (var data in dataSource) { chartDataSource.Add(new DataPoint(xValues[index], yValues[index], data)); index++; } return chartDataSource; }
public Series() { Points = new DataPointCollection(); }
private Program() { _volStdDev = new DataPointCollection(); _vols = new List<DataPoint>(); }
private void AddToSeries(DataPointCollection points, int[] values) { for (int i = 0; i < values.Length; ++i) points.AddXY(i, values[i]); }
public AutoRegressiveTrainer(BackPropagationNetwork network, DataPointCollection dataSet) : base(network, dataSet) { lastOutput = new double[dataSet.Count]; }
public SimpleNetworkTrainer(BackPropagationNetwork network, DataPointCollection dataSet) : base(network, dataSet) { }
private void CallOnChangePoint(DataPointCollection points) { if (null != OnChangePoints) { var lst = new List<KeyValuePair<float, float>>(); foreach (var point in points) { lst.Add(new KeyValuePair<float, float>((float)point.XValue, (float)point.YValues[0])); } OnChangePoints(lst); } }
public void ConvolutionNetwork() { int[] layerSizes = new int[5] { 841, 1014, 1250, 100, 10 }; TransferFunction[] transferFunctions = new TransferFunction[5] { TransferFunction.None, TransferFunction.Convolution, TransferFunction.Convolution, TransferFunction.Linear, TransferFunction.Linear }; BackPropagationNetwork backPropagationNetwork = new BackPropagationNetwork(layerSizes, transferFunctions); double[] input1 = new double[841]; for (int i = 0; i < input1.Length; i++) { if(i % 2 == 0) input1[i] = 1; } double[] input2 = new double[841]; for (int i = 0; i < input2.Length; i++) { input2[i] = 1; } DataPoint _dp1 = new DataPoint(input1, new[] { 1.0 }); DataPoint _dp2 = new DataPoint(input2, new[] { 0.0 }); DataPointCollection _dataPointCollection = new DataPointCollection(); _dataPointCollection.Add(_dp1); _dataPointCollection.Add(_dp2); SimpleNetworkTrainer _networkTrainer = new SimpleNetworkTrainer(backPropagationNetwork, _dataPointCollection); _networkTrainer.TargetError = 0.0001; _networkTrainer.MaxIterations = 1000000; _networkTrainer.NudgeScale = 0.8; _networkTrainer.NudgeWindow = 100; _networkTrainer.TrainNetwork(); Assert.IsTrue(true, "Never Reached Minimum Error"); for (int i = _networkTrainer.ErrorHistory.Count - 100; i < _networkTrainer.ErrorHistory.Count; i++) { Console.WriteLine("{0}: {1:0.00000000}", i, _networkTrainer.ErrorHistory[i]); } }
private void GetMinAndMax(DataPointCollection<CategoricalDataPoint> dataPoints, out double min, out double max) { min = double.NaN; max = double.NaN; foreach (CategoricalDataPoint dp in dataPoints) { if (dp.Value.HasValue) { if (double.IsNaN(min) || dp.Value.Value < min) { min = dp.Value.Value; } if (double.IsNaN(max) || max < dp.Value.Value) { max = dp.Value.Value; } } } if (double.IsNaN(min) || double.IsNaN(max)) { return; } double expansion = (max - min) / 10; min -= expansion; max += expansion; if (min >= 0 && 0.16 < (max - min) / max) { min = 0; } }
private void PopulatePoints(DataPointCollection points, Random rand) { foreach (var i in Enumerable.Range(0, 100)) { points.Add(GetRandomPoint(i, rand)); } }