How to fix the error probability plot in Python for MIM and PNS attacks?

  • Context: Python 
  • Thread starter Thread starter Nur Ziadah
  • Start date Start date
  • Tags Tags
    Convert Python
Click For Summary

Discussion Overview

The discussion revolves around the challenges of plotting error probability graphs in Python for MIM and PNS attacks based on specific equations from a paper. Participants are focused on translating mathematical equations into Python code and addressing issues related to the resulting plots.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant describes the need to convert equations related to error probability for MIM and PNS attacks into Python code for plotting.
  • Another participant points out a potential issue in the code regarding division by zero when x=0, suggesting a correction to the parentheses in the equation.
  • A later reply confirms that the corrected code produces a graph that resembles the desired output, although it still encounters a runtime divide error at zero.
  • One participant raises a new concern about the error probability not being plotted correctly at N=0, referencing a previous thread for context.

Areas of Agreement / Disagreement

Participants generally agree on the need to correct the Python code for accurate plotting, but there remains disagreement regarding the specific behavior of the graph at N=0 and whether this constitutes a new problem.

Contextual Notes

The discussion highlights limitations related to handling edge cases in the equations and the potential for runtime errors in the code. The exact conditions under which the equations apply and the definitions of terms are not fully resolved.

Nur Ziadah
Messages
34
Reaction score
3
I have several equations and need to convert it into Python. The problem is that I tried to plot a graph according to the equation. However, the graph that I get is not the same as the original one.

In the paper, the equation of error probability for MIM attack is given by:

First Image
jlPMh.png

Second Image
h99h4.png

The equation to calculate the error probability of PNS attack is given by:
7CsYR.png

Where the region condition satisfied:
0Bxa3.png

The error probability of PNS attack should be plotted like this:
1IwAa.png

My question: How to insert equation 8.1 into equation 8.5?

This is my python code according to equation 8.5:

Python:
import matplotlib.pyplot as plt
import math
import numpy as np
from scipy.special import iv,modstruvex=[0, 5, 10, 15, 20]
t= 0.9
x = np.array(x)
y = (np.exp(x*t/2)*(iv(0, x*t/2) - modstruve(0,x*t/2))-1)/(np.exp(x*t/2-1))                                           

plt.plot(x, y, label='Normal')
plt.xlabel('Mean photon number N')
plt.ylabel('Error probabiity')
plt.scatter(x,y)
plt.title('N/2')
plt.ylim([0, 0.5])
plt.legend()
plt.show()

Please help me regarding this matter.

Thank you.
 

Attachments

  • jlPMh.png
    jlPMh.png
    3.3 KB · Views: 1,196
  • h99h4.png
    h99h4.png
    9.7 KB · Views: 1,260
  • 7CsYR.png
    7CsYR.png
    3.9 KB · Views: 1,188
  • 0Bxa3.png
    0Bxa3.png
    1.5 KB · Views: 1,091
  • 1IwAa.png
    1IwAa.png
    18.6 KB · Views: 1,160
Technology news on Phys.org
When x=0 then N=0 hence the denominator is zero and so you are dividing zero according to the equation.

In your code, you misplaced the last paren. it should look like this:

Python:
y = (   np.exp(x*t/2) * (iv(0,x*t/2) - modstruve(0,x*t/2)) - 1   )  /  (np.exp(x*t/2) - 1)

This code now gives a runtime divide error at zero but the curve looks more like what you want.
 
Thank you so much. Finally I did plot the graph.
 

Similar threads

  • · Replies 21 ·
Replies
21
Views
6K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
10K
  • · Replies 6 ·
Replies
6
Views
2K