In the variational classifier demo from Pennylane, the data loading is performed with

data = np.loadtxt("variational_classifier/data/iris_classes1and2_scaled.txt")
X = data[:, 0:2]
print("First X sample (original)  :", X[0])

# pad the vectors to size 2^2 with constant values
padding = 0.3 * np.ones((len(X), 1))
X_pad = np.c_[np.c_[X, padding], np.zeros((len(X), 1))]
print("First X sample (padded)    :", X_pad[0])

# More code following...

Why are the 2 feature data from the IRIS dataset padded to make 4 features before calculating the angles? What is the significance of this padding?


1 Answer 1


If you do not create these "latent dimensions" with padding, the normalisation of the input vector looses all information on the length of the input. Decision boundaries would therefore have a very simplistic, radial shape like shown here:

enter image description here

With padding, the normalisation implicitly writes information about the length into the added dimensions and decision boundaries can be a bit more interesting.

For some datasets padding might not be important, but in the simple example used in the demo the classifier would probably not learn very well.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.