8
$\begingroup$

I have the formula, the renyi entropy $\frac{1}{1-q}ln(\sum_{i=1}^Np_i^q)$, and the figure I haven't seen before, is it the ContourPlot for N=3 (the condition is $0\le p_1\le1,0\le p_2\le1,p_1+p_2+p_3=1$)?enter image description here

I only get this:

q = 2;
S1 = 1/(1 - q) Log[p1^q + p2^q + (1 - p2 - p1)^q];
ContourPlot[S1, {p1, 0, 1}, {p2, 0, 1}]

enter image description here

$\endgroup$

1 Answer 1

12
$\begingroup$

We need to use ternary coordinate,that is we need to mapping the set

{p1,p2,p3}, p1+p2+p3==1,p1>0,p2>0,p3>0

to {x,y} coordinate.

Clear[q, f, ternary, inverseternary, reg, inversereg];
q = 2;
f[{p1_, p2_, p3_}] = 1/(1 - q) Log[p1^q + p2^q + p3^q];
ternary[{p1_, p2_, p3_}] = {p1 + 1/2 p2, Sqrt[3]/2 p2};
inverseternary[{x_, y_}] = {p1, p2, p3} /. 
   Solve[{x == p2 + 1/2 p3, y == Sqrt[3]/2 p3, 
      p1 + p2 + p3 == 1}, {p1, p2, p3}][[1]];
reg = ImplicitRegion[{p1 > 0, p2 > 0, p3 > 0, p1 + p2 + p3 == 1}, {p1,
     p2, p3}];
inversereg = TransformedRegion[reg, ternary];
ContourPlot[f[inverseternary[{x, y}]], {x, 0, 1}, {y, 0, 1}, 
 RegionFunction -> Function[{x, y}, {x, y} ∈ inversereg], 
 Contours -> 20, PlotLegends -> Automatic]

enter image description here

$\endgroup$
10
  • $\begingroup$ Amazing! You are so great! $\endgroup$
    – Mengr
    Aug 28, 2022 at 13:11
  • $\begingroup$ What if I change the function with "-p1 Log[p1] - p2 Log[p2] - p3 Log[p3] + Log[p1^2 + p2^2 + p3^2]", should I change "p2 + 1/2 p3, Sqrt[3]/2 p3"? $\endgroup$
    – Mengr
    Aug 28, 2022 at 13:17
  • $\begingroup$ @KarryMa For the coordinate transformation about ternary, we can read the document ref/TernaryListPlot or online reference.wolfram.com/language/ref/TernaryListPlot.html $\endgroup$
    – cvgmt
    Aug 28, 2022 at 13:19
  • $\begingroup$ So the picture I plot is in the rectangular coordinates and this is in barycentric coordinate system, right? $\endgroup$
    – Mengr
    Aug 28, 2022 at 13:24
  • $\begingroup$ @KarryMa Yes,you are right. $\endgroup$
    – cvgmt
    Aug 28, 2022 at 13:25

Your Answer

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

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