I came up with this code:
def DSigmoid(value):
return (math.exp(float(value))/((1+math.exp(float(value)))**2))
a.) Will this return the correct derivative?
b.) Is this an efficient method?
Friendly regards,
Daquicker
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Looks correct to me. In general, two good ways of checking such a derivative computation are:
Wolfram Alpha. Inputting the sigmoid function
1/(1+e^(-t)), we are given an explicit formula for the derivative, which matches yours. To be a little more direct, you can inputD[1/(1+e^(-t)), t]to get the derivative without all the additional information.Compare it to a numerical approximation. In your case, I will assume you already have a function
Sigmoid(value). TakingDapprox = (Sigmoid(value+epsilon) - Sigmoid(value)) / epsilonfor some small
epsilonand comparing it to the output of your functionDSigmoid(value)should catch all but the tiniest errors. In general, estimating the derivative numerically is the best way to double check that you’ve actually coded the derivative correctly, even if you’re already sure about the formula, and it takes almost no effort.