/// <summary> /// Construct an initial simplex, given starting guesses for the constants, and /// initial step sizes for each dimension /// </summary> /// <param name="simplexConstants"></param> /// <returns></returns> private static Vector[] _initializeVertices(SimplexConstant[] simplexConstants) { int numDimensions = simplexConstants.Length; Vector[] vertices = new Vector[numDimensions + 1]; // define one point of the simplex as the given initial guesses Vector p0 = new Vector(numDimensions); for (int i = 0; i < numDimensions; i++) { p0[i] = simplexConstants[i].Value; } // now fill in the vertices, creating the additional points as: // P(i) = P(0) + Scale(i) * UnitVector(i) vertices[0] = p0; for (int i = 0; i < numDimensions; i++) { double scale = simplexConstants[i].InitialPerturbation; Vector unitVector = new Vector(numDimensions); unitVector[i] = 1; vertices[i + 1] = p0.Add(unitVector.Multiply(scale)); #if DEBUG Console.Write(i+":" + vertices[i + 1].ToString() + "=="); #endif } #if DEBUG Console.WriteLine(""); #endif return vertices; }
/// <summary> /// Compute the centroid of all points except the worst /// </summary> /// <param name="vertices"></param> /// <param name="errorProfile"></param> /// <returns></returns> private static Vector _computeCentroid(Vector[] vertices, ErrorProfile errorProfile) { int numVertices = vertices.Length; // find the centroid of all points except the worst one Vector centroid = new Vector(numVertices - 1); for (int i = 0; i < numVertices; i++) { if (i != errorProfile.HighestIndex) { centroid = centroid.Add(vertices[i]); } } return centroid.Multiply(1.0d / (numVertices - 1)); }