QNeuron

Defined in qneuron.hpp.

class QNeuron

Activation Functions

enum Qrack::QNeuronActivationFn

Enumerated list of activation functions.

Values:

enumerator Sigmoid

Default.

enumerator ReLU

Rectified linear.

enumerator GeLU

Gaussian linear.

enumerator Generalized_Logistic

Version of (default) “Sigmoid” with tunable sharpness.

enumerator Leaky_ReLU

Leaky rectified linear.

Constructors

inline Qrack::QNeuron::QNeuron(QInterfacePtr reg, const std::vector<bitLenInt> &inputIndcs, const bitLenInt &outputIndx)

“QNeuron” is a “Quantum neuron” or “quantum perceptron” class that can learn and predict in superposition.

This is a simple “quantum neuron” or “quantum perceptron” class, for use of the Qrack library for machine learning. See https://arxiv.org/abs/quant-ph/0410066 (and https://arxiv.org/abs/1711.11240) for the basis of this class’ theoretical concept.

An untrained QNeuron (with all 0 variational parameters) will forward all inputs to 1/sqrt(2) * (|0> + |1>). The variational parameters are Pauli Y-axis rotation angles divided by 2 * Pi (such that a learning parameter of 0.5 will train from a default output of 0.5/0.5 probability to either 1.0 or 0.0 on one training input).

Warning

doxygenfunction: Unable to resolve function “Qrack::QNeuron::QNeuron” with arguments (QNeuron&) in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml. Potential matches:

- QNeuron(QInterfacePtr reg, const std::vector<bitLenInt> &inputIndcs, const bitLenInt &outputIndx)
- QNeuron(const QNeuron &toCopy)

Getters and Setters

inline void Qrack::QNeuron::SetSimulator(QInterfacePtr sim)

Replace the simulator.

inline QInterfacePtr Qrack::QNeuron::GetSimulator()

Retrieve the simulator.

Warning

doxygenfunction: Cannot find function “Qrack::QNeuron::SetAngles” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QNeuron::GetAngles” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

inline bitLenInt Qrack::QNeuron::GetInputCount()
inline bitCapIntOcl Qrack::QNeuron::GetInputPower()

Learning and Prediction

inline real1_f Qrack::QNeuron::Predict(const real1_s *angles, const bool &expected = true, const bool &resetInit = true, const QNeuronActivationFn &activationFn = Sigmoid, const real1_f &alpha = ONE_R1_F)

Predict a binary classification.

Feed-forward from the inputs, loaded in “qReg”, to a binary categorical classification. “expected” flips the binary categories, if false. “resetInit,” if true, resets the result qubit to 0.5/0.5 |0>/|1> superposition before proceeding to predict.

inline real1_f Qrack::QNeuron::Unpredict(const real1_s *angles, const bool &expected = true, const QNeuronActivationFn &activationFn = Sigmoid, const real1_f &alpha = ONE_R1_F)

“Uncompute” the Predict() method

inline real1_f Qrack::QNeuron::LearnCycle(real1_s *angles, const bool &expected = true, const QNeuronActivationFn &activationFn = Sigmoid, const real1_f &alpha = ONE_R1_F)
inline void Qrack::QNeuron::Learn(real1_s *angles, const real1_f &eta, const bool &expected = true, const bool &resetInit = true, const QNeuronActivationFn &activationFn = Sigmoid, const real1_f &alpha = ONE_R1_F)

Perform one learning iteration, training all parameters.

Inputs must be already loaded into “qReg” before calling this method. “expected” is the true binary output category, for training. “eta” is a volatility or “learning rate” parameter with a maximum value of 1.

In the feedback process of learning, default initial conditions forward untrained predictions to 1/sqrt(2) * (|0>

  • |1>) for the output bit. If you want to initialize other conditions before “Learn(),” set “resetInit” to false.

inline void Qrack::QNeuron::LearnPermutation(real1_s *angles, const real1_f &eta, const bool &expected = true, const bool &resetInit = true, const QNeuronActivationFn &activationFn = Sigmoid, const real1_f &alpha = ONE_R1_F)

Perform one learning iteration, measuring the entire QInterface and training the resulting permutation.

Inputs must be already loaded into “qReg” before calling this method. “expected” is the true binary output category, for training. “eta” is a volatility or “learning rate” parameter with a maximum value of 1.

In the feedback process of learning, default initial conditions forward untrained predictions to 1/sqrt(2) * (|0>

  • |1>) for the output bit. If you want to initialize other conditions before “LearnPermutation(),” set “resetInit” to false.