+.objfn {dMod}R Documentation

Direct sum of objective functions

Description

Direct sum of objective functions

Usage

## S3 method for class 'objfn'
x1 + x2

Arguments

x1

function of class objfn

x2

function of class objfn

Details

The objective functions are evaluated and their results as added. Sometimes, the evaluation of an objective function depends on results that have been computed internally in a preceding objective function. Therefore, environments are forwarded and all evaluations take place in the same environment. The first objective function in a sum of functions generates a new environment.

Value

Object of class objfn.

See Also

normL2, constraintL2, priorL2, datapointL2

Examples

  ## Generate three objective functions
  prior <- structure(rep(0, 5), names = letters[1:5])
  
  obj1 <- constraintL2(mu = prior, attr.name = "center")
  obj2 <- constraintL2(mu = prior + 1, attr.name = "right")
  obj3 <- constraintL2(mu = prior - 1, attr.name = "left")
  
  ## Evaluate first objective function on a random vector
  pouter <- prior + rnorm(length(prior))
  print(obj1(pouter))
  
  ## Split into fixed and non-fixed part
  fixed <- pouter[4:5]
  pouter <- pouter[1:3]
  print(obj1(pouter, fixed = fixed))
  
  
  ## Visualize the result by a parameter profile
  myfit <- trust(obj1, pouter, rinit = 1, rmax = 10, fixed = fixed)
  myprof <- profile(obj1, myfit$argument, "a", fixed = fixed)
  plotProfile(myprof)
  
  
  ## Create new objective function by adding the single ones,
  ## then evalue the random vector again
  pouter <- prior + rnorm(length(prior))
  obj <- obj1 + obj2 + obj3
  print(obj(pouter))

[Package dMod version 1.0.2 Index]