Пример #1
0
        private void ShowMultipleRegressionModel()
        {
            tabControlMain.SelectedIndex = 2;
            string qualityParam = XMLWork.FindNameWithID(_multipleRegressionEquation.OutputParameter.Id.Value,
                                                         Properties.Settings.Default.Languages);

            double[] coefficients =
                _multipleRegressionEquation.InputParameters.Select(item => item.Coefficient).ToArray();
            string[] inputParametersToCheck = _multipleRegressionEquation.InputParameters.Skip(1)
                                              .Select(item => XMLWork.FindNameWithID(item.Id.Value, Properties.Settings.Default.Languages)).ToArray();

            for (int i = 0; i < comboBoxQualityParametersPage3.Items.Count; i++)
            {
                if (comboBoxQualityParametersPage3.Items[i].Equals(qualityParam))
                {
                    comboBoxQualityParametersPage3.SelectedIndex = i;
                    break;
                }
            }
            for (int i = 0; i < checkedListBoxInputParametersToCheckPage3.Items.Count; i++)
            {
                checkedListBoxInputParametersToCheckPage3.SetItemCheckState(i,
                                                                            inputParametersToCheck.Contains(checkedListBoxInputParametersToCheckPage3.Items[i])
                        ? CheckState.Checked
                        : CheckState.Unchecked);
            }
            labelRMSEPage3.Text = _multipleRegressionEquation.RMSEString;
            checkBoxNormalizeValuesPage3.Checked = _multipleRegressionEquation.NormalizeValues;
            ShowRegressionEquasion(qualityParam, coefficients);
            ShowRegressionEquasionHelp(inputParametersToCheck);
        }
Пример #2
0
        private void ShowLinearRegressionModel()
        {
            tabControlMain.SelectedIndex = 0;
            string qualityParam = XMLWork.FindNameWithID(_linearEquation.OutputParameter.Id.Value,
                                                         Properties.Settings.Default.Languages);

            double[] coefficients =
                _linearEquation.InputParameters.Select(item => item.Coefficient).ToArray();
            string inputParam = XMLWork.FindNameWithID(_linearEquation.InputParameters[1].Id.Value,
                                                       Properties.Settings.Default.Languages);

            for (int i = 0; i < comboBoxInputParams.Items.Count; i++)
            {
                if (comboBoxInputParams.Items[i].Equals(inputParam))
                {
                    comboBoxInputParams.SelectedIndex = i;
                    break;
                }
            }
            for (int i = 0; i < comboBoxQualityParams.Items.Count; i++)
            {
                if (comboBoxQualityParams.Items[i].Equals(qualityParam))
                {
                    comboBoxQualityParams.SelectedIndex = i;
                    break;
                }
            }
            labelRMSE.Text = _linearEquation.RMSEString;
            checkBoxNormalizeValuesPage1.Checked = _linearEquation.NormalizeValues;
            GetLinearRegressionModel(qualityParam, inputParam, false);
        }
Пример #3
0
        public Kohonen()
        {
            if (!string.IsNullOrEmpty(Properties.Settings.Default.Languages))
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture =
                    System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Languages);
                System.Threading.Thread.CurrentThread.CurrentCulture =
                    System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Languages);
            }
            InitializeComponent();
            ListAdd.Items.Clear();
            ListDelete.Items.Clear();
            List <int> keys = new List <int>();
            Dictionary <int, decimal> firstRow = TrainData.Train.First().Input;

            foreach (OneRow data in TrainData.Train)
            {
                foreach (var item in data.Input)
                {
                    if (keys.Contains(item.Key))
                    {
                        continue;
                    }
                    if (item.Key != firstRow[item.Key])
                    {
                        keys.Add(item.Key);
                    }
                }
                break;
            }
            var parameters = TrainData.nameParameter.Values.Where(o => o.StartsWith("Def")).ToArray();

            foreach (var parameter1 in parameters)
            {
                ListAdd.Items.Add(XMLWork.FindNameWithScada(parameter1, Properties.Settings.Default.Languages));
            }
            foreach (int key in keys)
            {
                ListAdd.Items.Add(XMLWork.FindNameWithID(key, Properties.Settings.Default.Languages));
            }
            if (ListAdd.Items.Count != 0)
            {
                ListAdd.SelectedIndex = 0;
            }
            if (ListDelete.Items.Count != 0)
            {
                ListDelete.SelectedIndex = 0;
            }
        }
Пример #4
0
        /// <summary>
        /// Calculate Dispersion all parameters
        /// </summary>
        private void CalculateDispersion()
        {
            int countElements = 10;
            Dictionary <int, decimal> mathematicalExpectation = new Dictionary <int, decimal>();
            Dictionary <int, decimal> dispersion = new Dictionary <int, decimal>();
            Dictionary <int, decimal> bestValues = new Dictionary <int, decimal>();

            ProcessingData.MathematicalExpectation(TrainData.Train, mathematicalExpectation);
            ProcessingData.Dispersion(TrainData.Train, mathematicalExpectation, dispersion);
            List <FisherCritery> elements = new List <FisherCritery>();

            foreach (var @decimal in dispersion)
            {
                elements.Add(new FisherCritery(@decimal.Key, @decimal.Value));
            }
            ListOfElements dispoersionElements = new ListOfElements(elements);

            dispoersionElements.InsertionSort();
            for (int i = 0; i < countElements; i++)
            {
                bestValues.Add(dispoersionElements.Fisher[i].Key, dispoersionElements.Fisher[i].Value);
            }

            this.chart2.Series.Clear();
            this.chart2.Titles.Clear();
            this.chart2.ChartAreas[0].AxisY.Maximum = Math.Round(Convert.ToDouble(bestValues.First().Value), 0) + 25;
            this.chart2.ChartAreas[0].AxisY.Minimum = Math.Round(Convert.ToDouble(bestValues.Last().Value), 0) - 25;

            // Set palette.
            this.chart2.Palette = ChartColorPalette.SeaGreen;

            // Set title.
            this.chart2.Titles.Add("Deviation");
            double numberOfParameters = 1.0;

            foreach (var item in bestValues)
            {
                // Add series.
                Series series = this.chart2.Series.Add(XMLWork.FindNameWithID(item.Key, Properties.Settings.Default.Languages));
                // Add point.
                //series.Points.Add(Convert.ToDouble(item.Value));
                series.Points.AddXY(numberOfParameters, item.Value);
                numberOfParameters += 0.1;
            }
            // Add series.
        }
Пример #5
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DictionaryMeasurement_Shown(object sender, EventArgs e)
        {
            int       columns = TrainData.Train[0].Input.Count;
            int       i;
            DataTable sourceTable = new DataTable();

            sourceTable.Columns.Add("Date");
            foreach (KeyValuePair <int, decimal> keyValuePair in TrainData.Train[0].Input)
            {
                String parName = XMLWork.FindNameWithID(keyValuePair.Key, Properties.Settings.Default.Languages);
                sourceTable.Columns.Add(parName);
            }
            foreach (KeyValuePair <int, decimal> keyValuePair in TrainData.Train[0].Output)
            {
                String parName = XMLWork.FindNameWithID(keyValuePair.Key, Properties.Settings.Default.Languages);
                sourceTable.Columns.Add(parName);
            }
            foreach (OneRow oneRow in TrainData.Train)
            {
                DataRow row = sourceTable.NewRow();
                i = 1;
                foreach (KeyValuePair <int, decimal> valuePair in oneRow.Input.OrderBy(o => o.Key))
                {
                    row[0] = oneRow.Date;
                    row[i] = valuePair.Value;
                    i++;
                }
                foreach (KeyValuePair <int, decimal> valuePair in oneRow.Output.OrderBy(o => o.Key))
                {
                    row[i] = valuePair.Value;
                    i++;
                }
                sourceTable.Rows.Add(row);
            }
            gridMeasurements.DataSource = sourceTable;
            EnableDoubleBuffering();
        }
Пример #6
0
        private void parameterCondition_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListAdd.Items.Clear();
            ListDelete.Items.Clear();
            List <int> keys                    = new List <int>();
            int        parameterID             = XMLWork.FindIDWithName(parameterCondition.SelectedItem.ToString(), Properties.Settings.Default.Languages);
            Dictionary <int, decimal> firstRow = TrainData.Train.First().Input;

            foreach (OneRow data in TrainData.Train)
            {
                foreach (var item in data.Input)
                {
                    if (keys.Contains(item.Key))
                    {
                        continue;
                    }
                    if (item.Key != firstRow[item.Key])
                    {
                        keys.Add(item.Key);
                    }
                }
                break;
            }
            foreach (int key in keys)
            {
                ListAdd.Items.Add(XMLWork.FindNameWithID(key, Properties.Settings.Default.Languages));
            }
            if (ListAdd.Items.Count != 0)
            {
                ListAdd.SelectedIndex = 0;
            }
            if (ListDelete.Items.Count != 0)
            {
                ListDelete.SelectedIndex = 0;
            }
        }
Пример #7
0
        /// <summary>
        /// Selects parameters in orange
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        /*private void DrawItem(object sender, ListBoxDrawItemEventArgs e)
         * {
         *  ListBoxControl control = (ListBoxControl)sender;
         *  if (e.Index == (control.SelectedIndex))
         *  {
         *      e.Appearance.BackColor = Color.Orange;
         *  }
         * }*/

        #endregion


        private void parameterCondition_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListAdd.Items.Clear();
            ListDelete.Items.Clear();
            ListAddError.Items.Clear();
            ListDeleteError.Items.Clear();
            List <int> keys                    = new List <int>();
            int        parameterID             = XMLWork.FindIDWithName(parameterCondition.SelectedItem.ToString(), Properties.Settings.Default.Languages);
            Dictionary <int, decimal> firstRow = TrainData.Train.First(o => o.Output[parameterID] > (Convert.ToDecimal(uppLimit.Value) * 0.9M)).Input;

            foreach (OneRow data in TrainData.Train)
            {
                if (data.Output[parameterID] > 1.0M)
                {
                    foreach (var item in data.Input)
                    {
                        if (keys.Contains(item.Key))
                        {
                            continue;
                        }
                        if (item.Key != firstRow[item.Key])
                        {
                            keys.Add(item.Key);
                        }
                    }
                }
            }
            foreach (int key in keys)
            {
                ListAdd.Items.Add(XMLWork.FindNameWithID(key, Properties.Settings.Default.Languages));
                ListAddError.Items.Add(XMLWork.FindNameWithID(key, Properties.Settings.Default.Languages));
            }
            addAllToFirstCoordinate.Enabled     = true;
            addAllToSecondCoordinate.Enabled    = true;
            addOneCoordinate.Enabled            = true;
            addOneToSecondCoordinate.Enabled    = true;
            deleteAllToFirstCoordinate.Enabled  = true;
            deleteAllToSecondCoordinate.Enabled = true;
            deleteOneToSecondCoordinate.Enabled = true;
            deleteToFirstCoordinate.Enabled     = true;
            if (parameterCondition.SelectedIndex != -1)
            {
                parameterCondition.BackColor = Color.White;
            }

            if (ListAdd.Items.Count != 0)
            {
                ListAdd.SelectedIndex = 0;
            }
            if (ListDelete.Items.Count != 0)
            {
                ListDelete.SelectedIndex = 0;
            }
            if (ListAddError.Items.Count != 0)
            {
                ListAddError.SelectedIndex = 0;
            }
            if (ListDeleteError.Items.Count != 0)
            {
                ListDeleteError.SelectedIndex = 0;
            }
        }
Пример #8
0
        private void ShowThrend(object sender)
        {
            FormsPlot chartControl = chartControl1;

            try
            {
                List <double> xs = new List <double>();
                List <double> ys = new List <double>();
                // Процедура поиска текущего контрола для отрисовки трендов
                if (extruderTabPage.Visible)
                {
                    chartControl = chartTrends;
                }
                if (calenderRollTabPage.Visible)
                {
                    chartControl = chartCalenderRoll;
                }
                if (takeoffRollTabPage.Visible)
                {
                    chartControl = chartTakeOffRoll;
                }
                if (temperingRollTabPage.Visible)
                {
                    chartControl = chartTemperingRoll;
                }
                if (winderTabPage.Visible)
                {
                    chartControl = chartWinder;
                }
                if (qualityTabPage.Visible) // Ситуация когда мы находимся на вкладке показателей качества является нетривиальной
                {
                    chartControl = chartControl1;
                    if (sender is TextBox)
                    {
                        //Поиск текстбокса и указание ограничений по времени
                        TextBox  edit       = sender as TextBox;
                        DateTime timeBefore = TrainData.Train.OrderBy(o => o.Date).First().Date;
                        DateTime timeAfter  = TrainData.Train.OrderByDescending(o => o.Date).First().Date;
                        chartControl.plt.Clear();
                        if (edit.Name.Contains("Shrinkage")) //если выбрана усадка
                        {
                            TimeSpan ts = new TimeSpan(ProductionTime.TakeOffTime);
                            foreach (OneRow row in TrainData.Train)
                            {
                                DataSet AuthorsDataSet = new DataSet();
                                AuthorsDataSet.ReadXml(XMLWork.PathShrinkage);
                                string shrinkageValues = XMLWork.FindShrinkageWithTimestamp(row.Date);
                                if ((row.Date >= timeBefore) && (row.Date <= timeAfter))
                                {
                                    xs.Add((row.Date - ts).ToOADate());
                                    ys.Add(Convert.ToDouble(shrinkageValues.Replace(".", ",")));
                                }
                            }
                            chartControl.plt.PlotScatter(xs.ToArray(), ys.ToArray(), lineWidth: 2, markerShape: MarkerShape.none, label: "Shrinkage value");
                        }
                        else
                        {
                            //Отрисовка
                            int parameterID = XMLWork.FindID(edit.Name.Replace("_", "."));
                            foreach (OneRow row in TrainData.Train)
                            {
                                if ((row.Date >= timeBefore) && (row.Date <= timeAfter))
                                {
                                    xs.Add(row.Date.ToOADate());
                                    ys.Add(Convert.ToDouble(row.Output[parameterID]));
                                }
                            }
                            chartControl.plt.PlotScatter(xs.ToArray(), ys.ToArray(), lineWidth: 2, markerShape: MarkerShape.none, label: XMLWork.FindNameWithID(parameterID, Properties.Settings.Default.Languages));
                        }
                    }
                    chartControl.plt.Ticks(dateTimeX: true);
                    chartControl.plt.Legend(location: legendLocation.upperRight, shadowDirection: shadowDirection.none);
                    chartControl.plt.AxisAuto();
                    double xDelta = Math.Abs(xs.Max() - xs.Min());
                    double yDelta = Math.Abs(ys.Max() - ys.Min());
                    chartControl.plt.Axis(xs.Min() - xDelta * 0.05, xs.Max() + xDelta * 0.05, ys.Min() - yDelta * 0.05, ys.Max() + yDelta * 0.05); chartControl.Render();
                    return;
                }
                if (sender is TextBox)
                {
                    //Поиск текстбокса и указание ограничений по времени
                    TextBox  edit       = sender as TextBox;
                    DateTime timeBefore = TrainData.Train.OrderBy(o => o.Date).First().Date;
                    DateTime timeAfter  = TrainData.Train.OrderByDescending(o => o.Date).First().Date;
                    chartControl.plt.Clear();
                    //Отрисовка
                    int parameterID = XMLWork.FindID(edit.Name);
                    foreach (OneRow row in TrainData.Train)
                    {
                        if ((row.Date >= timeBefore) && (row.Date <= timeAfter) && (!qualityTabPage.Visible))
                        {
                            xs.Add(row.Date.ToOADate());
                            ys.Add(Convert.ToDouble(row.Input[parameterID]));
                        }
                    }
                    chartControl.plt.PlotScatter(xs.ToArray(), ys.ToArray(), lineWidth: 2, markerShape: MarkerShape.none, label: XMLWork.FindNameWithID(parameterID, Properties.Settings.Default.Languages));
                    chartControl.plt.Ticks(dateTimeX: true);
                    chartControl.plt.Legend(location: legendLocation.upperRight, shadowDirection: shadowDirection.none);
                    chartControl.plt.AxisAuto();
                    double xDelta = Math.Abs(xs.Max() - xs.Min());
                    double yDelta = Math.Abs(ys.Max() - ys.Min());
                    chartControl.plt.Axis(xs.Min() - xDelta * 0.05, xs.Max() + xDelta * 0.05, ys.Min() - yDelta * 0.05, ys.Max() + yDelta * 0.05);
                    chartControl.Render();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(Localization.MyStrings.SomethingWrong + exception.ToString());
            }
        }
Пример #9
0
        /// <summary>
        /// Implement FisherCritery
        /// </summary>
        private void FisherCritery()
        {
            if (parameterCondition.Items.Count != 0)
            {
                int                       countElements = 10;
                List <OneRow>             trainData     = TrainData.Train;
                Dictionary <int, decimal> bestValues    = new Dictionary <int, decimal>();
                List <FisherCritery>      fishers       = new List <FisherCritery>();
                try
                {
                    int     parameterID = XMLWork.FindIDWithName((string)parameterCondition.SelectedItem, Properties.Settings.Default.Languages);
                    decimal averageY    = AverageOutput(trainData, parameterID);

                    //Fisher Critery
                    foreach (var item in trainData[0].Input)
                    {
                        Fisher fisher = new Fisher(trainData, item.Key, parameterID, averageY);
                        fisher.CalculateFisher();
                        fishers.Add(new FisherCritery(item.Key, fisher.Critery));
                    }

                    //Sort of data
                    ListOfElements fisherElements = new ListOfElements(fishers);
                    fisherElements.InsertionSort();
                    //Give Best Value
                    for (int i = 0; i < countElements; i++)
                    {
                        bestValues.Add(fisherElements.Fisher[i].Key, fisherElements.Fisher[i].Value);
                    }

                    //Clear Palette
                    this.chart1.Series.Clear();
                    this.chart1.Titles.Clear();
                    this.chart1.ChartAreas[0].AxisY.Maximum = Math.Round(Convert.ToDouble(bestValues.First().Value), 0) + 25;
                    this.chart1.ChartAreas[0].AxisY.Minimum = Math.Round(Convert.ToDouble(bestValues.Last().Value), 0) - 25;

                    // Set palette.
                    this.chart1.Palette = ChartColorPalette.SeaGreen;

                    // Set title.
                    this.chart1.Titles.Add("Critery F-Test");
                    double numberOfParameters = 1.0;

                    foreach (var item in bestValues)
                    {
                        // Add series.
                        Series series = this.chart1.Series.Add(XMLWork.FindNameWithID(item.Key, Properties.Settings.Default.Languages));
                        // Add point.
                        //series.Points.Add(Convert.ToDouble(item.Value));
                        series.Points.AddXY(numberOfParameters, item.Value);
                        numberOfParameters += 0.1;
                    }
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show(Localization.MyStrings.SelectCriterion);
                }
                catch (Exception excep)
                {
                    MessageBox.Show(excep.ToString());
                }
            }
            else
            {
                MessageBox.Show(Localization.MyStrings.WithoutDefect);
            }
            // Add series.
        }