private void Window_Loaded(object sender, RoutedEventArgs e) { var xMatrix = new Libs.Matrix(new float[, ] { { -3.2f, -2.1f, 0.4f, 0.7f, 2f, 2.5f, 2.777f } }); var yMatrix = new Libs.Matrix(new float[, ] { { 10f }, { -2f }, { 0f }, { -7f }, { 7f }, { 0f }, { 0f } }); var coefs = MeanSquaredErrorApproximation.Approximate( xMatrix, yMatrix, 2 ); var points = new List <Point>(); for (float x = -3.2f; x <= 2.777; x += 0.0001f) { float y = 0; for (int c = 0; c < coefs.ToArray().Length; c++) { y += coefs[c, 0] * (float)Math.Pow(x, c); } points.Add(new Point(x, y)); } using (var file = System.IO.File.CreateText(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "points.csv"))) { foreach (var point in points) { file.WriteLine(string.Format("{0},{1}", point.X, point.Y)); } file.Close(); } DrawGraph(points, Brushes.Green); var realPoints = new List <Point>(); for (int i = 0; i < xMatrix.Width; i++) { realPoints.Add(new Point(xMatrix[0, i], yMatrix[i, 0])); } DrawGraph(realPoints, Brushes.Orange); }
private List <Point> GeneratePoints(Libs.Matrix coefficients) { var points = new List <Point>(); for (float x = xMatrix[0, 0]; x <= xMatrix[0, xMatrix.Width - 1]; x += 0.001f) { float y = 0; for (int c = 0; c < coefficients.ToArray().Length; c++) { y += coefficients[c, 0] * (float)Math.Pow(x, c); } points.Add(new Point(x, y)); } return(points); }
private void DemoTable_MSE_Click(object sender, RoutedEventArgs e) { CleanDataSources(); float[] xValues = new float[] { 0, 3.3f, 6.6f, 9.9f }; float[] yValues = new float[] { 2.1f, 5.9f, 2.4f, 3.4f }; var xMatrix = new Libs.Matrix(new float[, ] { { 0, 3.3f, 6.6f, 9.9f } }); var yMatrix = new Libs.Matrix(new float[, ] { { 2.1f }, { 5.9f }, { 2.4f }, { 3.4f } }); var coefs = MeanSquaredErrorApproximation.Approximate( xMatrix, yMatrix, 1 ); MnkK1Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate( xMatrix, yMatrix, 2 ); MnkK2Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate( xMatrix, yMatrix, 3 ); MnkK3Plotter.ItemsSource = GeneratePoints(coefs); DrawBasePoints(xValues, yValues); }
private void DrawMSE_Func() { var rank = ChebyshevApproximation.CalculateRank(a, b, step); var xValues = new Libs.Matrix(ChebyshevApproximation.GenerateX(a, b, step)); var yValues = new Libs.Matrix(new float[rank, 1]); for (int j = 0; j < yValues.Height; j++) { yValues[j, 0] = (float)ApproximatedFunction(xValues[0, j]); } var coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 1); MnkK1Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 2); MnkK2Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 3); MnkK3Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 4); MnkK4Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 5); MnkK5Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 6); MnkK6Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 7); MnkK7Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 8); MnkK8Plotter.ItemsSource = GeneratePoints(coefs); coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 9); MnkK9Plotter.ItemsSource = GeneratePoints(coefs); }