How to plot integration equation using Python?

Click For Summary

Discussion Overview

The discussion revolves around plotting integration equations using Python, specifically focusing on the error probability of authentication in normal operation and under a MIM attack. Participants explore the challenges faced in achieving accurate plots that match expected results, including issues with the underlying equations and code implementation.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes their attempt to plot error probabilities using Python, noting discrepancies between their generated graph and an expected original graph.
  • Another participant references a previous thread, questioning whether the original poster addressed earlier suggestions or corrections.
  • Several participants express curiosity about the equations used, with questions about specific mathematical operations and the implementation of numpy for array operations.
  • Some participants suggest improvements for code readability, such as consistent color usage for plots and clearer variable naming.
  • A participant indicates that the curve for the normal authentication probability appears correct, but questions remain about the MIM case and the lack of an explicit expression for it.
  • There is a suggestion to seek clarification from the original source of the equations to better understand the plotting requirements.
  • Another participant proposes that the issue may stem from not knowing what to plot rather than a coding error, advising to focus on understanding the equations first.

Areas of Agreement / Disagreement

Participants express uncertainty regarding the correct expression for the MIM case and the differences between the error probabilities. There is no consensus on the correct approach to plotting the MIM error probability, and multiple viewpoints on the source of the problem are presented.

Contextual Notes

Participants note that the original equations for the MIM case are not provided, leading to difficulties in reproducing the expected plots. There are also mentions of potential typos in the code that could affect the results.

Nur Ziadah
Messages
34
Reaction score
3
I have a few of integration equations and need to convert it into Python. The problem is when I tried to plot a graph according to the equation, some of the plot is not same with the original one.

The first equation is the error probability of authentication in normal operation:
upload_2018-12-29_12-2-16.png

cond equation is the error probability of authentication under MIM attack:
upload_2018-12-29_12-2-48.png

The error probability of authentication in normal operation can be calculated by:
upload_2018-12-29_12-3-56.png

Supposedly, the graph (original) will be shown like this:
upload_2018-12-29_12-4-42.png


y-axis: error probability
x-axis: N
Pe^normal = blue lines
Pe^MIM = red lines
Differences between two error probabilities (Pe^MIM - Pe^normal)= green lines

I tried to code it into Python and this is my full codes:

Python:
import matplotlib.pyplot as plt
import math
import numpy as np
from scipy.special import iv,modstruve

x=np.arange(-0.5,21,1)
x = np.array(x)
t = 0.9
pe_normal = (np.exp(t*x/2)*(iv(0, t*x/2) - modstruve(0,t*x/2))-1)/(np.exp(t*x)-1)
pe_diff = (np.exp((1-t**2)*x/2)*(iv(0, (1-t**2)*x/2) - modstruve(0,(1-t**2)*x/2))-1)/(np.exp((1-t**2)*x)-1)
pe_mim= np.add(pe_normal,pe_diff)plt.plot(x, pe_normal, '-', color='blue', label='Normal')
plt.plot(x, pe_mim,  '-', color='red', label='MIM')
plt.plot(x, pe_diff,  '-', color='green', label='DIFF')
plt.xlabel('Mean photon number N')
plt.ylabel('Error probabiity')
plt.text(10, 0.4, 't=0.9', size=12, ha='center', va='center')
plt.ylim([0, 0.5])
plt.xlim([0, 20])
plt.legend()
plt.show()

The graph produce from my code is:

upload_2018-12-29_14-29-55.png


It looks like that my plot is not same with the original one in terms N=0 of Pe^MIM (red line) and differences between two error probabilities (green line). The problem is the calculation for error probability under MIM attack was not given.

I hope that anyone may help me to solve this problem.

Thank you.
 

Attachments

  • upload_2018-12-29_12-2-16.png
    upload_2018-12-29_12-2-16.png
    2 KB · Views: 1,546
  • upload_2018-12-29_12-2-48.png
    upload_2018-12-29_12-2-48.png
    2.6 KB · Views: 1,320
  • upload_2018-12-29_12-3-56.png
    upload_2018-12-29_12-3-56.png
    5.7 KB · Views: 1,481
  • upload_2018-12-29_12-4-42.png
    upload_2018-12-29_12-4-42.png
    2.7 KB · Views: 1,444
  • upload_2018-12-29_12-7-29.png
    upload_2018-12-29_12-7-29.png
    6.3 KB · Views: 613
  • afNIG.png
    afNIG.png
    1.9 KB · Views: 607
  • upload_2018-12-29_14-29-55.png
    upload_2018-12-29_14-29-55.png
    6 KB · Views: 1,383
Last edited:
Technology news on Phys.org
Ahh okay. I’ll look at it some more. Python and it’s plot capability is really awesome.
 
Yes
jedishrfu said:
Ahh okay. I’ll look at it some more. Python and it’s plot capability is really awesome.
Yes. It is very interesting to play around with python. However, I felt some headache to understand the equation.
Thank you for your attention and help for the previous post.
Really appreciate it.
 
A couple of questions:

- so the t**2 means to square the t value right? Okay I found this is correct.

- and the z2 = y + z adds the elements of y to the elements of z to get an array of z2 right?

I thought maybe you need to use numpy to do the element by element addition.

I didn’t see the equation that you used to code the z = line
 
jedishrfu said:
A couple of questions:

- so the t**2 means to square the t value right? Okay I found this is correct.

- and the z2 = y + z adds the elements of y to the elements of z to get an array of z2 right?

I thought maybe you need to use numpy to do the element by element addition.

I didn’t see the equation that you used to code the z = line

1. Yes. t**2 is the square the t value
2. Yes. z2 = element of y + element of z
3. z line is (1-t**2)N, which is replacing tN in Pe^(aut,normal)
 
jedishrfu said:
For numpy:

Python:
z2 = np.add(y,z)

I have tried it. However, it shows the same graph that I have been plotted before.
upload_2018-12-29_13-22-17.png
 

Attachments

  • upload_2018-12-29_13-22-17.png
    upload_2018-12-29_13-22-17.png
    6.3 KB · Views: 1,372
  • #10
While I don’t see exactly what’s wrong, I do see places where you could improve the readability of your code.

1) use the same colors for the curves to make easier to compare the expected graph to the one you generated

2) label your variables like pe_mim, pe_normal, pe_diff

3) I don’t see where you’re doing the pe_diff calculation and this may be the source of your problem,
 
  • #11
jedishrfu said:
For numpy:

Python:
z2 = np.add(y,z)

I have tried it. However, it shows the same graph that I have been plotted before.
View attachment 236522
jedishrfu said:
While I don’t see exactly what’s wrong, I do see places where you could improve the readability of your code.

1) use the same colors for the curves to make easier to compare the expected graph to the one you generated

2) label your variables like pe_mim, pe_normal, pe_diff

3) I don’t see where you’re doing the pe_diff calculation and this may be the source of your problem,

I already updated the code and the graph in the question.
 
  • #12
Your curve for ##P_e^{Auth,Normal}(t,N)## looks right. Therefore the problem is in your MIM case. You don't seem to have written out an explicit expression for ##P^{Auth,MIM}_e(t,N)##. Reverse engineering your code, you have implemented $$P_e^{Auth,MIM}(t,N)=
{{\left(I_0\left({{\left(1-t^2\right)N}\over{2}}\right)-
L_0\left({{\left(1-t^2\right)N}\over{2}}\right)
\right)e^{{{\left(1-t^2\right)N}/{2}}}-1}\over{e^{\left(1-t^
2\right)N}-1}}+{{\left(I_0\left({{tN}\over{2}}\right)-
L_0\left({{tN}\over{2}}\right)\right)e^{{{tN
}/{2}}}-1}\over{e^{tN}-1}}$$(Edit: replaced x with N above.) I presume this is incorrect.
 
Last edited:
  • Like
Likes   Reactions: jedishrfu
  • #13
Ibix said:
Your curve for ##P_e^{Auth,Normal}(t,N)## looks right. Therefore the problem is in your MIM case. You don't seem to have written out an explicit expression for ##P^{Auth,MIM}_e(t,N)##. Reverse engineering your code, it is $$P_e^{Auth,MIM}(t,N)=
{{\left(I_0\left({{\left(1-t^2\right)x}\over{2}}\right)-
L_0\left({{\left(1-t^2\right)x}\over{2}}\right)
\right)e^{{{\left(1-t^2\right)x}/{2}}}-1}\over{e^{\left(1-t^
2\right)x}-1}}-{{\left(I_0\left({{tx}\over{2}}\right)-
L_0\left({{tx}\over{2}}\right)\right)e^{{{tx
}/{2}}}-1}\over{e^{tx}-1}}$$I presume this is incorrect.

How to write the expression for ##P^{Auth,MIM}_e(t,N)##? Do you have any idea, what is the equation to plot ##P^{Auth,MIM}_e(t,N)##?
 
Last edited:
  • #14
I've no idea. I simply reverse engineered your code in the hope that you would see a typo or something.

You seem to have a source with at least some of the maths in it - what does it say? And you have the graph you want to replicate - how was it generated?
 
  • #15
Ibix said:
I simply reverse engineered your code in the hope that you would see a typo or something.
...speaking of which, it should be a plus between the fractions. Now corrected above.
 
  • #16
Ibix said:
...speaking of which, it should be a plus between the fractions. Now corrected above.
Yes. I realized it. It is stated that
upload_2018-12-29_16-57-23.png
. However, I don't think that they used another equation to calculate pe_mim.
 

Attachments

  • upload_2018-12-29_16-57-23.png
    upload_2018-12-29_16-57-23.png
    1.1 KB · Views: 888
  • #17
Then what is the expression given for the difference? Is it consistent with the expression I gave in #12?
 
  • #18
Actually, I didn't have any idea.
 
  • #19
Then where did you get what you implemented in the code?
 
  • #20
Ibix said:
Then where did you get what you implemented in the code?
I will try to ask about the equation from the author of the paper. Hopefully he will response my questions.
 
  • #21
A good idea. It seems to me that the problem is you don't know what to plot, not a problem with the actual plotting. You might get more help with that if you provide a link to the paper and start a thread asking for help understanding that, rather than focussing on the python. Your code seems to be right in the sense that it's doing what you ask - your problem is that you don't know what exactly you want it to do.
 
  • #22
Ibix said:
A good idea. It seems to me that the problem is you don't know what to plot, not a problem with the actual plotting. You might get more help with that if you provide a link to the paper and start a thread asking for help understanding that, rather than focussing on the python. Your code seems to be right in the sense that it's doing what you ask - your problem is that you don't know what exactly you want it to do.
That is the good idea. I will start a new thread and asking about the equations.
 

Similar threads

Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
991
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K