rStats.js v1.3.0
    Preparing search index...

    Function optim

    • General-purpose minimisation of fn from the starting point par. Equivalent to R's optim(). The same methods with the same iterations, so the same results and counts, except CG: after an accepted step it tries the minimum of the parabola through the start and the accepted point, where R's cgmin always tries the midpoint (so CG's path, results and counts differ from R's).

      Parameters

      • par: readonly number[]
      • fn: (par: number[]) => number
      • options: OptimOptions = {}

      Returns OptimResult

      const rosen = (x: number[]) => 100 * (x[1] - x[0] ** 2) ** 2 + (1 - x[0]) ** 2;
      optim([-1.2, 1], rosen).par; // [1.0002601387256695, 1.000505999303765]
      optim([-1.2, 1], rosen, { method: "BFGS" }).counts; // [118, 38]