3
$\begingroup$

I want to generate a plot similar to this one, which allows for different colors when given different parameters : (This is the Moreau-Yosida regularization of the absolute value) Moreau-Yosida of regularization

the Moreau-Yosida regularization is given by :

$$f_{\lambda}(x):= \inf_{u\in \mathbb{R}}\left\lbrace f(u)+ \dfrac{1}{2 \lambda} |x-u|^2 \right\rbrace $$

I want to show these functions in the same plot:

  • Absolute value function
  • the Moreau-Yosida regularization of the $0-norme$ with different values of $\lambda$ to get this kind of color progression (aesthetically, I think a luminosity progression with a single color would look better than the rainbow colors) ( $|x|_0 = 0$ if $x=0$ and $|x|_0 = 1$ otherwise)
  • the Moreau-Yosida regularization of the Absolute value function with different values of $\lambda$ and the same criteria as above.

The following code is my first attempt to set up the visualization I want to get:

Manipulate[
 Plot[{Abs[x], 
   1/(2 \[Lambda]) * (Abs[x]^2 - Max[Abs[x]^2 - 2 \[Lambda], 0]), 
   1/(2 b) * (Abs[x]^2 - Max[Abs[x] - b, 0]^2)}, {x, -2, 
   2}] , {\[Lambda], 1/1000, 1}, {b, 1/1000, 1}]
$\endgroup$
1
  • $\begingroup$ Thank you @dionys for editing, I hope my English get better someday. $\endgroup$ Commented Oct 18, 2014 at 20:10

1 Answer 1

4
$\begingroup$

EDIT

Thank you for comment from ybeltukov: Exclusions->None:

fun[b_, x_] := 1/(2 b)*(Abs[x]^2 - Max[Abs[x] - b, 0]^2)
Legended[ParametricPlot[{u, fun[a, u]}, {u, -2, 2}, {a, 0, 1}, 
  ColorFunction -> {ColorData["Rainbow"][#4] &}, Exclusions -> None, 
  ImageSize -> 500], BarLegend["Rainbow"]] 

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ Exclusions -> None removes artifacts. It is also 2.5 times faster. $\endgroup$
    – ybeltukov
    Commented Oct 18, 2014 at 13:01
  • $\begingroup$ @ybeltukov thank you I have edited $\endgroup$
    – ubpdqn
    Commented Oct 18, 2014 at 13:08
  • $\begingroup$ Thank you very much @ubpdqn. Can you pleas explain the part {ColorData["Rainbow"][#4] &} of the code? ( what is the function of the argument #4 and the & in the end) ;) And how can we do the Color gradient with one color?, say from gray 10 % to gray 100% (black) $\endgroup$ Commented Oct 18, 2014 at 14:03
  • 1
    $\begingroup$ @AymaneFihadi #4 just the slot for b in parameter space (x,b). I suggest looking at documentation of ColorFunction and ColorData and playing. $\endgroup$
    – ubpdqn
    Commented Oct 18, 2014 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.