<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Davide Tezza on Medium]]></title>
        <description><![CDATA[Stories by Davide Tezza on Medium]]></description>
        <link>https://medium.com/@d.tezza?source=rss-ab779223b6ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uHYM2fwTpfMXv_C_rGlVFw.jpeg</url>
            <title>Stories by Davide Tezza on Medium</title>
            <link>https://medium.com/@d.tezza?source=rss-ab779223b6ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:58:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@d.tezza/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introduction to Quantum Kernels and application]]></title>
            <link>https://medium.com/data-reply-it-datatech/introduction-to-quantum-kernels-and-application-482f36ae1afe?source=rss-ab779223b6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/482f36ae1afe</guid>
            <category><![CDATA[quantum]]></category>
            <category><![CDATA[kernel-trick]]></category>
            <category><![CDATA[quantum-circuits]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[quantum-machine-learning]]></category>
            <dc:creator><![CDATA[Davide Tezza]]></dc:creator>
            <pubDate>Wed, 05 Jul 2023 08:00:57 GMT</pubDate>
            <atom:updated>2023-07-05T08:00:57.040Z</atom:updated>
            <content:encoded><![CDATA[<h3>Theoretical definitions and results</h3><p>The quantum technologies are theoretically able to speed up a huge amount of classical algorithms. In fact, there are different cases, referring to theoretical problems, in which a quantum hardware has been able to solve a problem in a time way faster than the most powerful classic hardware, see [2] for a fascinating example. This is the reason behind the general charm of the quantum application field. In case one wants to deepen the fundamental concepts that are used in this article, we want to direct the reader to the fantastic article at the following <a href="https://medium.com/data-reply-it-datatech/quantum-computing-a-moderately-mathematical-introduction-78af4e907022">link</a>. The hardness of designing a learning procedure in a quantum implementation is not only based on the nowadays hardware limitations but also on one intrinsic property of the quantum physics.</p><blockquote><strong>Postulate 1: </strong>The evolution of a closed quantum system can be described by a unitary transformation. That is, the relation between the state |ψ⟩ of the system at time t1 and the state |ψ′⟩ of the system at time t2 can be represented by a unitary operator U which depends only on the times t1 and t2</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*GGG8cfAdYqHpGrB04pA7NQ.png" /></figure><blockquote>where UU† = I, with U† as the transpose conjugate of U, and |ψ⟩ is a quantum state.</blockquote><p>This is one of the fundamental postulates of the quantum mechanics. It simply resembles the fact that the evolution of our quantum information (quantum state or qubit in our scenario) can only be represented through linear operations. This highlights the impossibility to use a traditional activation function, which is non linear, in order to start a deep learning procedure directly on quantum data. We operate according to the framework of a quantum computer and this requires to embed our data into a large Hilbert space in which perform our operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*wEJywatoMufzt8hCxhvE-w.png" /><figcaption>Figure 1: Encoding of classical data into quantum states.</figcaption></figure><p>This process resembles the construction of a feature map that assigns quantum states to our data. This embedding links the quantum approach to the classical one through the use of kernels. In classical kernel methods we access to the feature space through kernels or inner products of feature vectors. In a quantum setting we access to the Hilbert space of quantum states (a reformulation of the feature space) through measurements which can also be expressed by inner products of quantum states. The power of this kernel based approach is that we do not need any explicit form, knowing every element, of the final feature space, which in general is too large. This allows us to retrieve the information behind the data in a scenario which in general is simpler, for example consider the separability of data (with linear models) between spaces with different dimensions, particularly useful in classifications task. The efficiency which can be obtained in this way refers to the fact that the number of operations performed on the system grows at most polynomially with the system size. Let us introduce the formal concept of quantum kernel.</p><blockquote><strong>Definition 1(Quantum Kernel)<br></strong>Let ϕ be a feature map over the input Ω, encoding our data into quantum information. A <strong>quantum kernel</strong> is a kernel given by the inner product (in Dirac notation), defined on our space of quantum states, between two quantum states:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*z0Cdq3sFQmXjMgcGwfb8qg.png" /></figure><p>This definition highlights that we can compute inner products of vectors in much higher dimensional spaces by computing a kernel function, which is computationally a lot easier.</p><p>The kernels have to be chosen accurately. In fact by switching between kernels we switch between different models in a training procedure. This is also known as kernel trick. In particular the kernel trick corresponds to changing the data encoding. This means that every solution has to be designed for a specific task. Furthermore we have that every kernel defines a different vector space which is linked with the space of the encoded data, the reproducing kernel Hilbert space (<strong>RKHS</strong>).<br>The encoding schemes can be very different and there are a large amount of them in literature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UFE3WznAMZWMUSIQqSNHqw.png" /><figcaption>Figure 2: Quantum kernels of different data embeddings. Figure by [4].</figcaption></figure><p>In Figure 2, we see four different very well known encoding schemes able to transform our classic data into quantum information.</p><p>At this point we are ready to see how we can perform a learning procedure using quantum kernels. We have that in machine learning, independently from the learning task, we have to find out the best model describing our data of interest. The training process is also seen as the regularised empirical risk minimization problem.<br>It can be formulated as described in [4].</p><blockquote><strong>Definition 2(Minimization of regularized empirical risk)</strong><br>Let X ,Y be respectively data input and output domains. Let p be a probability distribution on X for data selection. Let L : X×Y ×<strong>R</strong> → [0,∞) be a loss function computing the quality of the prediction of a quantum model f(x). Consider the expected loss of f under L, i.e.,</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*smD8MOqE8wyQeGGc3ibO8g.png" /></figure><blockquote>Since p is not known, we have to rely on the empirical formulation. We have that the <strong>regularized empirical risk</strong>, on a sample of size M, is:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*UdpSEQyYZsdC-b_KPyxMSQ.png" /></figure><p>In particular we want to highlight that optimizing the empirical risk of convex loss functions, over functions in an RKHS (the space defined by the chosen kernel), is a finite-dimensional convex optimization problem [4]. Optimizing over large spaces reveals to be easy when we use training data. Since the feature spaces in which we assign the labels to the data are usually very high-dimensional (such as for example the feature space of the embedding), and possibly even infinite-dimensional, the fact that this optimization is finitedimensional is not trivial at all. Moreover the fact that optimization is convex reveals that there is only one global minimum. We recall the general result that convex optimization problems can be greedly solved in <em>O(M²)</em> in the number of training data <em>M</em>, making the optimization tractable even for large datasets. This result not only enables the training procedure for quantum kernel but also reveals as this procedure can be seen as a finite-dimensional problem!<br>Let give a simple example.</p><blockquote><strong>Example 1</strong><br>A special case of kernel-based training is support vector machine which uses a special convex loss function:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*TDgwTo2lfkG27P6SroBq-w.png" /></figure><blockquote>with y ∈ {0, 1}. This function is called hinge loss. Training a quantum kernel k and a support vector machine with hinge loss is equivalent to finding the quantum model that minimizes the hinge loss.</blockquote><h3>Application</h3><p>We now propose a little application of quantum kernel training procedure in order to have a better idea on how it works. We could use different framework for our purpose, such for example <em>qiskit</em>, the package for quantum implementations developed by IBM and <em>pennylane</em>, developed by Xanadu. We refer to the last one.<br>We want to identify a procedure able to fully solve a classification or regression problem with classical or quantum labels, the last coming from a generic embedding. This procedure naturally has to adapt to every kind of datasets. We will highlight how the choice of the data is restricted to not too large datasets since the needed computation effort grows in a non linear way. Let us consider a binary classification task. We use the dataset <em>glass</em>, available on <a href="https://www.openml.org/search?type=data&amp;status=active&amp;id=41&amp;sort=runs">openml.org</a>, whose id is 41. These data refer to a classification task between different types of glasses. This study was originally motivated by criminologist investigation. In fact, if we identify correctly the glass then it can be used as evidence in a crime scene. The dataset contains 214 instances, divided into 6 classes. This reduced dimension ensures us the possibility to perform lots of different quantum based procedures on common used hardware. <br>In order to have a more complete view of the possible choices one can make to train quantum data, we rely on <strong>QuASK </strong>[1], a useful python script able to help in searching the best encoding scheme for our data.<br>We start simply loading our data.</p><pre>Labels have type int64 thus this is a classification problem<br>The dataset has 6 labels being [0, 1, 2, 4, 5, 6] as it follows:<br>Counter({1: 76, 0: 70, 6: 29, 2: 17, 4: 13, 5: 9})<br>  Class 0 is present 70 times (32.71 %)<br>  Class 2 is present 17 times (7.94 %)<br>  Class 5 is present 9 times (4.21 %)<br>  Class 1 is present 76 times (35.51 %)<br>  Class 6 is present 29 times (13.55 %)<br>  Class 4 is present 13 times (6.07 %)<br>Do you want to pick just the first two classes? [y/N]: &gt;? y<br>Do you want to undersample the largest class? [y/N]: &gt;? y<br>Do you want to oversample the smallest class? [y/N]: &gt;? y<br>Do you want to apply preprocessing to the features? [y/N]: &gt;? y<br>Your data are numerical. Do you want to apply PCA? [y/N]: &gt;? y<br>How many components you want?: &gt;? 2<br>Do you want to scale each field from 0 to 1 (MinMaxScaler)? [y/N]: y<br>Which percentage of data must be in the test set?: 0.3</pre><p>As we can see from the console output, we reduce ourself to a binary classification problem selecting only two classes. In order to have a more balanced dataset we undersample the largest class and oversample the smallest one. Moreover we also apply a pre-processing scheme based on a two components <em>PCA</em>. Furthermore, we also rescale our data through <em>minmaxscaler </em>tool [3].<br>At this point, QuASK gives to the user the possibility to choose between the usage of a<em> fixed kernel</em>, which is basically a fixed procedure, and a <em>trainable kernel</em>. We perform our considerations using a trainable kernel. At first we have to choose a way to embed our data. Between the several possible choices the script proposes, we go for the following scheme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*tMzvIaTBRP31mUW3MKRGog.png" /><figcaption>Figure 3: Longitudinal and Transverse Field Ising Model (LTFIM). The gates resemble the notation of the Pauli rotation matrices and we can see three different angle parameters for the steps of the circuit.</figcaption></figure><p>This encoding, preceded by the application of the Y Pauli matrix on all the wires of the circuit, is able to have a precise effect on our data. In particular, using this encoding scheme repeated 4 times and relying on <em>adam </em>as our solver, we are able to get the full classification of our data. We have reached this conclusion after several tests with different encoding schemes. The training procedure is based on fit our data into the encoding procedure and maximizing a chosen metric (kernel target alignment, model complexity, accuracy ecc…). We want to highlight as the choice of the encoding scheme is crucial in this procedure. In fact we have that the classification results change a lot, based on the type of encoding chosen and the number of times this pattern is repeated in order to have the final embedding. This resembles the general hardness in performing a quantum training procedure. Also in this way the used tool is able to help in finding out the best encoding scheme.</p><h3>Conclusion</h3><p>We have seen how we can rely on kernels in order to perform a learning procedure on quantum data. In a particular way, we have highlighted the importance of the encoding scheme used to transform our data into quantum information. In general we have that this kernel approach is very useful since it can be applied in the nowadays technologies. Moreover, when we deal with real problems, we face a huge amount of data and kernels allow us to access only to the quantum information we are interested in, without the knowledge of the entire high dimensional space.</p><h3>References</h3><p>[1] Francesco Di Marcantonio et al. “Quantum Advantage Seeker with Kernels (QuASK): a software framework to speed up the research in quantum machine learning”. In: Quantum Machine Intelligence 5.1 (May 2023), p. 20. issn: 2524–4914. doi: <a href="https://link.springer.com/article/10.1007/s42484-023-00107-2">10.1007/s42484–023–00107–2</a>. url: <a href="https://link.springer.com/article/10.1007/s42484-023-00107-2">https://doi.org/10.1007/s42484–023–00107–2</a>.</p><p>[2] Lars S. Madsen et al. “Quantum computational advantage with a programmable photonic processor”. In: Nature 606.7912 (June 2022), pp. 75–81. issn: 1476–4687. doi: <a href="https://www.nature.com/articles/s41586-022-04725-x">10.1038/s41586–022–04725-x</a>. url: <a href="https://www.nature.com/articles/s41586-022-04725-x">https://doi.org/10.1038/s41586–022–04725-x</a>.</p><p>[3] F. Pedregosa et al. “Scikit-learn: Machine Learning in Python”. In: Journal of Machine Learning Research 12 (2011), pp. 2825–2830.</p><p>[4] Maria Schuld. Supervised quantum machine learning models are kernel methods. 2021. arXiv: <a href="https://arxiv.org/abs/2101.11020">2101.11020 [quant-ph]</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=482f36ae1afe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-reply-it-datatech/introduction-to-quantum-kernels-and-application-482f36ae1afe">Introduction to Quantum Kernels and application</a> was originally published in <a href="https://medium.com/data-reply-it-datatech">Data Reply IT | DataTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>