Results
Restricted boltzmann machine via bayesian machine learning. We first discribe the restricted Boltzmann machine (RBM) model and the methodology to train it by utilizing bayesian framework [33]. The RBM model is a twolayer, bipartite neural network, which is a ”restricted version” of the Boltzmann machine with only interconnections between hidden layers and visible layers. The visible layer encodes the input data into a dimensional binary string, and the hidden layer is composed of
stochastic binary variables. Then the joint probability of
is expressed as , where the potential function . The Boltzmann weights compose a symmetry matrix, and the formalized factor .Given the training data , the Boltzmann weights can be estimated by utilizing the maximum a posterior (MAP) within the bayesian learning framework [29]:
(1) 
The probability is the priori distribution of the Boltzmann weights, and
is the likelyhood probability distribution, which can be computed as
on the RBM model.Meanwhile, in some application scenarios, the predictive distribution of the new data point prevails over the Boltzmann parameter itself, and we can directly express the predictive distribution by sum of with the weight parameter :
(2) 
In general, the distribution
can not be analytically computed, therefore researchers often utilize Markov Chain Monte Carlo (MCMC) method to estimate this distribution. Nevertheless, if the machine learning tasks process the data on a high dimensional feature space
, estimating the posterior distribution and predictive distribution will take a large amount of computational overheads which is extremely hard for classical computing. We therefore choose the quantum state space as the feature space, and we design a quantum bayesian framework to handle this issue.Encoding phase of bayesian learning framework. The quantum bayesian framework contains two fundamental components, namely the encoding phase and the training phase. The first stage of encoding phase indicates the procedure that maps the real data onto the quantum feature space which is special designed for quantum bayesian learning.
In quantum settings, the feature map is an injective encoding of classical information into a quantum state on an qubits register, s.t. . The family of feature map circuit can be defined as , where the unitary operator
(3) 
The notation indicates a subset that belongs to set , and are nonlinear functions of the input data [34], and other choices of the feature maps are also possible such as squeezed vacuum state [28]. For the supervised classification tasks, the training data is stored into two parts , namely data parts and label parts. Then the feature state is defined as:
(4) 
where the operator encodes the label parts into the last qubits, and the binary string indicates the . For instance, if handling the binary classification task, the label is marked by when , otherwise .
On the other hand, the predictive data , which does not have its label, is encoded by the quantum feature map:
(5) 
Still taking the binary classification into consideration, the feature state of predictive data becomes . Fig.1 illustrates the quantum circuits of these two quantum feature maps respectively.
The second subroutine aims at encoding the parameter into a density matrix , whose structure satisfies connection rules between the visible nodes and hidden nodes. To achieve this, we propose a parallel hardwareefficient ansatz to represent the priori density matrix of the RBM model (see Methods).
Training phase of quantum bayesian framework. We then discuss the training phase of our framework. First, we deliver a quantum algorithm for maximum the posterior distribution, and this quantum algorithm is designed according to the measure of a physical quantity. We find the overlap between the priori density matrix and likelyhood density matrix can be recognized as a principle to evaluate the posterior distribution in quantum settings, furthermore this physical quantity can be efficiently computed by quantum computer but hard for classical computer [35], and this measure reveals the quantum advantages.
The validity for choosing this measure as well as the method for computing the likelyhood density matrix are presented in Methods.
Specifically, the quantum maximum posterior distribution (QMAP) algorithm can be regarded as a procedure that adjusts the parameter to achieve
(6) 
The QMAP algorithm starts with estimating the measure, s.t. , by swap test technique [30]. Utilizing this information, QMAP algorithm is followed by simultaneous perturbation stochastic approximation (SPSA) approach [31] to find out the optimal parameter . For every step of the optimization, we sample from
symmetrical Bernoulli distributions
using preassigned elements from a sequence converging to zero, s.t., . The gradient at is approximated using energy evaluations at , and is constructed as(7) 
Noting that this gradient approximation only requires two estimations of the energy, regardless of the number of variables in . The value of can be obtained by swap test technique, then the parameters are updated as
(8) 
The step length is selected based on experience, and the optimal solution convergences rapidly after several iterations in this iterative algorithm. So far, the QMAP algorithm obtains the optimal parameter which can be used to classify the predictive data.
The classification rules of QMAP algorithm are interpreted as follows. After determining the optimal solution , the likelyhood distribution of a test data point can be computed by the QCL subroutine (see Methods), where the training feature state should be substituted by the testing feature state . Then we utilize computational basis to measure the last registers of . Taking binary classification as an example, we select basis to measure the third register. If the probability , then is assigned to the class , otherwise .
The QMAP algorithm involves swap test technique as well as the QCL subroutine proposed in Methods, which actually takes gate complexity. The parameter is the number of utilized qubits or the scale of the quantum system, indicates the error taken by swap test, represents the number of data points in the data set, and is the iterative times of SPSA approach. Given the real data set and the corresponding feature space , then the QMAP algorithm achieves the exponential speedup under the assumption of .
Then we discuss another inference method in our framework. The quantum predictive distribution estimator (QPDE) can directly construct a predictive distribution rather than deliver the Boltamann weight, and this result naturally corresponds to a quantum state which represents such distribution. Given a predictive visible data (without label), the QPDE aims at obtaining the corresponding predictive distribution
(9) 
where is the likelyhood distribution of the predicted data that has been introduced above. We indicate the fact that traversing all the possible state can be achieved by modifying the rotation parameter accompanied by an appropriate error in Theorem 2 (see Methods). Generally, the predictive distribution can not be calculated analytically, unless priori and likelyhood distribution belong to the same conjugate distribution family. Furthermore, the likelyhood density matrix , in which visible data has been mapped on the quantum feature space, is computationally hard by classical means because of the construction of the feature map and overleap . Thus we also believe that function (9) may not be estimated directly by Markov chain Monte Carlo (MCMC) method efficiently [34].
Combining MCMC method and quantum technique, the QPDE provides a method to estimate function (9). We first select and prepare a sampling distribution which satisfies the condition , and there are some possible choices of
such as uniform distribution, multivariate Gaussian distribution and multivariate Laplasian distribution. Then the function (
9) can be rewritten as(10) 
This is followed by obtaining a set of samples (where ) drawn independently from the distribution , which allows the function (9) to be approximated by a finite sum
(11) 
where
(12) 
Noting that QPDE does not directly achieve , but it just measures the last qubits and then performs simple calculations on the measurement results. We still deliver a binary classification as an illustrative example. In detail, parameters can be calculated by the swap test, then one can measure the last qubit of by computational basis , where the probability can be estimated by simply counting the measurement results. Finally is assigned to the class if , otherwise class is assigned.
Noting that QPDE also needs the supportive of QCL subroutine, meanwhile sampling from the distribution takes additive complexity of times. Therefore, QPDE takes time, where is the number of data points in real dataset, represents the error taken by swap test.
Experimental results. The experimental preparation of the QMAP algorithm is illustrated as follows. We utilize hidden node and visible nodes to construct a QRBM to implement a binary classification task. At first, we encode the classical training data onto the quantum qubits and by utilizing the quantum feature map , which is illustrated in Fig.6. Then we invoke the QCL subroutine to add the hidden node onto the RBM model and computing the likelyhood distribution at the same time. Finally, QMAP algorithm can find out the optimal parameter with the help of SPSA algorithm and swap test technique, and the evolution of quantum posterior distribution is illustrated as Fig.4(c). The optimal parameter can be further examined by the testing data set. We set the iterative parameter , afterwards the test results are illustrated as Fig.2. Our quantum algorithm yields success for the test data set. The original data distribution and the decision boundary of the QMAP algorithm are illustrated as Fig.4(a) and (b).
For the experiments of QPDE, the preparation stage is to obtain a set of samples from a uniform distribution and the function (9) can be evaluated as
(13) 
where the parameter , , and . We first implement the quantum variational classifier with sampling times, respectively, on the quantum simulation processor. We expect the classification success rate goes up with increasing the number of samplings. We utilize training sets consisting of data points per label. And we take 40 testing data points for each class. Two of the testing data and ’s wavefunction are shown in Fig.5 for different number of samplings. And the classification success is also illustrated in Fig.3(a). We observe that the upper bound of the accuracy converges to albeit with more optimization steps. The number of layer depth of priori distribution is set to , and sampling interval is .
Second, we implement the quantum variational circuit for different layer depth from to on the quantum simulation processor. We observe that the classification accuracy shows a slight rise from to with layer depth varying from to , and maintains a constant regardless of increasing the layer depth. The sampling interval is set to and the number of sampling times is .
Finally, we also implement the experiments on varying the sampling interval from to when executing to different sampling times on the layer depth quantum circuit. It is interesting to note that larger number of sampling times with larger interval actually yield higher success rate up to .
According to the experiments results, compared with QPDE, the QMAP algorithm has a larger complexity, but achieves higher success rate up to . Therefore, we in practice have to face a tradeoff between complexity and success rate before choosing a more suitable one between the two algorithms.
Discussion
In summary, we implement a quantum bayesian learning framework in the exponentially large feature spaces. Our framework provides two variational quantum algorithms, which build upon the realization that the posterior and predictive distributions are hard to estimate classically in the quantumstate feature spaces. Both of them can handle the classical dataset and output the classical predictive label, and it is shown that our algorithms are able to be exponentially faster than the classical counterparts. We hope our work can inspire more bayesian machine learning algorithms accessible to NISQ devices. .
Methods
Parallel hardwareefficient ansatz. In this section, we present a quantum technique to generate the priori probability in the pattern of quantum state. To process the data in the high dimensional quantumenhanced feature space with dimension, researchers propose the hardware efficient ansatz to approximate an arbitrary quantum state with an affordable error [21]. To represent the relationship between the visible nodes and hidden nodes, we propose the parallel hardwareefficient ansatz whose fundamental quantum circuit is illustrated in Fig.7(a). If the RBM model has hidden nodes , the quantum priori quantum state can be prepared by
(14) 
in which . The shallow quantum circuit can be achieved by appending layers of singlequbit unitaries and entangling gates, and each layer contains an additional set of entanglers across all the qubits used. The operator is a circuit of repeated entanglers, and interleave them with layers comprised of local single qubit rotations: . It is interesting to note that is only confined to invoking and , of course, there are other ways to construct the rotations. The rotation angles are sampled from a classical distribution (such as uniform distribution, multivariate Gaussian distribution and multivariate Laplasian distribution), and the entangler comes from the graph model , which is uniquely determined by the structure of the RBM:
(15) 
The implementing of the parallel hardware efficient ansatz depends on the Hadamard gate and controlled unitary , i.e.,
(16) 
where . Therefore the priori probability distribution can be computed by measuring the above state on the basis , and the oblivious amplitude amplification technique [3] can realize the
polynomial acceleration in this measuring step.
Density matrix of likelyhood distribution. In the feature space, the posterior distribution of RBM can be further simplified as
(17) 
where denotes the th column vector of . Noting that is actually an overlap, or the inner product, between the vectors and [33].
Given the weight state and feature state , we attempt to estimate there overlap using quantum computer. The implementing of the following quantum algorithm depends on two two quantum techniques provided in Supplementary materials. The first technique [38], the combination of amplitude estimation [36] and swap test, promises our proposed algorithm enabling calculating that overlap and immediately encoding it into the register, and the second one interprets the procedure of linear combination of unitary.
Drawing supportive from these two techniques, we can implement the following quantum algorithm that computes likelyhood distribution in quantum settings.
Subroutine (QCL): Quantum algorithm for computing likelyhood density matrix
Input: A quantum restricted boltzmann machine composed of visible nodes and hidden nodes; qubits initialized to to encode visible nodes; qubits initialized to to encode hidden nodes; an auxiliary qubit; and training data set .
Output:Likelyhood distribution

For any training data , we first construct quantum state in the first system, and then apply Hardmard gate to the auxiliary qubit (the second system) resulting in the state of the whole system
(18) The operation is performed onto the the third system controlled by the second register, then we obtain
(19) 
According to the linear combination of unitary (LCU) technique, we have
(20) 
Considering the QRBM model with hidden nodes, for the first hidden node and corresponding weight states . Construct the controlled operator and apply it on the second and the third system, where the parameter is determined by the previous phase. The resulting state becomes
(21) 
Perform Hadamard gate on the second system, then the system turns to the following state by invoking the analogue of swap test technique (see Supplementary material), s.t.
(22) where .

Perform exponential operator onto the third system, then add ancillary qubit and utilize controlled rotation procedure, s.t. , so the state becomes
(23) after measuring ancillary qubit with . The parameter is the number of qubits to describe the overlap , and the controlled rotation therefore takes complexity of .

Uncomputing the step 3 and step 4, we have the state
(24) Then repeat the steps 35 adding the hidden nodes respectively, we finally obtain the likelyhood state of the training data under the quantum restricted boltzmann machine model.
(25) in which the probability parameter is the likelyhood probability of the data . We therefore obtain the likelyhood distribution density operator .
To save the sources of qubits, actually, one can also measure the third system and save each on the classical memory without utilizing amplitude estimation technique, and finally designs the unitary operator
(26) 
and perform it on the initial state to achieve the state of Eq.(25) when implementing the experiments. Thus the procedure does not depend on the auxiliary qubit and amplitude estimation algorithm necessarily, furthermore this schema does not submerge the quantum supremacy taken by the feature state.
On the other hand, we should also point that the number of hidden nodes is a constant which does not depend on the scale of visible data set . In fact, our experiment only sets 1 hidden nodes but manifests a descent performance.
Theorem 1: Suppose the ansatz can be generated in the way of , and there are enough layers in the quantum circuit , s.t. can generate an arbitrary state, then the physical quantity can be recognized as a measure to represent posterior distribution in quantum settings.
Proof: If we expand the physical quantity under the computational basis, then we have
(27) 
If we traverse all the possible , this physical quantity can be simplified as:
(28)  
(29) 
Therefore, the physical quantity, s.t. the overlap between likelyhood and priori density matrixes, can be recognized as a measure to represent posterior distribution in quantum settings.
Theorem 2: If the ansatz can be prepared by , then modifying the rotation parameter can actually traverse all the possible weight parameter with an affordable error.
Proof: Suppose we perform a sequence of gates intended to approximate some other sequence of gates: . Then it turns out that the error caused by the entire sequence of imperfect gates is at most the sum of the errors in the individual gates:
(30) 
Now we consider the local single qubit rotation , then the difference between and can be measured as
(31)  
(32) 
(33) 
Combining the theorem, therefore the difference between and can be measured as
(34) 
Thus the microelement , which implies the fact that modifying the rotation parameter can actually traverse all the possible weight states with an exponential small error.
References
 1. M.Nielsen and I.Chuang. Quantum computation and quantum information. Mathematical Structures in Computer Science, 21(1):159 (2002).
 2. C.H.Bennett, J.I.Cirac, M.S.Leifer, D.W.Leung, N.Linden, S.Popescu, and G.Vidal. Optimal simulation of twoqubit hamiltonians using general local operations. Physical Review A, 66(1):144144 (2001).
 3. D.W.Berry, A.M.Childs, R.Cleve, R.Kothari, and R.D.Somma. Simulating hamiltonian dynamics with a truncated taylor series. Phys. Rev. Lett, 114(9):090502 (2014).
 4. G.H.Low and I.Chuang. Optimal hamiltonian simulation by quantum signal processing. Phys. Rev. Lett., 118(1):010501 (2017).
 5. P.W.Shor. Polynomialtime algorithms for prime factorization and discrete logarithms on a quantum computer. Siam Rev., 41(2):303332 (1999).
 6. Grover and k.Lov. A fast quantum mechanical algorithm for database search. Phys. Rev. lett., 78:212219 (1996).
 7. P.Wittek and S.Lloyd. Quantum machine learning. Nature, 549(7671):195 (2017).
 8. W.A.Harrow, A.Hassidim, and S.Lloyd. Quantum algorithm for linear systems of equations. Phys. Rev. lett., 103(15):150502 (2009).
 9. Leonard Wossnig, Zhikuan Zhao, and Anupam Prakash Quantum linear system algorithm for dense matrices. Phys. Rev. lett., 120, 050502 (2018).
 10. L.C.Wan, C.H.Yu, S.J.Pan, F.Gao, Q.Y.Wen, and S.J.Qin. Asymptotic quantum algorithm for the toeplitz systems. Phys. Rev. A (2018).
 11. M.Schuld, I.Sinayskiy, and F.Petruccione. Prediction by linear regression on a quantum computer. Phys. Rev. A, 94(2) (2016).
 12. P.Rebentrost, M.Mohseni, and S.Lloyd. Quantum support vector machine for big data classification. Phys. Rev. lett., 113(13):130503 (2014).
 13. S.Lloyd, M.Mohseni, and P.Rebentrost. Quantum algorithms for supervised and unsupervised machine learning. arXiv (2013).

14.
S.Lloyd, M.Mohseni, and P.Rebentrost.
Quantum principal component analysis.
Nature Physics, 10(9):108113 (2013).  15. C.H.Yu, F.Gao, and Q.Y.Wen. Quantum algorithms for ridge regression. arXiv:1707.09524 (2017).
 16. N. Wiebe, D. Braun, and S. Lloyd. Quantum algorithm for data fitting, Phys. Rev. Lett. 109, 050505 (2012).
 17. Y. Liu and S. Zhang, Fast quantum algorithms for least squares regression and statistic leverage scores, Theor. Comput. Sci. 657, 38 (2017).
 18. P.Rebentrost and S.Lloyd. Quantum gradient descent and newton’s method for constrained polynomial optimization. arXiv (2016).
 19. B.Kulchytskyy, E.Andriyash, M.Amin, and R.Melko. Quantum boltzmann machine. Phys. Rev. X, 33(2):489493 (2016).

20.
A. Peruzzo, J. McClean, P. Shadbolt, M. Yung, X. Zhou, P. J.
Love, A. AspuruGuzik, and J. L. O Brien,
A variational eigenvalue solver on a quantum processor.
Nat. Commun.4213 (2014).  21. A. Kandala, A. Mezzacapo, K. Temme, M. Takita, M. Brink, J. M. Chow, and J. M. Gambetta, Hardwareefficient variational quantum eigensolver for small molecules and quantum magnets. Nature.549, 242 (2017).
 22. E. Farhi, J. Goldstone, and S. Gutmann, A Quantum Approximate Optimization Algorithm, arXiv:1411.4028, (2014).
 23. E. Farhi and A. W. Harrow, Quantum supremacy through the Quantum Approximate Optimization Algorithm, arXiv:1602.07674, (2016).
 24. J. S. Otterbach, R. Manenti, N. Alidoust, A. Bestwick, M. Block, B. Bloom, S. Caldwell, N. Didier, E. S. Fried, S. Hong, P. Karalekas, C. B. Osborn, A. Papageorge, E. C. Peterson, G. Prawiroatmodjo, N. Rubin, C. A. Ryan, D. Scarabelli, M. Scheer, E. A. Sete, P. Sivarajah, R. S. Smith, A. Staley, N. Tezak,W. J. Zeng, A. Hudson, B. R. Johnson, M. Reagor, M. P. da Silva, and C. Rigetti, Unsupervised machine learning on a hybrid quantum computer, arXiv:1712.05771, (2017).
 25. K. Mitarai, M. Negoro, M. Kitagawa, and K. Fujii, Quantum circuit learning, Phys. Rev. A 98, 032309 (2018).
 26. Ryan LaRose, Arkin Tikku, tude O NeelJudy, Lukasz Cincio and Patrick J. Coles Variational quantum state diagonalization, npj Quantum Information (2019).
 27. M. Schuld, K. Brsadler, R. Israel, D. Su, and B. Gupt. A quantum hardwareinduced graph kernel based on Gaussian Boson sampling. arxiv:1905.12646.
 28. M. Schuld, Quantum machine learning in feature Hilbert spaces. Phys. Rev. Lett. (2019)
 29. N. Friedman et al. Bayesian network classifiers. Machine Learning, 29(23):131163, (1997).
 30. H. Buhrman, R. Cleve, J.Watrous, and R. deWolf, Quantum fingerprinting. Phys. Rev. Lett. 87, 167902 (2001).
 31. Spall J. C. Multivariate stochastic approximation using a simultaneous perturbation gradient approximation In Proceedings of C IEEE Transactions on Automatic Control, pages 332341 (1992).
 32. Zhikuan Zhao et al. Bayesian deep learning on a quantum computer, arXiv:1806.11463, (2018).
 33. Hanchen Xiong et al. Towards sparsity and selectivity: bayesian learning of restricted Boltzmann machine for early visual features ICNN, (2014).
 34. Havlicek, Vojtech, et al. Supervised learning with quantumenhanced feature spaces. Nature: 567.7747 (2019): 209212.
 35. Goldberg L. A., Guo H. The complexity of approximating complexvalued Ising and Tutte partition functions Computational Complexity., 26(4): 765833, (2017).
 36. G.Brassard, P.Hoyer, M.Mosca, and A.Tapp. Quantum amplitude amplification and estimation. Quantum Computation and Information, 5494:5374 (2012).
 37. Huawei HiQ team, ’Huawei HiQ: A Highperformance quantum computing simulator and programming framework’, http://hiq.huaweicloud.com.

38.
S.S.Zhou, T.Loke, J.A.Izaac, and J. B. Wang.
Quantum fourier transform in computational basis.
Quantum Information Processing, 16(3):82 (2017).  39. Yusen Wu et al. Quantum conditional random field. arXiv:1901.01027, (2019).
Acknowledgments
This work is supported by NSFC (Grant Nos. 61672110, 61671082, 61976024, 61972048), and the Fundamental Research Funds for the Central Universities (Grant No.2019XDA01). We thank Bailing Zhang, Shijie Pan and Binbin Cai on discussing the writing thoughts, and we also acknowledge using of the HiQ for this work.
Author contributions
Y.W. contributed to the initiation of the idea. All authors wrote and reviewed the manuscript.