diff --git a/bin/CS_NMLS_with_UI.exe b/bin/CS_NMLS_with_UI.exe index 240f702..cae92d7 100644 Binary files a/bin/CS_NMLS_with_UI.exe and b/bin/CS_NMLS_with_UI.exe differ diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 0000000..c72486c --- /dev/null +++ b/bin/README.md @@ -0,0 +1,31 @@ +# README + +### Short explenation of the c# .exe + +![alt text](https://github.com/FBRDNLMS/NLMSvariants/blob/master/img/CS_exe_screenshot_1.PNG "C# .exe with loaded picture") + +1. Choose the algorithm u want to calculate on and press "start" or "enter" + +2. Choose the number of pixels you want to go for + +3. Clears the screen and reprints the actual values of your picture or predefined values + +4. Choose the learnrate and window size you want, learnrate has to be over 0.0 and under or even 1.0. + The window size has to be an integer. + +5. Loads a picture, it has to be BMP, GIF, EXIF, JPG, PNG or TIFF + +6. Check this for generating outputfiles in the same direktory you started your .exe in + Outputfiles are : weights.txt, weights_after.txt, localMean|directPredecessorer|differentialPredecessorer.txt, results.txt + +7. Chart where the algorithems output is displayed + + +![alt text](https://github.com/FBRDNLMS/NLMSvariants/blob/master/img/CS_exe_screenshot_2.PNG "C# .exe with loaded picture and calculated") + +1. Displays the average error of the calculated algorithm + +2. Displays the variance of the error of the calculated algorithm + +3. The history of graphs displayed in the chart, it is possible to have graphs of all 3 LMS algorithems in the history. + There is no way to hide graphs, simply use "Clear" and then calculate again. \ No newline at end of file diff --git a/img/CS_exe_screenshot_1.PNG b/img/CS_exe_screenshot_1.PNG new file mode 100644 index 0000000..95b949c Binary files /dev/null and b/img/CS_exe_screenshot_1.PNG differ diff --git a/img/CS_exe_screenshot_2.PNG b/img/CS_exe_screenshot_2.PNG new file mode 100644 index 0000000..bb6688a Binary files /dev/null and b/img/CS_exe_screenshot_2.PNG differ diff --git a/src/c_sharp_implementation/NLMSvariants.cs b/src/c_sharp_implementation/NLMSvariants.cs index 595c1d2..878bba0 100644 --- a/src/c_sharp_implementation/NLMSvariants.cs +++ b/src/c_sharp_implementation/NLMSvariants.cs @@ -1,3 +1,10 @@ +/* +=========================================================================== + +Created by Kevin Becker on 19.04.2018 + +=========================================================================== +*/ using System; using System.Collections.Generic; using System.ComponentModel; @@ -37,11 +44,52 @@ namespace NMLS_Graphisch * *---------------------------------------------------*/ - private void GO_btn_Click(object sender, EventArgs e) + private void Start_btn_Click(object sender, EventArgs e) { - /* Initializing the chart to display all values */ + /* Initializing NumberOfSamples with the choosen pixelcount */ NumberOfSamples = Int32.Parse(comboBox_pixel.SelectedItem.ToString()); + + /* Initializing the weights */ + + w = new double[windowSize, NumberOfSamples]; + for (int i = 0; i < NumberOfSamples; i++) + { + for (int k = 0; k < windowSize; k++) + { + w[k, i] = rnd.NextDouble(); + } + } + + /* Initializing the learnrate with the choosen one */ + txtBox_learnrate.Text = txtBox_learnrate.Text.Replace(".", ","); + try + { + learnrate = Double.Parse(txtBox_learnrate.Text); + } + catch(Exception exep) + { + MessageBox.Show("Please choose a learnrate between >0.0 and <=1.0"); + return; + } + + while(learnrate <= 0.0 || learnrate > 1.0) + { + MessageBox.Show("Please choose a learnrate between >0.0 and <=1.0"); + var myValue = Microsoft.VisualBasic.Interaction.InputBox("Choose a learnrate between >0.0 and <=1.0", "Learnrate", "0,8"); + if(myValue == "") + { + return; + } + else + { + learnrate = Double.Parse(myValue); + } + } + + /* Initializing the windowsize with the choosen one*/ + + /* Initializing the chart to display all values */ chart_main.ChartAreas[0].AxisX.Maximum = NumberOfSamples; chart_main.ChartAreas[0].AxisY.Maximum = 300; chart_main.ChartAreas[0].AxisY.Minimum = -100; @@ -53,7 +101,7 @@ namespace NMLS_Graphisch { for (int k = 0; k < windowSize; k++) { - File.AppendAllText("weights.txt", + File.AppendAllText(String.Format("weights_{0}.txt", comboBox_algorithem.SelectedItem.ToString().Replace(" ","")), String.Format("[{0}][{1}] {2}\n", k, i, Math.Round(w[k, i], 2).ToString()), Encoding.UTF8); } @@ -66,15 +114,15 @@ namespace NMLS_Graphisch switch (comboBox_algorithem.SelectedItem.ToString()) { - case "lokaler Mittelwert": + case "local mean": series = localMean(); break; - case "direkter Vorgänger": + case "direct predecessor": series = directPredecessor(); break; - case "differenzieller Vorgänger": + case "differential predecessor": series = diffPredecessor(); break; @@ -104,7 +152,7 @@ namespace NMLS_Graphisch { for (int k = 0; k < windowSize; k++) { - File.AppendAllText("weights_after.txt", + File.AppendAllText(String.Format("weights_after_{0}.txt", comboBox_algorithem.SelectedItem.ToString().Replace(" ", "")), String.Format("[{0}][{1}] {2}\n", k, i, Math.Round(w[k, i], 2).ToString()), Encoding.UTF8); } @@ -133,8 +181,8 @@ namespace NMLS_Graphisch x_error[0] = 0; /* Inizilazing series for the main chart */ - Series localMeanError = new Series("Lokaler Mittelwert Error"); - Series localMeanPredict = new Series("Lokaler Mittelwert Prediction"); + Series localMeanError = new Series("Local Mean Error"); + Series localMeanPredict = new Series("Local Mean Prediction"); localMeanError.ChartType = SeriesChartType.Spline; localMeanPredict.ChartType = SeriesChartType.Spline; @@ -155,7 +203,7 @@ namespace NMLS_Graphisch double x_pred = 0.0; double[] x_array = _x; - double x_actual = _x[x_count + 1]; + double x_actual = _x[x_count]; /* Prediction algorithem */ @@ -169,11 +217,11 @@ namespace NMLS_Graphisch if (checkBox_output.Checked) { - File.AppendAllText("lokalerMittelwert.txt", + File.AppendAllText("localMean.txt", String.Format("{0}. X_pred {1}\n", x_count, x_pred), Encoding.UTF8); - File.AppendAllText("lokalerMittelwert.txt", + File.AppendAllText("localMean.txt", String.Format("{0}. X_actual {1}\n", x_count, x_actual), Encoding.UTF8); } @@ -187,7 +235,7 @@ namespace NMLS_Graphisch /* Output */ if (checkBox_output.Checked) { - File.AppendAllText("lokalerMittelwert.txt", + File.AppendAllText("localMean.txt", String.Format("{0}. X_error {1}\n\n", x_count, x_error[x_count]), Encoding.UTF8); } @@ -234,8 +282,8 @@ namespace NMLS_Graphisch /* Output the result */ if (checkBox_output.Checked) { - File.AppendAllText("ergebnisse.txt", - String.Format("Quadratische Varianz(x_error): {0}\n Mittelwert(x_error): {1}\n\n", varianz, mittel), + File.AppendAllText("results_localMean.txt", + String.Format("Squared variance(x_error): {0}\n Average(x_error): {1}\n\n", varianz, mittel), Encoding.UTF8); } @@ -259,8 +307,8 @@ namespace NMLS_Graphisch int x_count = 0; /* Inizilazing series for the main chart */ - Series directPredecessorError = new Series("Direkter Vorgänger Error"); - Series directPredecessorPrediction = new Series("Direkter Vorgänger Prediction"); + Series directPredecessorError = new Series("Direct predecessor Error"); + Series directPredecessorPrediction = new Series("Direct predecessor Prediction"); directPredecessorError.ChartType = SeriesChartType.Spline; directPredecessorPrediction.ChartType = SeriesChartType.Spline; @@ -268,7 +316,7 @@ namespace NMLS_Graphisch while (x_count < NumberOfSamples - 1) { double x_pred = 0.0; - double x_actual = _x[x_count + 1]; + double x_actual = _x[x_count]; if (x_count > 0) { @@ -285,11 +333,11 @@ namespace NMLS_Graphisch /* If output is checked a file is produced with prediction, actual and the error */ if (checkBox_output.Checked) { - File.AppendAllText("direkterVorgaenger.txt", + File.AppendAllText("directpredecessor.txt", String.Format("{0}. X_pred {1}\n", x_count, x_pred), Encoding.UTF8); - File.AppendAllText("direkterVorgaenger.txt", + File.AppendAllText("directpredecessor.txt", String.Format("{0}. X_actual {1}\n", x_count, x_actual), Encoding.UTF8); } @@ -300,7 +348,7 @@ namespace NMLS_Graphisch /* Output */ if (checkBox_output.Checked) { - File.AppendAllText("direkterVorgaenger.txt", + File.AppendAllText("directpredecessor.txt", String.Format("{0}. X_error {1}\n\n", x_count, x_error[x_count]), Encoding.UTF8); } @@ -350,8 +398,8 @@ namespace NMLS_Graphisch /* Output the result */ if (checkBox_output.Checked) { - File.AppendAllText("ergebnisse.txt", - String.Format("Quadratische Varianz(x_error): {0}\n Mittelwert(x_error): {1}\n\n", varianz, mittel), + File.AppendAllText("results_directpredecessor.txt", + String.Format("Squared variance(x_error): {0}\n Average(x_error): {1}\n\n", varianz, mittel), Encoding.UTF8); } @@ -375,8 +423,8 @@ namespace NMLS_Graphisch int x_count = 0; /* Inizilazing series for the main chart */ - Series diffPredecessorError = new Series("Differenzieller Vorgänger Error"); - Series diffPredecessorPrediction = new Series("Differenzieller Vorgänger Prediction"); + Series diffPredecessorError = new Series("Differential predecessor Error"); + Series diffPredecessorPrediction = new Series("Differential predecessor Prediction"); diffPredecessorError.ChartType = SeriesChartType.Spline; diffPredecessorPrediction.ChartType = SeriesChartType.Spline; @@ -384,7 +432,7 @@ namespace NMLS_Graphisch while (x_count < NumberOfSamples - 1) { double x_pred = 0.0; - double x_actual = _x[x_count + 1]; + double x_actual = _x[x_count]; if (x_count > 0) { @@ -401,11 +449,11 @@ namespace NMLS_Graphisch /* If output is checked a file is produced with prediction, actual and the error */ if (checkBox_output.Checked) { - File.AppendAllText("differenziellerVorgaenger.txt", + File.AppendAllText("differentialpredecessor .txt", String.Format("{0}. X_pred {1}\n", x_count, x_pred), Encoding.UTF8); - File.AppendAllText("differenziellerVorgaenger.txt", + File.AppendAllText("differentialpredecessor.txt", String.Format("{0}. X_actual {1}\n", x_count, x_actual), Encoding.UTF8); } @@ -416,7 +464,7 @@ namespace NMLS_Graphisch /* Output */ if (checkBox_output.Checked) { - File.AppendAllText("differenziellerVorgaenger.txt", + File.AppendAllText("differentialpredecessor.txt", String.Format("{0}. X_error {1}\n\n", x_count, x_error[x_count]), Encoding.UTF8); } @@ -468,8 +516,8 @@ namespace NMLS_Graphisch /* Output the result */ if (checkBox_output.Checked) { - File.AppendAllText("ergebnisse.txt", - String.Format("Quadratische Varianz(x_error): {0}\n Mittelwert(x_error): {1}\n\n", varianz, mittel), + File.AppendAllText("results_differentialpredecessor.txt", + String.Format("Squared variance(x_error): {0}\n Average(x_error): {1}\n\n", varianz, mittel), Encoding.UTF8); } @@ -484,15 +532,24 @@ namespace NMLS_Graphisch *---------------------------------------------------*/ private void Form1_Load(object sender, EventArgs e) { + /* Initializing some diffrent combo-/textboxes and the main chart */ comboBox_algorithem.SelectedIndex = 0; comboBox_pixel.SelectedIndex = 0; + // sets an eventhandler on the gotFocus event + txtBox_learnrate.GotFocus += new EventHandler(txtBox_learnrate_gotFocus); + txtBox_learnrate.Text = ">0.0 & <=1.0"; + // sets an eventhandler on the gotFocus event + txtBox_windowSize.GotFocus += new EventHandler(txtBox_windowSize_gotFocus); chart_main.Series.Clear(); Series x_actual = new Series("Actual x Value"); x_actual.ChartType = SeriesChartType.Spline; + // sets the accept button to Start_btn + this.AcceptButton = Start_btn; + /* Initializing weights and actual values In case no picture is loaded, actual values are generated - And printing them on a chart */ + Then printing them on a chart */ for (int i = 0; i < NumberOfSamples; i++) { _x[i] += ((255.0 / NumberOfSamples) * i); @@ -505,6 +562,30 @@ namespace NMLS_Graphisch chart_main.Series.Add(x_actual); } + /*-------------------------------------------------- + * txtBox_learnrate_gotFocus() + * + * sets the default text to "" if gotFocus is raised + * + * -------------------------------------------------*/ + + protected void txtBox_learnrate_gotFocus(Object sender, EventArgs e) + { + txtBox_learnrate.Text = ""; + } + + /*-------------------------------------------------- + * txtBox_windowSize_gotFocus() + * + * sets the default text to "" if gotFocus is raised + * + * -------------------------------------------------*/ + + protected void txtBox_windowSize_gotFocus(Object sender, EventArgs e) + { + txtBox_windowSize.Text = ""; + } + /*--------------------------------------------------- * Clear_btn_Click() * @@ -594,6 +675,28 @@ namespace NMLS_Graphisch } } } + + /*--------------------------------------------------- + * txtBox_windowSize_TextChanged() + * + * proofs if window size textbox is a valid number + * + *---------------------------------------------------*/ + + private void txtBox_windowSize_TextChanged(object sender, EventArgs e) + { + try + { + if(txtBox_windowSize.Text.Length > 0) + { + windowSize = Int32.Parse(txtBox_windowSize.Text); + } + }catch(Exception excep) + { + MessageBox.Show("Not a valid window size"); + txtBox_windowSize.Text = ""; + } + } } }