Questions tagged [sigmoid]

A sigmoid function is a mathematical function having an "S" shape (sigmoid curve). Often, sigmoid function refers to the special case of the logistic function defined by the formula S ( t ) = 1 / (1 + e^-t)

Sigmoid function (Wikipedia)

256 questions
219
votes
16 answers

How to calculate a logistic sigmoid function in Python?

This is a logistic sigmoid function: I know x. How can I calculate F(x) in Python now? Let's say x = 0.458. F(x) = ?
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
57
votes
2 answers

What is the difference between a sigmoid followed by the cross entropy and sigmoid_cross_entropy_with_logits in TensorFlow?

When trying to get cross-entropy with sigmoid activation function, there is a difference between loss1 = -tf.reduce_sum(p*tf.log(q), 1) loss2 = tf.reduce_sum(tf.nn.sigmoid_cross_entropy_with_logits(labels=p, logits=logit_q),1) But they are the…
38
votes
2 answers

Fit sigmoid function ("S" shape curve) to data using Python

I'm trying to fit a sigmoid function to some data I have but I keep getting:ValueError: Unable to determine number of fit parameters. My data looks like this: My code is: from scipy.optimize import curve_fit def sigmoid(x): return…
user88484
  • 1,249
  • 1
  • 13
  • 34
27
votes
5 answers

ReLU derivative in backpropagation

I am about making backpropagation on a neural network that uses ReLU. In a previous project of mine, I did it on a network that was using Sigmoid activation function, but now I'm a little bit confused, since ReLU doesn't have a derivative. Here's an…
Gergely Papp
  • 800
  • 1
  • 7
  • 12
25
votes
6 answers

Keras retrieve value of node before activation function

Imagine a fully-connected neural network with its last two layers of the following structure: [Dense] units = 612 activation = softplus [Dense] units = 1 activation = sigmoid The output value of the net is 1, but I'd like to know…
johk95
  • 873
  • 10
  • 28
21
votes
2 answers

Keras Binary Classification - Sigmoid activation function

I've implemented a basic MLP in Keras with tensorflow and I'm trying to solve a binary classification problem. For binary classification, it seems that sigmoid is the recommended activation function and I'm not quite understanding why, and how Keras…
Daniel Whettam
  • 345
  • 1
  • 2
  • 9
18
votes
1 answer

Binary classification with Softmax

I am training a binary classifier using Sigmoid activation function with Binary crossentropy which gives good accuracy around 98%. The same when I train using softmax with categorical_crossentropy gives very low accuracy (< 40%). I am passing the…
AKSHAYAA VAIDYANATHAN
  • 2,715
  • 7
  • 30
  • 51
17
votes
6 answers

optimal way of defining a numerically stable sigmoid function for a list in python

For a scalar variable x, we know how to write down a numerically stable sigmoid function in python: def sigmoid(x): if x >= 0: return 1. / ( 1. + np.exp(-x) ) else: return exp(x) / ( 1. + np.exp(x) ) For a list of scalars,…
RandomWalker
  • 765
  • 1
  • 7
  • 10
16
votes
2 answers

Sigmoid output - can it be interpreted as probability?

Sigmoid function outputs a number between 0 and 1. Is this a probability or is it merely a 'yes or no' depending on whether it's above or below 0.5? Minimal example: Cats vs dogs binary classification. 0 is cat, 1 is dog. Can I perform the…
Voy
  • 5,286
  • 1
  • 49
  • 59
14
votes
2 answers

sigmoid in python that can take scalar, vector or matrix

The following code is written in Octave Programming language g =1./(1+e.^-(z) It computes a sigmoid function and can take scalar, vector or Matrix. For example if I put the above into a function sigmoid(z), where z=0, the result will…
sunny
  • 643
  • 2
  • 11
  • 29
14
votes
3 answers

logistic / sigmoid function implementation numerical precision

in scipy.special.expit, logistic function is implemented like the following: if x < 0 a = exp(x) a / (1 + a) else 1 / (1 + exp(-x)) However, I have seen implementations in other languages/frameworks that simply do 1 / (1 +…
colinfang
  • 20,909
  • 19
  • 90
  • 173
6
votes
2 answers

Training MSE loss larger than theoretical maximum?

I am training a keras model whose last layer is a single sigmoid unit: output = Dense(units=1, activation='sigmoid') I am training this model with some training data in which the expected output is always a number between 0.0 and 1.0. I am…
oooliverrr
  • 98
  • 7
6
votes
2 answers

tf.keras.metrics.MeanIoU with sigmoid layer

I have a network for semantic segmentation and the last layer of my model applies a sigmoid activation, so all predictions are scaled between 0-1. There is this validation metric tf.keras.metrics.MeanIoU(num_classes), which compares classified…
WillemBoone
  • 93
  • 1
  • 6
6
votes
2 answers

Sigmoid with Large Number in JavaScript

From what I understand you use a sigmoid function to reduce a number to the range of 0-1. Using the function found in this library function sigmoid(z) { return 1 / (1 + Math.exp(-z)); } This works for a numbers 1-36. Any number higher than this…
Michael Warner
  • 3,879
  • 3
  • 21
  • 45
6
votes
2 answers

Sigmoid function returns 1 for large positive inputs

I wrote the following function in Python to calculate sigmoid function of a scalar, vector or matrix. def sigmoid(z): sig = 1.0/(1.0 + np.exp(-z)) return sig For relatively large positive values of z, e^-z returns a very small value close…
Supratim Haldar
  • 2,376
  • 3
  • 16
  • 26
1
2 3
17 18