Qrack  10.0
General classical-emulating-quantum development framework
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Qrack::QNeuron Class Reference

#include <qneuron.hpp>

Public Member Functions

 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. More...
 
 QNeuron (const QNeuron &toCopy)
 Create a new QNeuron which is an exact duplicate of another, including its learned state. More...
 
QNeuronoperator= (QNeuron &toCopy)
 
void SetSimulator (QInterfacePtr sim)
 Replace the simulator. More...
 
void SetIndices (const std::vector< bitLenInt > &inputIndcs, const bitLenInt &outputIndx)
 Replace the input and output indices. More...
 
QInterfacePtr GetSimulator ()
 Retrieve the simulator. More...
 
bitLenInt GetInputCount ()
 
bitCapIntOcl GetInputPower ()
 
real1_f 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. More...
 
real1_f Unpredict (const real1_s *angles, const bool &expected=true, const QNeuronActivationFn &activationFn=Sigmoid, const real1_f &alpha=ONE_R1_F)
 "Uncompute" the Predict() method More...
 
real1_f LearnCycle (real1_s *angles, const bool &expected=true, const QNeuronActivationFn &activationFn=Sigmoid, const real1_f &alpha=ONE_R1_F)
 
void 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. More...
 
void 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. More...
 

Protected Member Functions

real1_f LearnInternal (real1_s *angles, const bool &expected, const real1_f &eta, const bitCapIntOcl &permOcl, const real1_f &startProb, const QNeuronActivationFn &activationFn=Sigmoid, const real1_f &alpha=ONE_R1_F)
 

Static Protected Member Functions

static real1_f applyRelu (const real1_f &angle)
 
static real1_f negApplyRelu (const real1_f &angle)
 
static real1_f applyGelu (const real1_f &angle)
 
static real1_f negApplyGelu (const real1_f &angle)
 
static real1_f applyAlpha (real1_f angle, const real1_f &alpha)
 
static real1_f applyLeakyRelu (const real1_f &angle, const real1_f &alpha)
 
static real1_f clampAngle (real1_f angle)
 

Protected Attributes

bitLenInt outputIndex
 
std::vector< bitLenIntinputIndices
 
QInterfacePtr qReg
 

Constructor & Destructor Documentation

◆ QNeuron() [1/2]

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

"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).

◆ QNeuron() [2/2]

Qrack::QNeuron::QNeuron ( const QNeuron toCopy)
inline

Create a new QNeuron which is an exact duplicate of another, including its learned state.

Member Function Documentation

◆ applyAlpha()

static real1_f Qrack::QNeuron::applyAlpha ( real1_f  angle,
const real1_f alpha 
)
inlinestaticprotected

◆ applyGelu()

static real1_f Qrack::QNeuron::applyGelu ( const real1_f angle)
inlinestaticprotected

◆ applyLeakyRelu()

static real1_f Qrack::QNeuron::applyLeakyRelu ( const real1_f angle,
const real1_f alpha 
)
inlinestaticprotected

◆ applyRelu()

static real1_f Qrack::QNeuron::applyRelu ( const real1_f angle)
inlinestaticprotected

◆ clampAngle()

static real1_f Qrack::QNeuron::clampAngle ( real1_f  angle)
inlinestaticprotected

◆ GetInputCount()

bitLenInt Qrack::QNeuron::GetInputCount ( )
inline

◆ GetInputPower()

bitCapIntOcl Qrack::QNeuron::GetInputPower ( )
inline

◆ GetSimulator()

QInterfacePtr Qrack::QNeuron::GetSimulator ( )
inline

Retrieve the simulator.

◆ Learn()

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 
)
inline

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.

◆ LearnCycle()

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

◆ LearnInternal()

real1_f Qrack::QNeuron::LearnInternal ( real1_s angles,
const bool &  expected,
const real1_f eta,
const bitCapIntOcl permOcl,
const real1_f startProb,
const QNeuronActivationFn activationFn = Sigmoid,
const real1_f alpha = ONE_R1_F 
)
inlineprotected

◆ LearnPermutation()

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 
)
inline

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.

◆ negApplyGelu()

static real1_f Qrack::QNeuron::negApplyGelu ( const real1_f angle)
inlinestaticprotected

◆ negApplyRelu()

static real1_f Qrack::QNeuron::negApplyRelu ( const real1_f angle)
inlinestaticprotected

◆ operator=()

QNeuron& Qrack::QNeuron::operator= ( QNeuron toCopy)
inline

◆ Predict()

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 
)
inline

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.

◆ SetIndices()

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

Replace the input and output indices.

◆ SetSimulator()

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

Replace the simulator.

◆ Unpredict()

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

"Uncompute" the Predict() method

Member Data Documentation

◆ inputIndices

std::vector<bitLenInt> Qrack::QNeuron::inputIndices
protected

◆ outputIndex

bitLenInt Qrack::QNeuron::outputIndex
protected

◆ qReg

QInterfacePtr Qrack::QNeuron::qReg
protected

The documentation for this class was generated from the following file: