numpymatplotlibdistributionsigmoidbeta-distribution

How to get a sigmoid function between 0 and 1 for probability of correct answer?


I am trying to simulate some data where a response can either be right (1) or wrong (0). I am thus trying to find a distribution in which there are four conditions (in this case degrees of a circle).

Thus, the x axis is pi/2, pi, pi1.5, 2pi. I have normalised this from 0 to 1 to make this easier. On the y axis I would like the probability of answering correct so is 0-1 or 0-100 etc. I am trying to generate/plot a sigmoid function such that the probability is higher when the condition is closer to 1 and lower when the condition is closer to 0.

I cannot seem to be able to generate the sigmoid between 0 and 1, it just gives me a straight line unless i set x = np.linspace (-10,10,10). How can I do this? The code I currently have is below. Thank you!

I was originally going to use a beta distribution as this is better suited (as it is degrees around a circle) but cannot seem to get it into the shape I want. Any help would be greatly appreciated!

def sigmoid(x,x0=0,k=0.5):
            return (1 / (1 + np.exp(-x)))
x = np.linspace(0,1,10)

Solution

  • As you are happy with normalising to the range [0,1], consider normalising to [-1,1]

    import numpy as np
    import matplotlib.pyplot as plt
    
    def norm(x):
        # normalise x to range [-1,1]
        nom = (x - x.min()) * 2.0
        denom = x.max() - x.min()
        return  nom/denom - 1.0
    
    def sigmoid(x, k=0.1):
        # sigmoid function
        # use k to adjust the slope
        s = 1 / (1 + np.exp(-x / k)) 
        return s
    
    # un-normalised data
    x = np.linspace(-4,+4,100)
    # normalise the data
    x = norm(x) 
    
    plt.plot(x, sigmoid(x))
    plt.show()
    

    Sigmoid activation function