I want to plot the points of intersection in the following graphs.
Forming concave envelope to sigmoidal functions
The idea is to highlight the point of intersection of the line and sigmoid function and show that we have to reduce the value of upper bound such that the point of intersection and upper bound coincide. This gives the tightest concave envelope.
Therefore, I want to highlight the point of intersection. I looked up Intersection of two graphs in Python, find the x value, but the solutions here require same length of f and g so they can compute np.argwhere(np.diff(np.sign(f - g))).flatten()
I generate a line by simply joining end points and sigmoid by generating many points.
My code is appended below.
import matplotlib.pyplot as plt
import numpy as np
a1 = 5
a2 = 2.5
a3 = 1.75
x = np.linspace(-5, 5, 100)
z = 1 / (1 + np.exp(-x))
x1 = [-5, a1]
y1 = [1 / (1 + np.exp(5)), 1 / (1 + np.exp(-a1))]
x2 = [-5, a2]
y2 = [1 / (1 + np.exp(5)), 1 / (1 + np.exp(-a2))]
x3 = [-5, a3]
y3 = [1 / (1 + np.exp(5)), 1 / (1 + np.exp(-a3))]
plt.figure(figsize=(15,5))
plt.subplot(1,3,1)
plt.plot(x, z, '-b', label='Sigmoid function')
plt.plot(x1, y1, 'o--g', label='Concave envelope', alpha= 0.75)
plt.xlabel("x")
plt.ylabel("Sigmoid(x)")
plt.legend()
plt.grid()
plt.subplot(1,3,2)
plt.plot(x, z, '-b', label='Sigmoid function')
plt.plot(x2, y2, 'o--g', label='Concave envelope', alpha= 0.75)
plt.xlabel("x")
plt.grid()
plt.subplot(1,3,3)
plt.plot(x, z, '-b', label='Sigmoid function')
plt.plot(x3, y3, 'o--g', label='Concave envelope', alpha= 0.75)
plt.xlabel("x")
plt.grid()
#plt.savefig('Sigmoid_ex.png', transparent=True, dpi = 144)
plt.show()
Can anyone suggest a workaround this?