| tags | python,numpy,neural-network,classification,classes,sigmoid,softmax,XOR Classification |
|---|---|
| mathjax | true |
We define n as the softmax output vector index and k as the softmax input vector index. The sum symbol in the formulas below always means "sum over all k" (sum over all input indices).
The softmax function is defined as
The derivative of softmax(x)[n] with respect to x[k] has to be divided into two cases
The case in which n equals k
The case in which n and k are not equal
import numpy_neural_network as npnn
import npnn_datasets
model = npnn.Sequential()
model.layers = [
npnn.Dense(2, 4),
npnn.LeakyReLU(4),
npnn.Dense(4, 4),
npnn.LeakyReLU(4),
npnn.Dense(4, 1),
npnn.Sigmoid(1)
]
loss_layer = npnn.loss_layer.BinaryCrossEntropyLoss(1)
optimizer = npnn.optimizer.Adam(alpha=5e-3)
dataset = npnn_datasets.XORBinClasses()
optimizer.norm = dataset.norm
optimizer.model = model
optimizer.model.chain = loss_layer{:.w70}
XOR Classification using Sigmoid + Binary-Cross-Entropy-Loss
import numpy_neural_network as npnn
import npnn_datasets
model = npnn.Sequential()
model.layers = [
npnn.Dense(2, 4),
npnn.LeakyReLU(4),
npnn.Dense(4, 4),
npnn.LeakyReLU(4),
npnn.Dense(4, 2),
npnn.Softmax(2)
]
loss_layer = npnn.loss_layer.CrossEntropyLoss(2)
optimizer = npnn.optimizer.Adam(alpha=1e-2)
dataset = npnn_datasets.XORTwoClasses()
optimizer.norm = dataset.norm
optimizer.model = model
optimizer.model.chain = loss_layer{:.w70}
XOR Classification using Softmax + Cross-Entropy-Loss