Exemplo n.º 1
1
        // 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);
        }
Exemplo n.º 2
0
        public void DrawGoodArea()
        {
            if (RK.ST.result == null)
            {
                return;
            }
            SumResult sumResult = RK.ST.result.Sum;

            cbGoodBad.Checked = sumResult.RClass == EClass.Brak;
            cbGoodBad_CheckedChanged(null, null);
            cbGoodBad.Enabled = true;
            mp1.Clear();
            SumResult.PP pp = sumResult.MaxGood;
            if (pp == null)
            {
                return;
            }
            double pos = pp.index;

            pos *= K;
            mp1.Add(new DataPoint(pos, 1.2));
            pos  = pp.index + pp.count;
            pos *= K;
            mp1.Add(new DataPoint(pos, 1.2));
        }
Exemplo n.º 3
0
        public void AddPoint(float xValue, float yValue, object tag)
        {
            var t = new DataPoint(xValue, yValue);

            t.Tag = tag;
            points.Add(t);
        }
    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);
    }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        // 显示 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);
            }
        }
Exemplo n.º 7
0
 internal void Draw(SumResult _sumResult)
 {
     Clear();
     for (int i = 0; i < _sumResult.MClass.Count(); i++)
     {
         mp.Add(1).Color = Classer.GetColor(_sumResult.MClass[i]);
     }
 }
Exemplo n.º 8
0
        public void Load(Meas[] _MMeas, double _gain, SignalViewPars _pars, Color _color_dead, double[] _borders, bool _IsOn)
        {
            pars = _pars;
            IsOn = _IsOn;
            DataPointCollection pp = series.Points;

            pp.Clear();
            box.Visible    = IsOn;
            series.Enabled = IsOn;
            bline.Visible  = IsOn;
            bline1.Visible = IsOn;
            if (!IsOn)
            {
                return;
            }

            series.Color   = _pars.SColor;
            series.Enabled = _pars.View;
            box.Checked    = _pars.View;
            box.ForeColor  = _pars.View ? _pars.SColor : Color.Black;
            if (_MMeas == null)
            {
                return;
            }
            for (int i = 0; i < _MMeas.Length; i++)
            {
                double v = 0;
                Meas   m = _MMeas[i];
                switch (type)
                {
                case EType.Source:
                    v = m.Source;
                    break;

                case EType.Median:
                    v = m.Median;
                    break;

                case EType.Filter:
                    v = m.Filter;
                    break;

                case EType.FilterIn:
                    v = -m.FilterIn;
                    break;
                }
                v *= _gain;
                DataPoint p = new DataPoint(i, v);
                p.Color = m.Dead ? _color_dead : _pars.SColor;
                pp.Add(p);
            }
            bline.SetBorders(_borders);
            bline.Visible = box.Checked;
            bline1.SetBorders(new double[2] {
                -_borders[0], -_borders[1]
            });
            bline1.Visible = box.Checked;
        }
        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);
        }
Exemplo n.º 10
0
    // Adds a new point to the end of the collection, with a spedified y and
    // a value of x that is dx larger than the last value.
    public static void AddDXY(this DataPointCollection points, double dx, double y)
    {
        double x = 0.0;     // Default starting x if there are no points in the collection.

        if (points.Count() > 0)
        {
            x = points.Last().XValue + dx;
        }
        points.Add(new DataPoint(x, y));
    }
Exemplo n.º 11
0
        public DataPointCollection getDataPoints_温湿度_湿度()
        {
            DataPointCollection datapoints = new DataPointCollection();

            foreach (LightDataPoint x in List_datapoint_温湿度_湿度)
            {
                datapoints.Add(x);
            }
            return(datapoints);
        }
 void CreateCartesianFoliumPoints()
 {
     for (int i = -30; i < 125; i += 5)
     {
         double t = Math.Tan((double)i / 180 * Math.PI);
         double x = 3 * (double)a * t / (t * t * t + 1);
         double y = x * t;
         cartesianFolium.Add(new DataPoint(x, y));
     }
 }
 void CreateArchimedianSpiralPoints()
 {
     for (int i = 0; i < 720; i += 15)
     {
         double t = (double)i / 180 * Math.PI;
         double x = t * Math.Cos(t);
         double y = t * Math.Sin(t);
         archimedianSpiral.Add(new DataPoint(x, y));
     }
 }
 void CreateCardioidPoints()
 {
     for (int i = 0; i < 360; i += 10)
     {
         double t = (double)i / 180 * Math.PI;
         double x = a * (2 * Math.Cos(t) - Math.Cos(2 * t));
         double y = a * (2 * Math.Sin(t) - Math.Sin(2 * t));
         cardioid.Add(new DataPoint(x, y));
     }
 }
Exemplo n.º 15
0
 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;
 }
        protected void UpdatePointsData2(DataPointCollection points, uint count, double t_time)
        {
            if (points.Count > _maxPoints2)
            {
                points.RemoveAt(0);
            }

            points.Add(new DataPoint()
            {
                AxisXLabel = count.ToString(),
                YValue     = t_time
            });
        }
        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]);
            }
        }
Exemplo n.º 18
0
        public void DrawGoodArea()
        {
            if (RK.ST.result == null)
            {
                return;
            }
            SumResult sumResult = RK.ST.result.Sum;

            uSelectResult1.Enabled = true;
            uSelectResult1.RClass  = sumResult.RClass;
            mp1.Clear();
            SumResult.PP pp = sumResult.MaxGood;
            if (pp == null)
            {
                return;
            }
            double pos = pp.index;

            pos *= K;
            mp1.Add(new DataPoint(pos, 1.2));
            pos  = pp.index + pp.count;
            pos *= K;
            mp1.Add(new DataPoint(pos, 1.2));
        }
Exemplo n.º 19
0
        internal void Draw()
        {
            SumResult sumResult = RK.ST.result.Sum;

            Clear();
            for (int i = 0; i < sumResult.MClass.Count(); i++)
            {
                double pos = i;
                pos *= K;
                pos += 0.5 * K;
                DataPoint p = new DataPoint(pos, 1);
                p.Color = Classer.GetColor(sumResult.MClass[i]);
                mp.Add(p);
            }
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        private void updateChart(String seriesName)
        {
            Series    series;
            ChartArea area;
            int       idNr;

            if (seriesName == "Camera")
            {
                series = cameraChart.Series["Camera"];
                area   = cameraChart.ChartAreas["cArea"];
                idNr   = 0;
            }
            else //seriesName == Glyph
            {
                series = glyphChart.Series["Glyph"];
                area   = glyphChart.ChartAreas["cArea"];
                idNr   = 1;
            }

            DataPointCollection points = series.Points;

            if (points.Count() >= dataPoints[idNr].Count())
            {
                dataPoints[idNr].Add(new DataPoint(DateTime.Now.ToOADate(), 0));
            }

            for (int i = points.Count(); i < dataPoints[idNr].Count(); i++)
            {
                points.Add(dataPoints[idNr].ElementAt(i));
            }

            area.AxisX.IntervalType      = DateTimeIntervalType.Seconds;
            area.AxisX.Interval          = 5;
            area.AxisX.LabelStyle.Format = "ss";
            area.AxisX.Minimum           = DateTime.Now.AddMinutes(-1).ToOADate();

            if (idNr == 0)
            {
                cameraValue.Text = points.Last().YValues[0].ToString();
            }
            else
            {
                glyphValue.Text = points.Last().YValues[0].ToString();
            }
        }
        /// <summary>
        /// This routine populates the main chart
        /// </summary>
        public void PopulateChart()
        {
            try
            {
                // Create a new instance of DataSeries
                var dataSeries = new DataSeries
                {
                    RenderAs      = RenderAs.QuickLine,
                    LineStyle     = LineStyles.Solid,
                    LineThickness = 1
                };

                var blueBrush = new SolidColorBrush {
                    Color = Colors.Blue
                };

                dataSeries.Color            = blueBrush;
                dataSeries.MarkerEnabled    = false;
                dataSeries.SelectionEnabled = true;
                dataSeries.SelectionMode    = SelectionModes.Multiple;
                dataSeries.LightWeight      = true;

                var collection = new DataPointCollection();

                // Create a DataPoint
                for (int point = 0; point < this.numberofpoints; point++)
                {
                    collection.Add(new DataPoint {
                        YValue = this.intensitypoints[point], XValue = point
                    });
                }

                dataSeries.DataPoints = new DataPointCollection();
                dataSeries.DataPoints = collection;

                IntensityChart.Series.Add(dataSeries);
            }
            catch (Exception e)
            {
                Util.ReportException(e);
            }
        }
Exemplo n.º 23
0
        public void RDraw()
        {
            Clear();
            if (RK.ST.result == null)
            {
                return;
            }
            ResultThickLite rs = RK.ST.result.Thick;

            if (rs == null)
            {
                return;
            }
            if (rs.MZone == null)
            {
                return;
            }
            double?level = null;

            for (int i = 0; i < rs.MZone.Count; i++)
            {
                BankLib.BankZoneThick z = rs.MZone[i];
                double lLevel           = z.Level == null ? rs.MaxThickness : z.Level.Value;
                mp.Add(lLevel).Color = Classer.GetColor(z.RClass);
                if (z.Level != null)
                {
                    if (level == null)
                    {
                        level = z.Level.Value;
                    }
                    else
                    {
                        if (z.Level.Value < level)
                        {
                            level = z.Level.Value;
                        }
                    }
                }
            }
            uMinThick1.MinThick = level;
        }
Exemplo n.º 24
0
        public SeriasForChart GetSeriasForChart(bool forWeek, DateTime currentDay)
        {
            var goodDreamPoints = new DataPointCollection();
            var badDreamPoints  = new DataPointCollection();
            var freecPoints     = new DataPointCollection();


            var period        = forWeek ? GetCurrentWeek(currentDay) : new List <DateTime>();
            var formatedDates = period.Select(day => new DateTime(day.Year, day.Month, day.Day).ToString("d")).ToList();
            var statistics    = _dreamCalendarRepository.GetQuery(x => formatedDates.Contains(x.Date)).ToList();

            for (var i = 0; i < period.Count; i++)
            {
                goodDreamPoints.Add(new DataPoint
                {
                    Label = DreamBookDataConstants.WeekNames[period[i].DayOfWeek],
                    Value = statistics.Any(x => x.Date == period[i].ToString("d"))
                        ? statistics.FirstOrDefault(x => x.Date == period[i].ToString("d")).GoodDreamValue
                        : 1
                });
                badDreamPoints.Add(new DataPoint
                {
                    Label = DreamBookDataConstants.WeekNames[period[i].DayOfWeek],
                    Value = statistics.Any(x => x.Date == period[i].ToString("d"))
                        ? statistics.FirstOrDefault(x => x.Date == period[i].ToString("d")).BadDreamValue
                        : 1
                });
                freecPoints.Add(new DataPoint
                {
                    Label = DreamBookDataConstants.WeekNames[period[i].DayOfWeek],
                    Value = i >= 5 ? 5 : i
                });
            }
            return(new SeriasForChart
            {
                BadDreamPoints = badDreamPoints,
                GoodDreamPoints = goodDreamPoints,
                FreecPoints = freecPoints
            });
        }
Exemplo n.º 25
0
        internal void Draw()
        {
            Clear();
            if (RK.ST.result == null)
            {
                return;
            }
            uTube.Value = RK.ST.result.IdTube.ToString();
            SumResult sumResult = RK.ST.result.Sum;

            for (int i = 0; i < sumResult.MClass.Count(); i++)
            {
                double pos = i;
                pos *= K;
                pos += 0.5 * K;
                DataPoint p = new DataPoint(pos, 1);
                p.Color = Classer.GetColor(sumResult.MClass[i]);
                mp.Add(p);
            }
            uSelectResult1.RClass = sumResult.RClass;
            //uSelectResult1.Enabled = true;
        }
Exemplo n.º 26
0
        /// <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;
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DesignerDataPointCollection ddpc = value as DesignerDataPointCollection;
            DataPointCollection         dc   = new DataPointCollection();

            foreach (DesignerDataPoint dp in ddpc)
            {
                DataPoint newDp = new DataPoint();
                newDp.Uid  = dp.ID.ToString();
                newDp.Name = dp.Name;
                newDp.SetBinding(DataPoint.AxisXLabelProperty, new Binding("AxisXLabel")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.BorderColorProperty, new Binding("LabelBorder.BorderBrush")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.BorderStyleProperty, new Binding("BorderStyle")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.BorderThicknessProperty, new Binding("LabelBorder.BorderThickness")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.ColorProperty, new Binding("Color")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.EnabledProperty, new Binding("Enabled")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelAngleProperty, new Binding("LabelAngle")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelBackgroundProperty, new Binding("LabelBackground")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelEnabledProperty, new Binding("LabelEnabled")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelFontColorProperty, new Binding("LabelFont.FontColor")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelFontFamilyProperty, new Binding("LabelFont.FontFamily")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelFontSizeProperty, new Binding("LabelFont.FontSize")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelFontStyleProperty, new Binding("LabelFont.FontStyle")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelFontWeightProperty, new Binding("LabelFont.FontWeight")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelLineColorProperty, new Binding("LabelLineColor")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelLineEnabledProperty, new Binding("LabelLineEnabled")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelLineStyleProperty, new Binding("LabelLineStyle")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelLineThicknessProperty, new Binding("LabelLineThickness")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelStyleProperty, new Binding("LabelStyle")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LabelTextProperty, new Binding("LabelText")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LegendMarkerColorProperty, new Binding("LegendMarkerColor")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LegendMarkerTypeProperty, new Binding("LegendMarkerType")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LegendTextProperty, new Binding("LegendText")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.LightingEnabledProperty, new Binding("LightingEnabled")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.MarkerBorderColorProperty, new Binding("MarkerBorderColor")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.MarkerBorderThicknessProperty, new Binding("MarkerBorderThickness")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.MarkerColorProperty, new Binding("MarkerColor")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.MarkerEnabledProperty, new Binding("MarkerEnabled")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.MarkerScaleProperty, new Binding("MarkerScale")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.MarkerSizeProperty, new Binding("MarkerSize")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.MarkerTypeProperty, new Binding("MarkerType")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.OpacityProperty, new Binding("DataPointOpacity")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.RadiusXProperty, new Binding("RadiusX")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.RadiusYProperty, new Binding("RadiusY")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.ShadowEnabledProperty, new Binding("ShadowEnabled")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.ShowInLegendProperty, new Binding("ShowInLegend")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.StickColorProperty, new Binding("StickColor")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.XValueProperty, new Binding("XValue")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.YValueProperty, new Binding("YValue")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.YValuesProperty, new Binding("YValues")
                {
                    Source = dp
                });
                newDp.SetBinding(DataPoint.ZValueProperty, new Binding("ZValue")
                {
                    Source = dp
                });

                dc.Add((IDataPoint)newDp);
            }
            return(dc);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Updates histogram window.
        /// </summary>
        public void UpdateHistogram()
        {
            if (PictureBox != null)
            {
                updating = true;
                try
                {
                    IReadOnlyList <PointF> histogram = PictureBox.Histogram;

                    DataPointCollection points = chartHist.Series[0].Points;
                    while (points.Count < histogram.Count)
                    {
                        points.Add(0);
                    }

                    List <double> counts = new List <double>();

                    double max = 0;
                    for (int n = 0; n < histogram.Count; n++)
                    {
                        points[n].XValue     = histogram[n].X;
                        points[n].YValues[0] = histogram[n].Y;
                        counts.Add(histogram[n].Y);
                        if (histogram[n].Y > max)
                        {
                            max = histogram[n].Y;
                        }
                    }

                    chartHist.ChartAreas[0].AxisY.Maximum = Percentile(counts.ToArray(), 0.995);

                    if (checkFullRange.Checked)
                    {
                        // Range from DynamicMin to DynamicMax
                        rangeMin = PictureBox.DynamicMin;
                        rangeMax = PictureBox.DynamicMax;
                    }
                    else
                    {
                        // Range from GlobalMin to GlobalMax
                        rangeMin = PictureBox.GlobalMin;
                        rangeMax = PictureBox.GlobalMax;
                    }

                    //float minVal = PictureBox.Min;
                    //float maxVal = PictureBox.Max;

                    //rangeMin = Math.Min(rangeMin, minVal);
                    //rangeMax = Math.Max(rangeMax, maxVal);

                    if (rangeMin >= rangeMax)
                    {
                        rangeMax = rangeMin + 1;
                    }

                    chartHist.ChartAreas[0].AxisX.Minimum = rangeMin;
                    chartHist.ChartAreas[0].AxisX.Maximum = rangeMax;

                    scrollMinimum.Maximum = Math.Max(256, (int)(rangeMax - rangeMin)) + scrollMinimum.LargeChange;
                    scrollMaximum.Maximum = scrollMinimum.Maximum;

                    SetScrollBarValue(scrollMinimum, PictureBox.Min);
                    SetScrollBarValue(scrollMaximum, PictureBox.Max);
                    UpdateLabels();
                }
                finally
                {
                    updating = false;
                }
            }
        }
 private void PopulatePoints(DataPointCollection points, Random rand)
 {
     foreach (var i in Enumerable.Range(0, 100))
     {
         points.Add(GetRandomPoint(i, rand));
     }
 }
Exemplo n.º 30
0
        public void InitRange(ResultDef _resultDef, int _iz0, int _iz1, int _is, double _gain)
        {
            chart1.Series.SuspendUpdates();
            Clear();
            TypeSize ts = ParAll.ST.TSSet.Current;

            resultDef = _resultDef;
            iz0       = _iz0;
            iz1       = _iz1;
            ise       = _is;
            Color DeviderColor      = ParAll.ST.Some.SignalsView.DeviderColor;
            DataPointCollection p   = chart1.Series[0].Points;
            DataPointCollection pIn = chart1.Series[0].Points;
            int ip     = 0;
            int ipIn   = 0;
            int istrip = 0;

            chart1.ChartAreas[0].AxisX.StripLines.Clear();
            DefCL dcl  = new DefCL(_resultDef.Tp);
            bool  IsIn = dcl.IsFinterIn;

            for (int ii = _iz0; ii <= _iz1; ii++)
            {
                Meas[] MMeas = _resultDef.MZone[ii].MSensor[ise].MMeas;
                if (istrip > 0)
                {
                    StripLine sl = new StripLine();
                    sl.BorderColor    = DeviderColor;
                    sl.BorderWidth    = 2;
                    sl.IntervalOffset = ip;
                    chart1.ChartAreas[0].AxisX.StripLines.Add(sl);
                }
                istrip++;
                for (int i = 0; i < MMeas.Length; i++)
                {
                    Meas      m  = MMeas[i];
                    DataPoint dp = new DataPoint(ip, m.FilterABC * _gain);
                    dp.Color = m.Dead ? Classer.GetColor(EClass.None) : Classer.GetColor(m.Class);
                    dp.Tag   = new PointSubj(ii, ise, i);
                    p.Add(dp);
                    ip++;
                    if (IsIn)
                    {
                        pIn.AddXY(ipIn, -m.FilterInABC * _gain);
                        p[ipIn].Color = m.Dead ? Classer.GetColor(EClass.None) : Classer.GetColor(m.ClassIn);
                        ipIn++;
                    }
                }
                istrip++;
            }
            if (bline != null)
            {
                bline.Visible = false;
            }
            if (blineIn != null)
            {
                blineIn.Visible = false;
            }
            bline   = new BorderLine(chart1.ChartAreas[0].AxisY, Classer.GetColor(EClass.Brak), Classer.GetColor(EClass.Class2));
            blineIn = new BorderLine(chart1.ChartAreas[0].AxisY, Classer.GetColor(EClass.Brak), Classer.GetColor(EClass.Class2));
            bline.SetBorders(dcl.Borders);
            bline.Visible = true;

            if (IsIn)
            {
                double[] borders = new double[2];
                borders[0] = -dcl.Border1In;
                borders[1] = -dcl.Border2In;
                blineIn.SetBorders(borders);
                blineIn.Visible = true;
            }
            chart1.ChartAreas[0].AxisY.Maximum = 100;
            if (IsIn)
            {
                chart1.ChartAreas[0].AxisY.Minimum = -100;
            }
            else
            {
                chart1.ChartAreas[0].AxisY.Minimum = 0;
            }
            if (cursor.Visible)
            {
                OnMove(cursor.Position);
            }
            chart1.Series[0].Enabled = true;
            chart1.Series[1].Enabled = IsIn;
            chart1.Series.ResumeUpdates();
        }
        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]);
            }
        }
Exemplo n.º 32
0
        private void TestAllSABTN_Click(object sender, EventArgs e)
        {
            ShowPoint.Clear();

            NowQueenSolve = Form1.ThisQueenSolve;
            NowQueenSolve.ChessLocationList = Form1.QueenChessLocation;

            NowQueenSolve.QueenLocationList = new List <Point>();
            for (int i = 0; i < 8; i++)
            {
                NowQueenSolve.QueenLocationList.Add(new Point(i, NowQueenSolve.EightQueenResult[0, i] - 1));
            }

            double InitTemp = 0, alpha = 0, SALenght = 0;

            try
            {
                InitTemp = Convert.ToDouble(InitTempTB.Text);
                alpha    = Convert.ToDouble(AlphaTB.Text);
                SALenght = Convert.ToDouble(SALenghtTB.Text);
            }
            catch (Exception)
            {
                throw;
            }

            Chart1.Series[0].ChartType                        = SeriesChartType.Point;
            Chart1.Series[0].IsValueShownAsLabel              = true;
            Chart1.Series[0].MarkerSize                       = 6;
            Chart1.Series[0].ToolTip                          = "第#VALX组八皇后的解\r\n寻优后的最短路径为:#VAL";
            Chart1.ChartAreas[0].AxisY.Maximum                = 55;
            Chart1.ChartAreas[0].AxisY.Minimum                = 30;
            Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled      = true;
            Chart1.ChartAreas[0].AxisY.MinorGrid.Enabled      = false;
            Chart1.ChartAreas[0].AxisY.MajorGrid.Interval     = 100;
            Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled      = true;
            Chart1.ChartAreas[0].AxisX.MajorGrid.Interval     = 1;
            Chart1.ChartAreas[0].AxisX.MinorGrid.Enabled      = false;
            Chart1.ChartAreas[0].AxisX.MajorTickMark.Interval = 5;
            Chart1.ChartAreas[0].AxisX.MinorTickMark.Interval = 1;


            //NowQueenSolve.InitSA(InitTemp, alpha, SALenght, 0, SimulateAnneal.Annealing.SAMode.SA);
            NowQueenSolve.InitSA(1000, 0.9, 90, 0.1, SimulateAnneal.Annealing.SAMode.FastSA);
            //NowQueenSolve.InitSA(1000, 0.9, 90, 0, SimulateAnneal.Annealing.SAMode.SA);

            List <Point> BestResult_QueenLocation = new List <Point>();
            List <int>   MoveSequence             = new List <int>();
            double       disall                   = 0;

            MoveSequence = NowQueenSolve.SearchResult_ForOverall(ref disall, ref BestResult_QueenLocation, ShowPoint);

            #region 92组解评估
            List <double> ResultEve = new List <double>();
            ResultEve = NowQueenSolve.QueenResultEvaluation();

            ShowPoint2.Clear();
            for (int i = 0; i < 92; i++)
            {
                ShowPoint2.Add(new DataPoint(i, ResultEve[i]));
            }
            #endregion

            InfoPrintTB.Text  = "模拟退火参数:" + System.Environment.NewLine;
            InfoPrintTB.Text += "T0 = " + InitTemp.ToString() + System.Environment.NewLine;
            InfoPrintTB.Text += "a = " + alpha.ToString() + System.Environment.NewLine;
            InfoPrintTB.Text += "L = " + SALenght.ToString() + System.Environment.NewLine;
            InfoPrintTB.Text += "本次最优距离为:" + System.Environment.NewLine;
            InfoPrintTB.Text += disall.ToString() + System.Environment.NewLine;
        }
Exemplo n.º 33
0
        void Charting(DataPointCollection Point, int N, int i)
        {
            double AccX = AccXList[i];
            double AccY = AccYList[i];
            double AccZ = AccZList[i];

            TiltXAccel = 0;

            if (!((AccY == 0) && (AccZ == 0)))
            {
                TiltXAccel = Math.Atan(AccX / (Math.Sqrt(AccY * AccY + AccZ * AccZ))) * 57.296;
            }

            TiltYAccel = 0;
            if (!((AccY == 0) && (AccZ == 0)))
            {
                TiltYAccel = Math.Atan(AccY / (Math.Sqrt(AccX * AccX + AccZ * AccZ))) * 57.296;
            }


            switch (N)
            {
            case 0:
                Point.Add(AccXList[i]);
                break;

            case 1:
                Point.Add(AccYList[i]);
                break;

            case 2:
                Point.Add(AccZList[i]);
                break;

            case 3:
                Point.Add(GyroXList[i]);
                break;

            case 4:
                Point.Add(GyroYList[i]);
                break;

            case 5:
                Point.Add(GyroZList[i]);
                break;

            case 6:
                Point.Add(TiltXList[i]);
                break;

            case 7:
                Point.Add(TiltYList[i]);
                break;

            case 8:
                Point.Add(TiltXAccel);
                break;

            case 9:
                Point.Add(TiltYAccel);
                break;
            }
        }
Exemplo n.º 34
0
        /// <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;
        }
Exemplo n.º 35
0
        DataPointCollection ShowPoint2; ///用来显示的点集2

        private void SATest1BTN_Click(object sender, EventArgs e)
        {
            NowQueenSolve = Form1.ThisQueenSolve;
            NowQueenSolve.ChessLocationList = Form1.QueenChessLocation;

            NowQueenSolve.QueenLocationList = new List <Point>();
            for (int i = 0; i < 8; i++)
            {
                NowQueenSolve.QueenLocationList.Add(new Point(i, NowQueenSolve.EightQueenResult[0, i] - 1));
            }

            SimulateAnneal.Annealing.SAMode UsedSAMode = SimulateAnneal.Annealing.SAMode.SA;
            double InitTemp = 0, alpha = 0, SALenght = 0, FSAh = 0;
            int    TestNum = 0;

            try
            {
                InitTemp = Convert.ToDouble(InitTempTB.Text);
                alpha    = Convert.ToDouble(AlphaTB.Text);
                SALenght = Convert.ToDouble(SALenghtTB.Text);
                FSAh     = Convert.ToDouble(FSAhTB.Text);
                TestNum  = Convert.ToInt32(TestNumSetTB.Text);

                if (SAModeSetTB.SelectedIndex == 0)//SA
                {
                    UsedSAMode = SimulateAnneal.Annealing.SAMode.SA;
                }
                else
                {
                    UsedSAMode = SimulateAnneal.Annealing.SAMode.FastSA;
                }
            }
            catch (Exception)
            {
                throw;
            }

            Chart1.Series[0].ChartType           = SeriesChartType.Line;
            Chart1.Series[0].MarkerSize          = 0;
            Chart1.Series[0].IsValueShownAsLabel = false;
            Chart1.Series[0].ToolTip             = "第#VALX次模拟退火中\r\n局部最短路径为:#VAL";
            //Chart1.ChartAreas[0].AxisY.Maximum = 1;
            //Chart1.ChartAreas[0].AxisY.Minimum = 30;
            Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled      = false;
            Chart1.ChartAreas[0].AxisY.MinorGrid.Enabled      = false;
            Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled      = false;
            Chart1.ChartAreas[0].AxisX.MinorGrid.Enabled      = false;
            Chart1.ChartAreas[0].AxisX.MajorTickMark.Interval = 5;
            Chart1.ChartAreas[0].AxisX.MinorTickMark.Interval = 1;

            Chart1.Series[1].ChartType           = SeriesChartType.Line;
            Chart1.Series[1].MarkerSize          = 0;
            Chart1.Series[1].IsValueShownAsLabel = false;
            Chart1.Series[1].ToolTip             = "第#VALX次模拟退火中\r\n局部最短路径为:#VAL";

            string TestStr = NowQueenSolve.Test_SAParameter(
                InitTemp, alpha, SALenght, FSAh, UsedSAMode, TestNum);

            ShowPoint.Clear();

            List <double> DisList = NowQueenSolve.TestDisList.ToList();
            List <double> UsedTimeList = NowQueenSolve.TestUsedTime.ToList();

            for (int i = 0; i < NowQueenSolve.TestDisList.Count; i++)
            {
                ShowPoint.Add(new DataPoint(i, DisList[i]));
            }
            ShowPoint2.Clear();
            for (int i = 0; i < NowQueenSolve.TestUsedTime.Count; i++)
            {
                //ShowPoint2.Add(new DataPoint(i, UsedTimeList[i]));
            }

            InfoPrintTB.Text = TestStr;
        }