public ISolution NextPos() { // calculated using Euclidean Distance if (old == null) { InitPos(); } // Calc gradient var grad = Grad(d0, d, old); // - grad * alpha foreach (var pt in grad) { pt[0] = -pt[0] * Alpha; // X pt[1] = -pt[1] * Alpha; // Y } // next_step = old - alpha * grad for (int k = 0; k < n; k++) { grad[k][0] += old.GetArgument()[k][0]; // X grad[k][1] += old.GetArgument()[k][1]; // Y } // save changes and return d = MDS.CalcDistances(grad, MDS.EuclideanDistance); old = new Solution(fun, d0, d, n, grad); return(old); }
private void DrawSolution(ISolution s, double zoom) { int count = 0; switch (polytope) { case Polytope.Simplex: count = Simplex.GetVerticesCount(dimX); break; case Polytope.Hypercube: count = Hypercube.GetVerticesCount(dimX); break; default: break; } double x_avg = 0, y_avg = 0; foreach (var pt in s.GetArgument()) { x_avg += pt[0]; y_avg += pt[1]; } x_avg /= count; y_avg /= count; for (int i = 0; i < count; i++) { v.Points[i].x = (s.GetArgument()[i][0] - x_avg) * zoom + canvas.ActualWidth / 2; v.Points[i].y = (s.GetArgument()[i][1] - y_avg) * zoom + canvas.ActualHeight / 2; } v.Draw(); }
List <double[]> Grad(double[,] d0, double[,] d, ISolution s) { int n = s.GetArgument().Count; double _B = B(d0, n); double _A = A(s); List <double[]> grad = new List <double[]>(); for (int k = 0; k < n; k++) { grad.Add(CalcGradPt(k, d0, d, s, _A, _B)); } return(grad); }
double C(int i, int j, int pt_i, ISolution s, double[,] d0, double B) { return(2.0 / B * (-s.GetArgument()[i][pt_i] + s.GetArgument()[j][pt_i]) * (1 - d0[i, j] / d[i, j])); }