0

I want to define my loss function as following picture

enter image description here

How can i do this?

3 Answers3

2

I can make three proposals, but you can mix the first two.

However, I'd prefer the simpler third way.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

First way
\[
L_\varepsilon\bigl(y,f(x,w)\bigr)=
\begin{cases}
0 & \bigl|y-f(x,w)\bigr|\leq\varepsilon,\\
\bigl|y-f(x,w)\bigr|-\varepsilon & \text{otherwise},
\end{cases}
\]

Second way
\[
L_\varepsilon(y,f(x,w))=
\begin{cases}
0                      & |y-f(x,w)|\leq\varepsilon,\\
|y-f(x,w)|-\varepsilon & \hfill\text{otherwise},
\end{cases}
\]

Third way
\[
L_\varepsilon(y,f(x,w))=
\max\{0, |y-f(x,w)|-\varepsilon\}
\]

\end{document}

enter image description here

egreg
  • 1,121,712
1

Here there is my welcome to TeX.SE. Your screenshot seem the font Cambria and I have created the similar image that you have glued. Therefore I have used, before, fontspec package that you can compile with XeLaTeX.

enter image description here

\documentclass[12pt]{article}
\usepackage{unicode-math} 
\usepackage{fontspec}
\setmainfont{Cambria}
\setmathfont{Cambria Math}

\begin{document}
\[L_\varepsilon\bigl(y,f(x,w)\bigr)=
\begin{cases}
0 & |y-f(x,w)|\leq\varepsilon;\\
\bigl|y-f(x,w)\bigr|-\varepsilon &\mathit{ otherwise,}
\end{cases}
\]

\end{document}

You can use also the classic pdfLaTeX that when you compile obtain this output:

enter image description here

\documentclass[12pt]{article}
\usepackage{amsmath} 
\usepackage{amssymb}

\begin{document}
\[L_\varepsilon\bigl(y,f(x,w)\bigr)=
\begin{cases}
0 & |y-f(x,w)|\leq\varepsilon;\\
\bigl|y-f(x,w)\bigr|-\varepsilon &\mathit{otherwise,}
\end{cases}
\]

\end{document}
Sebastiano
  • 54,118
0
\[
L_\varepsilon(y,f(x,w)=\begin{cases}
  0&|y-f(x,w)|\le\varepsilon;\\
  |y-f(x,w)|-\varepsilon&\text{otherwise,}
\end{cases}
\]

(where I assume that some environment causes the italics of what should be \text in your original; also I find the use of comma vs. semicolon confusing)

or perhaps use the mathematically equivalent

\[ L_\varepsilon(y,f(x,w)=\max\{0,|y-f(x,w)|-\varepsilon\} \]