Are pairwise-convex cost functions also globally-convex? I would like to get a better intuition for a cost function of an optimisation problem. The cost function depends on a number of real-valued arguments. I would like to find out if the cost function is convex.
Obviously I can visualise the cost function for 2 arguments in a 3-dimensional plot. I did this for all pairs of arguments and it turned out that the cost function is convex for all these pairs.
Now I would like to know: does this imply that the cost function is also globally convex?
 A: No.  There is a simple counterexample in two variables that generalizes to more variables: consider
$$f(x,y) = x^2 y^2$$
defined in (say) the square $[0,2]\times[0,2]$.
For fixed $y$, $f$ describes a convex parabola (as a function of $x$) and for fixed $x$ it also describes a convex parabola (as a function of $y$).  The coordinate lines in the figure are examples of these parabolas.

(For clarity, this figure shows a portion of the graph of $f$ restricted to the triangle bounded by $(0,0)$, $(2,0)$, and $(0,2)$.)
However, $f$ is not convex; for instance, although $(1,1) = \frac{1}{2}(2,0) + \frac{1}{2}(0,2)$, 
$$f(1,1) = 1^21^2 = 1 \gt \frac{1}{2} 0 + \frac{1}{2} 0 = \frac{1}{2} f(2,0) + \frac{1}{2} f(0,2),$$
demonstrating $f$ cannot be convex on any domain containing the line segment connecting $(2,0)$ to $(0,2)$: the graph of $f$ on this segment, shown in red, clearly is not convex in most locations.
Because this $f$ is about as well behaved as you might like--it is strictly convex away from the coordinate axes and continuously infinitely differentiable (even analytic)--this counterexample is not due to some special "pathology" that can be made to go away through some inconsequential technical restrictions.
For a counterexample with three variables look at $f(x,y,z) = (x^2+y^2)(y^2+z^2)(z^2+x^2)$ defined within the first octant ($x, y,$ and $z$ all positive).  The determinant of its Hessian is everywhere negative, showing this is not a convex function, but it is convex when any single one of the variables is fixed at a positive value (as you can check by calculating the determinant of its Hessian in the remaining two variables, which will be positive in the first quadrant with positive eigenvalues).
