static void Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Missing input parameters."); Console.WriteLine("Command line should be in format: Solver.exe <config file> <file with calculated points> <file for output points>"); //Console.ReadKey(); return; } Parser parser = new Parser(args[0], args[1]); int res = parser.doParse(); if (res != 0) { // Console.ReadKey(); return; } /*double[][] xf = new double[][] * { * new double[] { 0, 0, 0 }, * new double[] { 0, 1, 1 }, * new double[] { 0, 2, 2 }, * new double[] { 1, 0, 1 }, * new double[] { 1, 1, 2 }, * new double[] { 1, 2, 3 }, * new double[] { 2, 0, 2 }, * new double[] { 2, 1, 2 }, * new double[] { 2, 2, 4 } * };*/ Shepard model = new Shepard(parser.FunctionDimension, parser.Points); double[] x = new double[] { 0.5, 0.5, 0 }; model.Calculate(x); Console.WriteLine("f({0}, {1}) = {2}", x[0], x[1], x[2]); Analyzer analyzer = new Analyzer(model, parser.Points, new int[] { 10, 10 }); double[][] xx = analyzer.Result; for (int i = 0; i < parser.PredictionPointAmount; i++) { model.Calculate(xx[i]); Console.WriteLine("f({0}, {1}) = {2}\terror = {3}", xx[i][0], xx[i][1], xx[i][2], Math.Abs(xx[i][0] + xx[i][1] - xx[i][2])); } Parser.keepSolution(args[2], xx); //Console.ReadKey(); }
private int testDefWay(string configFile, string pointFile, Func <double[], double> func) { Parser parser = new Parser(configFile, pointFile); int pointAmount = parser.PointAmount; double[][] points = new double[parser.PointAmount][]; for (int j = 0; j < parser.PointAmount; j++) { points[j] = (double[])parser.Points[j].Clone(); } int i = 0; double maxErr = 10; while (i < 100000000 && maxErr > parser.Approximation) { Shepard model = new Shepard(parser.FunctionDimension, points); Console.WriteLine("Max " + String.Join(", ", model.Max) + " Min " + String.Join(", ", model.Min)); Analyzer analyzer = new Analyzer(model, points); analyzer.do_default_analyse(); double[][] xx = analyzer.Result; pointAmount = pointAmount + parser.PredictionPointAmount; points = getNewPoints(points, analyzer.Result, parser.PredictionPointAmount, parser.FunctionDimension, func); double[][] new_points = new double[parser.PredictionPointAmount][]; for (int j = 0; j < parser.PredictionPointAmount; j++) { new_points[j] = new double[xx[j].Length]; Array.Copy(xx[j], new_points[j], xx[j].Length); model.Calculate(new_points[j]); } double tempErr = 0; for (int k = 0; k < new_points.Length; k++) { double err = Math.Abs(points[pointAmount - parser.PredictionPointAmount + k][parser.FunctionDimension] - new_points[k][parser.FunctionDimension]); Console.WriteLine(" \n " + (points[pointAmount - parser.PredictionPointAmount + k][parser.FunctionDimension] - new_points[k][parser.FunctionDimension]) + " " + points[pointAmount - parser.PredictionPointAmount + k][parser.FunctionDimension] + " " + new_points[k][parser.FunctionDimension] + " \n "); if (err > tempErr) { tempErr = err; } Console.WriteLine("f({0}) real val {1} predict val {2} err {3}", String.Join(", ", xx[k]), points[pointAmount - parser.PredictionPointAmount + k][parser.FunctionDimension], new_points[k][parser.FunctionDimension], err); } maxErr = tempErr; i++; } testResult(parser.FunctionDimension, points, func); return(i); }
private void testResult(int functionDimension, double[][] points, Func <double[], double> func) { Console.WriteLine("\n\nTest result approximation"); Shepard model = new Shepard(functionDimension, points); for (int i = 1; i < 10; i += 2) { double[] a = new double[functionDimension + 1]; double[] b = new double[functionDimension + 1]; for (int j = 0; j < functionDimension; j++) { a[j] = model.Min[j] + ((model.Max[j] - model.Min[j]) * i / 10); b[j] = a[j]; } model.Calculate(a); Console.WriteLine("Vector " + String.Join(", ", b) + " Approximation result " + a[functionDimension] + " real " + func(b) + " error " + Math.Abs(a[functionDimension] - func(b))); } }
private int testWithRandomForest(string configFileToLearn, string pointFileToLearn, string configFile, string pointFile, Func <double[], double> funcToLearn, Func <double[], double[]> derivativeFuncToLearn, Func <double[], double> func, Func <double[], double[]> derivativeFunc) { Parser parserToLearn = new Parser(configFile, pointFile); int pointAmountToLearn = parserToLearn.PointAmount; Shepard model = new Shepard(parserToLearn.FunctionDimension, parserToLearn.Points); Analyzer analyzer = new Analyzer(model, parserToLearn.Points); Classifiers.IClassifier cls = analyzer.learn_random_forest_on_grid(funcToLearn, derivativeFuncToLearn, parserToLearn.Approximation); Parser parser = new Parser(configFile, pointFile); int pointAmount = parser.PointAmount; double[][] points = new double[parser.PointAmount][]; for (int j = 0; j < parser.PointAmount; j++) { points[j] = (double[])parser.Points[j].Clone(); } int i = 0; double maxErr = 10; while (i < 10 && maxErr > parser.Approximation) { model = new Shepard(parser.FunctionDimension, points); analyzer = new Analyzer(model, points); analyzer.do_random_forest_analyse(cls, parser.Approximation, func, derivativeFunc); double[][] xx = analyzer.Result; pointAmount = pointAmount + parser.PredictionPointAmount; double[][] newPoints = new double[pointAmount][]; for (int j = 0; j < pointAmount; j++) { if (j < pointAmount - parser.PredictionPointAmount) { newPoints[j] = (double[])points[j].Clone(); } else { newPoints[j] = (double[])xx[j - pointAmount + parser.PredictionPointAmount].Clone(); newPoints[j][parser.FunctionDimension] = func(newPoints[j]); } } points = newPoints; double[][] new_points = new double[parser.PredictionPointAmount][]; for (int j = 0; j < parser.PredictionPointAmount; j++) { new_points[j] = new double[xx[j].Length]; Array.Copy(xx[j], new_points[j], xx[j].Length); model.Calculate(new_points[j]); } double tempErr = 0; for (int k = 0; k < new_points.Length; k++) { double err = Math.Abs(points[pointAmount - parser.PredictionPointAmount + k][parser.FunctionDimension] - new_points[k][parser.FunctionDimension]); Console.WriteLine(" \n " + (points[pointAmount - parser.PredictionPointAmount + k][parser.FunctionDimension] - new_points[k][parser.FunctionDimension]) + " " + points[pointAmount - parser.PredictionPointAmount + k][parser.FunctionDimension] + " " + new_points[k][parser.FunctionDimension] + " \n "); if (err > tempErr) { tempErr = err; } Console.WriteLine("f({0}) real val {1} predict val {2} err {3}", String.Join(", ", xx[k]), points[pointAmount - parser.PredictionPointAmount + k][parser.FunctionDimension], new_points[k][parser.FunctionDimension], err); } maxErr = tempErr; i++; } testResult(parser.FunctionDimension, points, func); return(i); }