UpdateDataSeries() 공개 메소드

Update data series on the chart.
public UpdateDataSeries ( string name, double data ) : void
name string Data series name to update.
data double Data series values.
리턴 void
 // Clear current solution
 private void ClearSolution()
 {
     errorChart.UpdateDataSeries("error", null);
     weightsList.Items.Clear();
     currentIterationBox.Text = string.Empty;
     currentErrorBox.Text     = string.Empty;
 }
예제 #2
0
        // Update chart
        private void UpdateChart()
        {
            // update chart range
            chart.RangeX = userFunction.Range;

            double[,] data = null;

            if (chart.RangeX.Length > 0)
            {
                // prepare data
                data = new double[501, 2];

                double minX = userFunction.Range.Min;
                double length = userFunction.Range.Length;

                for (int i = 0; i <= 500; i++)
                {
                    data[i, 0] = minX + length * i / 500;
                    data[i, 1] = userFunction.OptimizationFunction(data[i, 0]);
                }
            }

            // update chart series
            chart.UpdateDataSeries("function", data);
        }
예제 #3
0
 public void ProgressUpdate(KeyValuePair <int, AccordGenetic.Wrap.Result> kvp)
 {
     // update info
     chart.UpdateDataSeries("solution", kvp.Value.Output);
     SetText(currentIterationBox, kvp.Key.ToString());
     SetText(currentValueBox, kvp.Value.BestSolution);
 }
        // Show training data on chart
        private void ShowTrainingData()
        {
            int class1Size = 0;
            int class2Size = 0;

            // calculate number of samples in each class
            for (int i = 0, n = samples; i < n; i++)
            {
                if (classes[i] == 0)
                {
                    class1Size++;
                }
                else
                {
                    class2Size++;
                }
            }

            // allocate classes arrays
            double[,] class1 = new double[class1Size, 2];
            double[,] class2 = new double[class2Size, 2];

            // fill classes arrays
            for (int i = 0, c1 = 0, c2 = 0; i < samples; i++)
            {
                if (classes[i] == 0)
                {
                    // class 1
                    class1[c1, 0] = data[i, 0];
                    class1[c1, 1] = data[i, 1];
                    c1++;
                }
                else
                {
                    // class 2
                    class2[c2, 0] = data[i, 0];
                    class2[c2, 1] = data[i, 1];
                    c2++;
                }
            }

            // updata chart control
            chart.UpdateDataSeries("class1", class1);
            chart.UpdateDataSeries("class2", class2);
        }
예제 #5
0
        // Load data
        private void loadDataButton_Click(object sender, System.EventArgs e)
        {
            // show file selection dialog
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                StreamReader reader = null;
                // read maximum 50 points
                double[] tempData = new double[50];

                try
                {
                    // open selected file
                    reader = File.OpenText(openFileDialog.FileName);
                    string str = null;
                    int    i   = 0;

                    // read the data
                    while ((i < 50) && ((str = reader.ReadLine()) != null))
                    {
                        // parse the value
                        tempData[i] = double.Parse(str);

                        i++;
                    }

                    // allocate and set data
                    data       = new double[i];
                    dataToShow = new double[i, 2];
                    Array.Copy(tempData, 0, data, 0, i);
                    for (int j = 0; j < i; j++)
                    {
                        dataToShow[j, 0] = j;
                        dataToShow[j, 1] = data[j];
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed reading the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    // close file
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }

                // update list and chart
                UpdateDataListView();
                chart.RangeX = new Range(0, data.Length - 1);
                chart.UpdateDataSeries("data", dataToShow);
                chart.UpdateDataSeries("solution", null);
                // set delimiters
                UpdateDelimiters();
                // enable "Start" button
                startButton.Enabled = true;
            }
        }
예제 #6
0
        // Generate new map for the Traivaling Salesman problem
        private void GenerateMap()
        {
            Random rand = new Random((int)DateTime.Now.Ticks);

            // create coordinates array
            map = new double[citiesCount, 2];

            for (int i = 0; i < citiesCount; i++)
            {
                map[i, 0] = rand.Next(1001);
                map[i, 1] = rand.Next(1001);
            }

            // set the map
            mapControl.UpdateDataSeries("map", map);
            // erase path if it is
            mapControl.UpdateDataSeries("path", null);
        }
예제 #7
0
        // Load data
        private void loadDataButton_Click(object sender, System.EventArgs e)
        {
            // show file selection dialog
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                data = null;

                try
                {
                    // open selected file
                    using (TextReader stream = new StreamReader(openFileDialog.FileName))
                        using (CsvReader reader = new CsvReader(stream, false))
                        {
                            data = reader.ToTable().ToMatrix(CultureInfo.InvariantCulture).GetColumn(0);
                        }
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed reading the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                dataToShow = Matrix.Stack(Vector.Range(0, data.Length).ToDouble(), data).Transpose();

                // update list and chart
                UpdateDataListView();
                chart.RangeX = new Range(0, data.Length - 1);
                chart.UpdateDataSeries("data", dataToShow);
                chart.UpdateDataSeries("solution", null);

                // set delimiters
                UpdateDelimiters();

                // enable "Start" button
                startButton.Enabled = true;
            }
        }
예제 #8
0
        // Load data
        private void loadDataButton_Click(object sender, System.EventArgs e)
        {
            // show file selection dialog
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                data = null;

                try
                {
                    // open selected file
                    using (TextReader stream = new StreamReader(openFileDialog.FileName))
                        using (CsvReader reader = new CsvReader(stream, false))
                        {
                            data = reader.ToTable().ToMatrix(CultureInfo.InvariantCulture);
                        }
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed reading the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                DoubleRange[] ranges = data.GetRange(dimension: 0);

                xRange = ranges[0];
                yRange = ranges[1];

                // update list and chart
                UpdateDataListView();
                chart.RangeX = new Range((float)xRange.Min, (float)xRange.Max);
                chart.UpdateDataSeries("data", data);
                chart.UpdateDataSeries("solution", null);

                // enable "Start" button
                startButton.Enabled = true;
            }
        }
        // Show training data on chart
        private void ShowTrainingData()
        {
            double[][,] dataSeries = new double[classesCount][, ];
            int[] indexes = new int[classesCount];

            // allocate data arrays
            for (int i = 0; i < classesCount; i++)
            {
                dataSeries[i] = new double[samplesPerClass[i], 2];
            }

            // fill data arrays
            for (int i = 0; i < samples; i++)
            {
                // get sample's class
                int dataClass = classes[i];
                // copy data into appropriate array
                dataSeries[dataClass][indexes[dataClass], 0] = data[i, 0];
                dataSeries[dataClass][indexes[dataClass], 1] = data[i, 1];
                indexes[dataClass]++;
            }

            // remove all previous data series from chart control
            chart.RemoveAllDataSeries();

            // add new data series
            for (int i = 0; i < classesCount; i++)
            {
                string className = string.Format("class" + i);

                // add data series
                chart.AddDataSeries(className, dataSereisColors[i], Chart.SeriesType.Dots, 5);
                chart.UpdateDataSeries(className, dataSeries[i]);
                // add classifier
                chart.AddDataSeries(string.Format("classifier" + i), Color.Gray, Chart.SeriesType.Line, 1, false);
            }
        }
예제 #10
0
        // Load data
        private void loadDataButton_Click(object sender, System.EventArgs e)
        {
            // show file selection dialog
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                StreamReader reader = null;
                // read maximum 50 points
                float[,] tempData = new float[50, 2];
                float minX = float.MaxValue;
                float maxX = float.MinValue;

                try
                {
                    // open selected file
                    reader = File.OpenText(openFileDialog.FileName);
                    string str = null;
                    int    i   = 0;

                    // read the data
                    while ((i < 50) && ((str = reader.ReadLine()) != null))
                    {
                        string[] strs = str.Split(';');
                        if (strs.Length == 1)
                        {
                            strs = str.Split(',');
                        }
                        // parse X
                        tempData[i, 0] = float.Parse(strs[0]);
                        tempData[i, 1] = float.Parse(strs[1]);

                        // search for min value
                        if (tempData[i, 0] < minX)
                        {
                            minX = tempData[i, 0];
                        }
                        // search for max value
                        if (tempData[i, 0] > maxX)
                        {
                            maxX = tempData[i, 0];
                        }

                        i++;
                    }

                    // allocate and set data
                    dataToShow = new double[i, 2];
                    Array.Copy(tempData, 0, dataToShow, 0, i * 2);
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed reading the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    // close file
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }

                // update list and chart
                UpdateDataListView();
                chart.RangeX = new Accord.Range(minX, maxX);
                chart.UpdateDataSeries("data", dataToShow);
                chart.UpdateDataSeries("solution", null);
                // enable "Start" button
                startButton.Enabled = true;
            }
        }
        // Load input data
        private void loadButton_Click(object sender, System.EventArgs e)
        {
            // data file format:
            // X1, X2, class

            // load maximum 10 classes !

            // show file selection dialog
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                StreamReader reader = null;

                // temp buffers (for 200 samples only)
                float[,] tempData = new float[200, 2];
                int[] tempClasses = new int[200];

                // min and max X values
                float minX = float.MaxValue;
                float maxX = float.MinValue;

                // samples count
                samples = 0;
                // classes count
                classesCount    = 0;
                samplesPerClass = new int[10];

                try
                {
                    string str = null;

                    // open selected file
                    reader = File.OpenText(openFileDialog.FileName);

                    // read the data
                    while ((samples < 200) && ((str = reader.ReadLine()) != null))
                    {
                        // split the string
                        string[] strs = str.Split(';');
                        if (strs.Length == 1)
                        {
                            strs = str.Split(',');
                        }

                        // check tokens count
                        if (strs.Length != 3)
                        {
                            throw new ApplicationException("Invalid file format");
                        }

                        // parse tokens
                        tempData[samples, 0] = float.Parse(strs[0]);
                        tempData[samples, 1] = float.Parse(strs[1]);
                        tempClasses[samples] = int.Parse(strs[2]);

                        // skip classes over 10, except only first 10 classes
                        if (tempClasses[samples] >= 10)
                        {
                            continue;
                        }

                        // count the amount of different classes
                        if (tempClasses[samples] >= classesCount)
                        {
                            classesCount = tempClasses[samples] + 1;
                        }
                        // count samples per class
                        samplesPerClass[tempClasses[samples]]++;

                        // search for min value
                        if (tempData[samples, 0] < minX)
                        {
                            minX = tempData[samples, 0];
                        }
                        // search for max value
                        if (tempData[samples, 0] > maxX)
                        {
                            maxX = tempData[samples, 0];
                        }

                        samples++;
                    }

                    // allocate and set data
                    data = new double[samples, 2];
                    Array.Copy(tempData, 0, data, 0, samples * 2);
                    classes = new int[samples];
                    Array.Copy(tempClasses, 0, classes, 0, samples);

                    // clear current result
                    weightsList.Items.Clear();
                    errorChart.UpdateDataSeries("error", null);
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed reading the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    // close file
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }

                // update chart
                chart.RangeX = new Range(minX, maxX);
                ShowTrainingData();

                // enable start button
                startButton.Enabled = true;
            }
        }
 // Clear current solution
 private void ClearCurrentSolution()
 {
     chart.UpdateDataSeries("classifier", null);
     errorChart.UpdateDataSeries("error", null);
     weightsList.Items.Clear();
 }