Table of Contents

This function creates a new MxRObjective object.

mxRObjective(objfun, ...)

`objfun:`

A function that accepts two arguments.

`...:`

The initial state information to the objective function.

The objfun argument must be a function that accepts two arguments. The first argument is the mxModel that should be evaluated, and the second argument is some persistent state information that can be stored between one iteration of optimization to the next iteration. It is valid for the function to simply ignore the second argument.

The function must return either a single numeric value, or a list of exactly two elements. If the function returns a list, the first argument must be a single numeric value and the second element will be the new persistent state information to be passed into this function at the next iteration. The single numeric value will be used by the optimizer to perform optimization.

The initial default value for the persistant state information is NA.

Returns a new MxRObjective object.

A <- mxMatrix(nrow = 2, ncol = 2, values = c(1:4), free = TRUE, name = 'A') squared <- function(x) { x ^ 2 } objFunction <- function(model, state) { values <- model[['A']]@values return(squared(values[1,1] - 4) + squared(values[1,2] - 3) + squared(values[2,1] - 2) + squared(values[2,2] - 1)) } objective <- mxRObjective(objFunction) model <- mxModel('model', A, objective)

- Printer-friendly version
- Login or register to post comments
- Send to friend