| Prev | Next |  |  |  |  |  |  |

Create An Abs-normal Representation of a Function
Syntax
`f.abs_normal_fun(g, a)`
f
The object `f` has prototype `
const ADFun<Base>& f
` It represents a function f : R n → R m . We assume that the only non-smooth terms in the representation are absolute value functions and use s ∈ Z + to represent the number of these terms.
n
We use `n` to denote the dimension of the domain space for `f` .
m
We use `m` to denote the dimension of the range space for `f` .
s
We use `s` to denote the number of absolute value terms in `f` .
a
The object `a` has prototype `
ADFun<Base> a
` The initial function representation in `a` is lost. Upon return it represents the result of the absolute terms a : R n → R s ; see a ( x ) defined below. Note that `a` is constructed by copying `f` and then changing the dependent variables. There may be many calculations in this representation that are not necessary and can be removed using `
a.optimize()
` This optimization is not done automatically by `abs_normal_fun` because it may take a significant amount of time.
zeta
Let ζ 0 ( x ) denote the argument for the first absolute value term in f ( x ) , ζ 1 ( x , | ζ 0 ( x ) | ) for the second term, and so on.
a(x)
For i = 0 , … , s -1 define a i ( x ) = | ζ i ( x , a 0 ( x ) , … , a i -1 ( x ) ) | This defines a : R n → R s .
g
The object `g` has prototype `
ADFun<Base> g
` The initial function representation in `g` is lost. Upon return it represents the smooth function g : R n + s → R m + s is defined by g ( x , u ) = [ y ( x , u ) z ( x , u ) ] were y ( x , u ) and z ( x , u ) are defined below.
z(x, u)
Define the smooth function z : R n + s → R s by z i ( x , u ) = ζ i ( x , u 0 , … , u i -1 ) Note that the partial of z i with respect to u j is zero for j ≥ i .
y(x, u)
There is a smooth function y : R n + s → R m such that y ( x , u ) = f ( x ) whenever u = a ( x ) .
Affine Approximation
We define the affine approximations y [ x ^ ] ( x , u ) = y ( x ^ , a ( x ^ ) ) + ∂ x y ( x ^ , a ( x ^ ) ) ( x - x ^ ) + ∂ u y ( x ^ , a ( x ^ ) ) ( u - a ( x ^ ) ) z [ x ^ ] ( x , u ) = z ( x ^ , a ( x ^ ) ) + ∂ x z ( x ^ , a ( x ^ ) ) ( x - x ^ ) + ∂ u z ( x ^ , a ( x ^ ) ) ( u - a ( x ^ ) ) It follows that y ( x , u ) = y [ x ^ ] ( x , u ) + o ( x - x ^ , u - a ( x ^ ) ) z ( x , u ) = z [ x ^ ] ( x , u ) + o ( x - x ^ , u - a ( x ^ ) )
Abs-normal Approximation
Approximating a(x)
The function a ( x ) is not smooth, but it is equal to | z ( x , u ) | when u = a ( x ) . Furthermore z [ x ^ ] ( x , u ) = z ( x ^ , a ( x ^ ) ) + ∂ x z ( x ^ , a ( x ^ ) ) ( x - x ^ ) + ∂ u z ( x ^ , a ( x ^ ) ) ( u - a ( x ^ ) ) The partial of z i with respect to u j is zero for j ≥ i . It follows that z i [ x ^ ] ( x , u ) = z i ( x ^ , a ( x ^ ) ) + ∂ x z i ( x ^ , a ( x ^ ) ) ( x - x ^ ) + ∑ j < i ∂ u ( j ) z i ( x ^ , a ( x ^ ) ) ( u j - a j ( x ^ ) ) Considering the case i = 0 we define a 0 [ x ^ ] ( x ) = | z 0 [ x ^ ] ( x , u ) | = |z 0 ( x ^ , a ( x ^ ) ) + ∂ x z 0 ( x ^ , a ( x ^ ) ) ( x - x ^ ) | It follows that a 0 ( x ) = a 0 [ x ^ ] ( x ) + o ( x - x ^ ) In general, we define a i [ x ^ ] using a j [ x ^ ] for j < i as follows: a i [ x ^ ] ( x ) = |z i ( x ^ , a ( x ^ ) ) + ∂ x z i ( x ^ , a ( x ^ ) ) ( x - x ^ ) + ∑ j < i ∂ u ( j ) z i ( x ^ , a ( x ^ ) ) ( a j [ x ^ ] ( x ) - a j ( x ^ ) ) | It follows that a ( x ) = a [ x ^ ] ( x ) + o ( x - x ^ ) Note that in the case where z ( x , u ) and y ( x , u ) are affine, a [ x ^ ] ( x ) = a ( x )
Approximating f(x) f ( x ) = y ( x , a ( x ) ) = y [ x ^ ] ( x , a [ x ^ ] ( x ) ) + o ( Δ x )
Correspondence to Literature
Using the notation Z = ∂ x z ( x ^ , u ^ ) , L = ∂ u z ( x ^ , u ^ ) , J = ∂ x y ( x ^ , u ^ ) , Y = ∂ u y ( x ^ , u ^ ) , the approximation for z and y are z [ x ^ ] ( x , u ) = z ( x ^ , a ( x ^ ) ) + Z ( x - x ^ ) + L ( u - a ( x ^ ) ) y [ x ^ ] ( x , u ) = y ( x ^ , a ( x ^ ) ) + J ( x - x ^ ) + Y ( u - a ( x ^ ) ) Moving the terms with x ^ together, we have z [ x ^ ] ( x , u ) = z ( x ^ , a ( x ^ ) ) - Z x ^ - L a ( x ^ ) + Z x + L u y [ x ^ ] ( x , u ) = y ( x ^ , a ( x ^ ) ) - J x ^ - Y a ( x ^ ) + J x + Y u Using the notation c = z ( x ^ , u ^ ) - Z x ^ - L u ^ , b = y ( x ^ , u ^ ) - J x ^ - Y u ^ , we have z [ x ^ ] ( x , u ) = c + Z x + L u y [ x ^ ] ( x , u ) = b + J x + Y u Considering the affine case, where the approximations are exact, and choosing u = a ( x ) = | z ( x , u ) | , we obtain z ( x , a ( x ) ) = c + Z x + L | z ( x , a ( x ) ) | y ( x , a ( x ) ) = b + J x + Y | z ( x , a ( x ) ) | This is Equation (2) of the reference .
Example
The file abs_get_started.cpp contains an example and test using this operation.

Input File: cppad/core/abs_normal_fun.hpp