/// Set the pixel shader. public void SetPixelShader <T>(T shader) where T : struct, IPixelShader { var impl = new RasterizerImpl <T>(shader, this); m_triangleFunc = impl.DrawTriangleModeTemplate; m_lineFunc = impl.DrawLineTemplate; m_pointFunc = impl.DrawPointTemplate; }
/// <summary> /// Finds approximate minimum of the function /// </summary> /// <param name="function">Function to minimize</param> /// <param name="initial">Initial point</param> /// <param name="result">Approximate minimum</param> public void Minimize(DifferentiableFunction function, ref VBuffer <Float> initial, ref VBuffer <Float> result) { Contracts.Check(FloatUtils.IsFinite(initial.Values, initial.Count), "The initial vector contains NaNs or infinite values."); LineFunc lineFunc = new LineFunc(function, ref initial, UseCG); VBuffer <Float> prev = default(VBuffer <Float>); initial.CopyTo(ref prev); for (int n = 0; _maxSteps == 0 || n < _maxSteps; ++n) { Float step = LineSearch.Minimize(lineFunc.Eval, lineFunc.Value, lineFunc.Deriv); var newPoint = lineFunc.NewPoint; bool terminateNow = n > 0 && TerminateTester.ShouldTerminate(ref newPoint, ref prev); if (terminateNow || Terminate(ref newPoint)) { break; } newPoint.CopyTo(ref prev); lineFunc.ChangeDir(); } lineFunc.NewPoint.CopyTo(ref result); }