y=max(0,x)y = \max(0,\,x)

Graph of the Ramp Function y=max(0,x)y = \max(0,\,x)

y=max(0,x)y = \max(0,\,x) returns xx when xx is positive and 00 when it is negative1. Called the ramp function or the positive part, it consists of two half-lines meeting at a corner at the origin. The formula is plain, but as an example sitting on the boundary of differentiability, and as an activation function in machine learning, its reach is wide.

Expression with an absolute value

The larger of two numbers can be written max(a,b)=a+b+ab2\max(a, b) = \dfrac{a + b + |a-b|}{2}. Taking a=0a = 0 and b=xb = x gives the following.

max(0,x)=x+x2\max(0,\,x) = \frac{x + |x|}{2}

The relation also runs the other way.

x=max(0,x)+max(0,x)x=max(0,x)max(0,x)\begin{align*} |x| &= \max(0,\,x) + \max(0,\,-x) \\ x &= \max(0,\,x) - \max(0,\,-x) \end{align*}

The absolute value and the ramp function build each other, through a sum and a difference.

Domain and range

The domain is all real numbers and the range is y0y \geq 0. The graph lies along the xx-axis on the negative side and along the line y=xy = x on the positive side.

Not differentiable at the origin

Rangeyyyy'
x<0x < 00000
x=0x = 000undefined
x>0x > 0xx11

The derivative from the right is 11 and from the left is 00, and they disagree, so the function is not differentiable at the origin. It is continuous, so like the absolute value it is an example of a function that is continuous without being differentiable.

Away from the origin the derivative is the Heaviside step function2. Conversely, integrating the step function gives the ramp function.

Convexity

The function is convex. A segment joining two points on the graph always lies above it, and the single bend turns downward. Allowing translations and scalar multiples, sums of ramp functions produce any convex polyline whatever. That every piecewise linear convex function is a linear combination of ramp functions is the ground on which the applications rest.

Integral

The antiderivative is as follows.

max(0,x)dx=12(max(0,x))2+C\int \max(0,\,x)\,dx = \frac{1}{2}\bigl(\max(0,\,x)\bigr)^{2} + C

It equals 00 for x0x \leq 0 and x22\dfrac{x^{2}}{2} for x>0x > 0. That function is continuous and differentiable once, but its second derivative disagrees at the origin.

FunctionSmoothness at the origin
The Heaviside step functiondiscontinuous
The ramp functioncontinuous but not differentiable
Its antiderivativedifferentiable once

Each integration raises the smoothness by one step, as this shows.

Applications

In machine learning this function goes by the name ReLU and is used as an activation function, widely adopted because the gradient does not easily vanish even through many layers. That the whole network becomes a piecewise linear function follows from the convexity and the superposition just described.

  • The ReLU activation function of machine learning
  • The value of a call option at expiry, max(0,SK)\max(0,\,S-K)
  • Half-wave rectification, which cuts off the negative side of an alternating current
  1. Ramp function, Wikipedia
  2. Heaviside step function, Wikipedia