Qrack  9.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, bitLenInt outputIndx, QNeuronActivationFn activationFn=Sigmoid, real1_f alpha=ONE_R1_F, real1_f tol=FP_NORM_EPSILON)
 "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= (const QNeuron &toCopy)
 
void SetAlpha (real1_f a)
 Set the "alpha" sharpness parameter of this QNeuron. More...
 
real1_f GetAlpha ()
 Get the "alpha" sharpness parameter of this QNeuron. More...
 
void SetActivationFn (QNeuronActivationFn f)
 Sets activation function enum. More...
 
QNeuronActivationFn GetActivationFn ()
 Get activation function enum. More...
 
void SetAngles (real1 *nAngles)
 Set the angles of this QNeuron. More...
 
void GetAngles (real1 *oAngles)
 Get the angles of this QNeuron. More...
 
bitLenInt GetInputCount ()
 
bitCapInt GetInputPower ()
 
real1_f Predict (bool expected=true, bool resetInit=true)
 Predict a binary classification. More...
 
real1_f Unpredict (bool expected=true)
 "Uncompute" the Predict() method More...
 
real1_f LearnCycle (bool expected=true)
 
void Learn (real1_f eta, bool expected=true, bool resetInit=true)
 Perform one learning iteration, training all parameters. More...
 
void LearnPermutation (real1_f eta, bool expected=true, bool resetInit=true)
 Perform one learning iteration, measuring the entire QInterface and training the resulting permutation. More...
 

Protected Member Functions

real1_f LearnInternal (bool expected, real1_f eta, bitCapInt perm, real1_f startProb)
 

Static Protected Member Functions

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

Protected Attributes

bitCapIntOcl inputPower
 
bitLenInt outputIndex
 
QNeuronActivationFn activationFn
 
real1_f alpha
 
real1_f tolerance
 
std::vector< bitLenIntinputIndices
 
std::unique_ptr< real1[]> angles
 
QInterfacePtr qReg
 

Constructor & Destructor Documentation

◆ QNeuron() [1/2]

Qrack::QNeuron::QNeuron ( QInterfacePtr  reg,
const std::vector< bitLenInt > &  inputIndcs,
bitLenInt  outputIndx,
QNeuronActivationFn  activationFn = Sigmoid,
real1_f  alpha = ONE_R1_F,
real1_f  tol = FP_NORM_EPSILON 
)
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,
real1_f  alpha 
)
inlinestaticprotected

◆ applyGelu()

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

◆ applyLeakyRelu()

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

◆ applyRelu()

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

◆ clampAngle()

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

◆ GetActivationFn()

QNeuronActivationFn Qrack::QNeuron::GetActivationFn ( )
inline

Get activation function enum.

◆ GetAlpha()

real1_f Qrack::QNeuron::GetAlpha ( )
inline

Get the "alpha" sharpness parameter of this QNeuron.

◆ GetAngles()

void Qrack::QNeuron::GetAngles ( real1 oAngles)
inline

Get the angles of this QNeuron.

◆ GetInputCount()

bitLenInt Qrack::QNeuron::GetInputCount ( )
inline

◆ GetInputPower()

bitCapInt Qrack::QNeuron::GetInputPower ( )
inline

◆ Learn()

void Qrack::QNeuron::Learn ( real1_f  eta,
bool  expected = true,
bool  resetInit = true 
)
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 ( bool  expected = true)
inline

◆ LearnInternal()

real1_f Qrack::QNeuron::LearnInternal ( bool  expected,
real1_f  eta,
bitCapInt  perm,
real1_f  startProb 
)
inlineprotected

◆ LearnPermutation()

void Qrack::QNeuron::LearnPermutation ( real1_f  eta,
bool  expected = true,
bool  resetInit = true 
)
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 ( real1_f  angle)
inlinestaticprotected

◆ negApplyRelu()

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

◆ operator=()

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

◆ Predict()

real1_f Qrack::QNeuron::Predict ( bool  expected = true,
bool  resetInit = true 
)
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.

◆ SetActivationFn()

void Qrack::QNeuron::SetActivationFn ( QNeuronActivationFn  f)
inline

Sets activation function enum.

◆ SetAlpha()

void Qrack::QNeuron::SetAlpha ( real1_f  a)
inline

Set the "alpha" sharpness parameter of this QNeuron.

◆ SetAngles()

void Qrack::QNeuron::SetAngles ( real1 nAngles)
inline

Set the angles of this QNeuron.

◆ Unpredict()

real1_f Qrack::QNeuron::Unpredict ( bool  expected = true)
inline

"Uncompute" the Predict() method

Member Data Documentation

◆ activationFn

QNeuronActivationFn Qrack::QNeuron::activationFn
protected

◆ alpha

real1_f Qrack::QNeuron::alpha
protected

◆ angles

std::unique_ptr<real1[]> Qrack::QNeuron::angles
protected

◆ inputIndices

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

◆ inputPower

bitCapIntOcl Qrack::QNeuron::inputPower
protected

◆ outputIndex

bitLenInt Qrack::QNeuron::outputIndex
protected

◆ qReg

QInterfacePtr Qrack::QNeuron::qReg
protected

◆ tolerance

real1_f Qrack::QNeuron::tolerance
protected

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