text
stringlengths
301
426
source
stringclasses
3 values
__index_level_0__
int64
0
404k
Quantum Computing. …+ ω^((L — 1)s) |L — 1⟩) The inverse QFT is obtained by just replacing ts with -st in the expression above U_QFT^-1 |t⟩ = 1/√L (|0⟩ + ω^-t |1⟩ + ω^(-2t) |2⟩ + … …+ω^(-st) |s⟩ + … …+ ω^(-(L — 1)t) |L — 1⟩) If we apply the inverse QFT to the state after measuring ƒ(j) = r we have that the amplitude
medium
1,857
Quantum Computing. of the generic state of the QFT superposition becomes ω^(-st) = √o/L ( ω^(-s j_1) + … + ω^(-s (j_1 + ok)) + … + ω^(-s (j_1 + L — o)) ) = √o/L ω^(-s j_1) ( 1 + … + ω^(-sok) + … + ω^(-s(L — o)) ) Let’s guess which of these terms is going to be much larger than the other ones. Let’s say that Ω_s = 1 +
medium
1,858
Quantum Computing. … + ω^(-sok) + … + ω^(-s(L — o)) This is a sum of complex numbers that are going to interfere with each other the more constructively the more they all point in the complex plane in the general direction of the positive real axis. This means that the square of the magnitude of the complex number
medium
1,859
Quantum Computing. ω^(-st) is going to be the highest when so/L is the closest to an integer. In our example if s = 17 the number so/L is far from an integer and the complex numbers that add up to Ω_s are pointing in all kind of different directions of the complex plane which means that they will interfere
medium
1,860
Quantum Computing. destructively causing Ω_s to have a small magnitude: On the other hand if s = 85 the number so/L is very close to the integer 1 and the complex numbers adding up to Ω_s are pointing to a preferred direction in the complex plane which means that Ω_s will have a large magnitude: For s = 256 the
medium
1,861
Quantum Computing. complex number ω^s is actually -1 so all the terms adding up to Ω_s are just even powers of -1 which are all equal to 1 and Ω_s becomes L/o. — Second measurement — If we now perform a measurement of s the QFT superposition will collapse to the term with a specific value of s, say s’ = k L/o and the
medium
1,862
Quantum Computing. probability of measuring this value is P(s’) = |<s’|U_QFT^-1|j: ƒ(j) = r⟩|² = (o/L²) Ω_s² In the example with n = 21, m = 11 and l = 9 let’s assume that the observed value of ƒ(j) is r = 16. Then the chart of the probability of measuring the value s is shown below: Let’s say that the outcome of the
medium
1,863
Quantum Computing. measurement is s = 427. We know that so/L must be very close to an integer K. So the known quantity s/L must be very close to K/o. We can then apply a classical algorithm to find K and o. This is accomplished by writing s/L as a continued fraction s/L = a_0 + 1/(a_1 + 1/(a_2 + 1/(…))) A fraction
medium
1,864
Quantum Computing. obtained by neglecting all a’s deeper than a certain level is an increasingly close approximation of the original fraction. With s = 427 and L = 512 a_0 = 0, a_1 = 1, a_2 = 5, a_3 = 42, a_4 = 2 and all other a’s are 0. The first approximations to s/L are then 0 + 1/1 = 1 and 0 + 1/(1 + 1/5) = 5/6.
medium
1,865
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. How to find correct angle values for Parametrized Quantum U3 gates and Controlled U3 gates using Qiskit Beginner-friendly tutorial encouraging baby-steps in Quantum Computing using Qiskit Source: Wikipedia. Bloch sphere representing different basis (x, y, z), states (0, 1, 𝜓) and relevant angle
medium
1,867
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. values (𝜃 and ϕ) as visualized for a single qubit. In my previous tutorial-blog, I explained how to calculate the angle values for Rϕ gates with the help of a particular case. As promised, this one will explain how to calculate angle values for the U-gates and Controlled U3 gate. General U Gates
medium
1,868
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. General U gates are generic single-qubit rotation gates with 3 Euler angles (i.e. θ, ϕ, λ). It is called ‘general’ because any single qubit quantum gate can be represented by a U(θ, ϕ, λ) gate. General U3 gates are given by: Eq. (1) Qiskit provides U2 and U1-gates, which are specific cases of the
medium
1,869
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. U3 gate. For U2 gate- θ=π/2, and for U1 gate- θ=ϕ=0, respectively. This makes the U1-gate equivalent to the Rϕ-gate. Here we will be dealing with a general U3 gate and will calculate it’s parameters to solve a particular problem. Objective 1: Create the state given below using only one U3 gate: Eq.
medium
1,870
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. (2) We know that the U3 gate is given by the matrix given in Eq. (1). Also, we can write the value of |𝜓⟩ in the form of a column vector: Eq. (3) Just to visualize what a U3 gate looks like, let’s build a demo circuit: Since this is a single qubit gate, the circuit has only one qubit whose initial
medium
1,871
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. value is |0⟩. This means, this U3 gate applied on state |0⟩ of our qubit should lead to the column matrix of Eq. (3). Equating individual elements, we get: Eq. (4) Using the value of θ in next equation: We can write this as: Eq. (5) Since, in this case, both the terms having λ were multiplied by 0,
medium
1,872
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. the value of λ can be anything. It doesn’t have any impact on the final state. Implementing the circuit with calculated θ and 𝜙 values: Executing and visualizing the circuit to find out the final state: The statevector shows two complex values where the value is 0.5 for |0⟩ (with 0 imaginary part)
medium
1,873
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. and 0.8660j for |1⟩ (with negligible real part). This gives us the state we aimed for in our objective. Finding the probability of measuring the states: Probability of finding a particular output (|𝑥⟩) in a given state (|𝜓⟩) is given by: |⟨𝑥|𝜓⟩|² i.e. the square of their inner product. So, Let’s
medium
1,874
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. find the probabilities state-wise, starting with state |0⟩: We know that, ⟨0|0⟩=1 and ⟨0|1⟩=0 [a useful thing to remember is that the inner product of two orthogonal vectors is 0], so: Eq. (6) Now, calculating for state |1⟩: Eq. (7) Now, plotting the probabilities of states on a histogram using
medium
1,875
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. get_counts(): Values match with what we calculated in Eq. (6) and (7) Hence, here we saw a simple case of calculating the parameters of a U3 gate to achieve any given state. We also calculated the probabilities and checked via Qiskit programming. You can similarly try to generate different states
medium
1,876
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. based on the rules of Quantum Computing. Controlled U3 Gates: Controlled-U3 gate is a 3-parameter two-qubit gate. This is a controlled version of the U3 gate (generic single qubit rotation). It is restricted to 3 parameters (i.e. θ, ϕ, λ). It can be applied to any qubit controlled on the opposite
medium
1,877
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. qubit. A CU3 gate controlled on q0 and q1 (Source: qiskit.circuit.library.CU3Gate) Let’s try to solve a question to understand how to find the θ, ϕ and λ for our CU3 gate. Objective 2: Modify the output of a given circuit such that the system is transformed to |↻⟩⊗|1⟩ using only a single
medium
1,878
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. ControlledU3 gate, where the state |↻⟩ is: Given circuit visualization According to the question, we need to apply a CU3 gate in the given circuit to get the resultant state |𝜓⟩=|↻⟩⊗|1⟩. Let us first solve and see the desired state in a simplified way: Eq. (8) So, this is the final column we are
medium
1,879
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. expected to have after applying the CU3 gate on given circuit. Now, let’s solve the given circuit. The initial state of both qubits, q0 and q1 is |0⟩. After applying Hadamard gate on q0 we get: and applying an X gate on q1 we get: Getting the combined state of both qubits in the given circuit: Eq.
medium
1,880
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. (9) Working on the transformation: We know that, parametrized CU3 gate is given by the following matrix: Applying CU3 gate on the given circuit (Eq.(9)) and equating with desired state (Eq.(8)): Now we have two equations: Solving the first equation for 1, we get 𝜃=0 or 𝜃=2𝜋. In that case, solving
medium
1,881
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. second equation: Using Euler’s formula, we can write it as: Since we have only imaginary part on the RHS, LHS has to match up. So, (𝜙+𝜆) has to be a value that gives 0 for cos and 1 for sin. i.e. (𝜙+𝜆)=3𝜋/2 (because cos(3𝜋/2)=0 and sin(3𝜋/2)=1) This gives us several possibilities for both 𝜙 and 𝜆:
medium
1,882
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. Case 1: 𝜙=3𝜋/2 and 𝜆=0 Case 2: 𝜙=0 and 𝜆=3𝜋/2 Case 3: 𝜙=𝜋 and 𝜆=𝜋/2 Case 4: 𝜙=𝜋/2 and 𝜆=𝜋 All these cases give the correct answer and can be tried as an exercise. We will see the circuit for Case 1 here: Plotting the statevector on the bloch sphere: The statevector values give us the desired state:
medium
1,883
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. 0.707 |0⟩ and -0.707j for |1⟩ which was our desired state (Eq. 8). Now let’s visualize the final circuit on the q-sphere: Like the previous tutorial, this one is also done using Qiskit version 0.21.0. So, here we end our little tour about dealing with the parametrized general U3 gates and
medium
1,884
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. controlled U3 gates. I tried to explain both gates with particular cases, both of which I came across in the #QiskitIndia Challenge. Solving these was fun, I hope you enjoyed and learned too. If this tutorial helped you, please leave a clap. In case of any doubts, feel free to comment, I’ll try my
medium
1,885
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. best to answer. Thanks for reading through! P.S. The notebook having both of these exercises can be found here and can be viewed here. (It has solutions for all the cases discussed in the tutorial). References: Abraham Asfaw, Luciano Bello, Yael Ben-Haim, Sergey Bravyi, Nicholas Bronn, Lauren
medium
1,886
Quantum Computing, Qiskit, General U3 Gate, Controlled U3 Gate, Tutorial. Capelluto, Almudena Carrera Vazquez, Jack Ceroni, Richard Chen, Albert Frisch, Jay Gambetta, Shelly Garion, Leron Gil, Salvador De La Puente Gonzalez, Francis Harkins, Takashi Imamichi, David McKay, Antonio Mezzacapo, Zlatko Minev, Ramis Movassagh, Giacomo Nannicni, Paul Nation, Anna Phan, Marco
medium
1,887
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. Machine Learning We Don’t Need To Worry About Overfitting Anymore Photo by Mohamed Nohassi on Unsplash Motivated by prior work connecting the geometry of the loss landscape and generalization, we introduce a novel, effective procedure for instead simulta- neously minimizing loss value and loss
medium
1,889
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. sharpness. In particular, our procedure, Sharpness-Aware Minimization (SAM), seeks parameters that lie in neighbor- hoods having uniformly low loss; this formulation results in a min-max optimiza- tion problem on which gradient descent can be performed efficiently. We present empirical results
medium
1,890
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. showing that SAM improves model generalization across a variety of benchmark datasets[1] Source: Sharpness Awareness Minimization Paper [1] In Deep Learning we use optimization algorithms such as SGD/Adam to achieve convergence in our model, which leads to finding the global minima, i.e a point
medium
1,891
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. where the loss of the training dataset is low. But several kinds of research such as Zhang et al have shown, many networks can easily memorize the training data and have the capacity to readily overfit, To prevent this problem and add more generalization, Researchers at Google have published a new
medium
1,892
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. paper called Sharpness Awareness Minimization which provides State of the Art results on CIFAR10 and other datasets. In this article, we will look at why SAM can achieve better generalization and how we can implement SAM in Pytorch. Why SAM works!? In Gradient descent or any other optimization
medium
1,893
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. algorithm, our goal is to find a parameter that has a low loss value But SAM achieves better generalization than any other normal optimization method by focusing on seeking parameters that lie in neighborhoods having uniformly low loss value (rather than parameters that only themselves have low
medium
1,894
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. loss value) Since computing neighborhood parameters in addition to computing a single parameter, the loss landscape is flatter comparing to other optimization methods, which in turn increases generalization of the model. (Left)) A sharp minimum to which a ResNet trained with SGD converged. (Right)
medium
1,895
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. A wide minimum to which the same ResNet trained with SAM converged.Image Source: SAM Paper[1] Note: SAM is not a new optimizer, It is used with any other common optimizers such as SGD/Adam Implementing SAM in Pytorch: Implementing SAM in Pytorch is very simple and straightforward Code was taken
medium
1,896
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. from the Unofficial Pytorch Implementation[2] Code explanation, At first, we inherit from the optimizer class from Pytorch to create an optimizer, though SAM is not a new optimizer but to update gradients(with the help of base optimizer) at each step we need to inherit that class The class accepts
medium
1,897
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. the model parameters, a base optimizer and a rho, which is the size of the neighborhood for computing the maximum loss Before moving on to the next steps let’s have a look at the pseudocode mentioned in the paper which will help us to understand the above code without math. Image Source: SAM
medium
1,898
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. Paper[1] As we see in the pseudocode after computing the first backward pass, we compute the epsilon and add it to the parameters, those steps are implemented in the method first_step on the above python code Now after computing the first step we have to get back to the previous weight for
medium
1,899
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. computing the actual step of a base optimizer, these steps are implemented in the function second_step The function _grad_norm is used to return the norm of the matrix vectors, which is said in the 10th line of the pseudocode After constructing this class you can simply use this for your deep
medium
1,900
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. learning projects by following the below snippet in the training function. Code was taken from the Unofficial Pytorch Implementation[2] Finishing Thoughts: Though SAM achieves better generalization, the main con of this method is, it takes twice the time for training since it computes forward and
medium
1,901
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. backward passes two times to compute the sharpness awareness gradient. Other than that SAM has also proved its effect on the recently published NFNETS, which is a current State of the Art for ImageNet, In the future, we can expect more and more papers utilizing this technique to achieve better
medium
1,902
Deep Learning, Artificial Intelligence, Computer Science, Machine Learning, Pytorch. generalization. If you’ve enjoyed this article or have any questions, please feel free to connect me on LinkedIn References: [1] Sharpness-Aware Minimization for Efficiently Improving Generalization [2] Unofficial Implementation of SAM by Ryuichiro Hataya
medium
1,903
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. In an era dominated by digital currencies and volatile market fluctuations, the quest for stability has never been more paramount. Enter Edelcoin, a pioneering cryptocurrency that seamlessly merges the unwavering stability of metals with the boundless potential of the digital age. This article
medium
1,904
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. delves deep into the essence of Edelcoin, exploring how it leverages the power of metals to offer a stable and promising digital asset. The Digital Age: A Landscape of Opportunities and Challenges The 21st century has been marked by rapid technological advancements, with the digital revolution at
medium
1,905
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. its forefront. Cryptocurrencies, once a niche concept, have now become mainstream, offering an alternative to traditional financial systems. However, with this surge in popularity comes volatility. The prices of most cryptocurrencies are known to swing wildly, influenced by market sentiment,
medium
1,906
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. regulatory news, and technological developments. In such a landscape, the need for a stable digital asset becomes evident. While several stablecoins have emerged, pegged to traditional currencies or assets, Edelcoin stands out with its unique proposition. Edelcoin: A Confluence of Metal Stability
medium
1,907
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. and Digital Innovation At the heart of Edelcoin lies a basket of precious and rare metals. These aren’t just any metals; they are metals that play pivotal roles in various industries, from medicine to aerospace. By backing its value with these metals, Edelcoin offers a stability that’s rare in the
medium
1,908
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. digital currency world. 1. Copper Isotopes: Copper isotopes, especially Copper-63 and Copper-65, have carved a niche for themselves in the fields of medicine and biochemistry. Their role as tracers in chemical and physical experiments is unparalleled. Moreover, they are integral to the production
medium
1,909
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. of radiopharmaceuticals and are indispensable for diagnostic procedures in nuclear medicine. The intricate supply chain, marked by complex extraction and purification processes, underscores their value. 2. Nickel Wire (NP1, NP2): The high-purity NP1 and NP2 grades of nickel wire are in high demand
medium
1,910
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. in the electronics, aerospace, and energy sectors. Their high melting point, resistance to oxidation and corrosion, and exceptional thermal and electrical properties make them invaluable. However, the supply of this metal is not without challenges, primarily due to geopolitical risks associated
medium
1,911
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. with mining. 3. Caesium 133: Perhaps the most intriguing of the lot, Caesium 133 is primarily used in atomic clocks, the gold standard of time and frequency. Its applications also extend to telecommunication and global navigation satellite systems. The rarity of Caesium 133, being one of the
medium
1,912
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. scarcest elements on Earth, adds to its allure. Why Metals? The Rationale Behind Edelcoin’s Stability Metals, especially the ones backing Edelcoin, have intrinsic value. Their applications in various industries ensure a consistent demand. Unlike digital assets, whose value can be influenced by
medium
1,913
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. market sentiment, metals have tangible uses that provide them with inherent stability. Furthermore, the supply challenges associated with these metals — be it the complex extraction processes for copper isotopes or the geopolitical risks for nickel wire — ensure that their value remains robust. By
medium
1,914
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. pegging its value to such metals, Edelcoin offers a stability that’s both rare and valuable in the digital currency landscape. Navigating the Future with Edelcoin As industries continue to evolve, the demand for these metals is set to rise. Whether it’s advancements in medicine requiring more
medium
1,915
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. copper isotopes or the growth of the aerospace industry driving the demand for nickel wire, the future looks promising for these metals. And as their demand grows, so does the stability and value of Edelcoin. Moreover, in a world where digital transactions are becoming the norm, having a stable
medium
1,916
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. digital asset like Edelcoin becomes invaluable. Whether it’s for international trade, investment, or daily transactions, Edelcoin offers a reliability that’s hard to match. Conclusion In the confluence of the stability of metals and the innovations of the digital age, Edelcoin emerges as a beacon
medium
1,917
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. of promise. It’s not just another cryptocurrency; it’s a digital asset backed by tangible value. As we navigate the complexities of the 21st century, Edelcoin stands as a testament to what’s possible when the old-world stability of metals meets the new-age digital revolution. Follow us on social
medium
1,918
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. media for more updates. Disclaimer: Edelcoin AG is a company being incorporated according to Swiss law with a legal seat in Egnach, Thurgau, Switzerland. This article and its content are provided for information purposes, and to contribute to the debate around stablecoins, only. It is not intended
medium
1,919
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. as a recommendation or an offer or a solicitation for the purchase or sale of any type of financial instrument or cryptocurrency/crypto token. The opinions expressed in this article do not constitute investment advice. Any such offer would be made only after a prospective participant had completed
medium
1,920
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. its independent investigation of the instruments or transactions and received all information required to make its investment decision. Edelcoin AG cannot and does not guarantee the accuracy, adequacy, completeness, or validity of the information and materials contained in these pages. In no event
medium
1,921
Edelcoin, Stable Coin, Payments, Stablecoin Cryptocurrency, Cryptocurrency. shall Edelcoin AG be liable for any use by any party of, for any decision made or action taken by any party in reliance upon, or for any inaccuracies or errors in, or omissions from, the information contained herein. Edelcoin AG does not undertake any obligation to update such information or
medium
1,922
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. Data Structures — Queue Queue is a data structure that follows the First-In-First-Out (FIFO) principle. This means that the first item added to the queue will be the first item to leave the queue. In this article, I present how to use this data structure in .NET. To illustrate how a queue works,
medium
1,924
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. think about a line of people waiting for a service, where the first person to join the line is the first person to be served. In similar way, when working with queues, the elements are added at the rear (enqueue) and removed from the front (dequeue) of the queue. For demonstration purposes, I
medium
1,925
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. created a console application using .NET. The complete code can be found on my GitHub. The Queue data structure provides a series of methods that you can use to work with it. These are the main methods: Enqueue: this adds elements to the rear/back of the stack. Dequeue: this removes and returns the
medium
1,926
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. element at the front of the queue. Peek: this returns the element at the front of the queue (without removing it). Count: this returns the number of elements in the queue. Contains: this returns whether an element is in the queue. In the image below you can see what happens when the Enqueue and
medium
1,927
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. Dequeue operations are executed: The element 1 was at the front of the queue, and when the Dequeue operation was executed, the element 1 was removed from the queue. The last element on this queue is element 6, and when the Enqueue operation is executed, the element 7 will be added to the end of the
medium
1,928
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. queue. Creating a Queue To create a Stack in C#, you can declare it by using the generic class Queue<T>, where T is the type of elements that will be stored in the queue. For example, below I’m creating a Queue of string elements: Queue<string> queueDemo = new Queue<string>(); // or var queueDemo =
medium
1,929
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. new Queue<string>(); Adding elements to the Queue In the code below I’m adding three elements to the queueDemo: queueDemo.Enqueue("Julie"); queueDemo.Enqueue("Ana"); queueDemo.Enqueue("Bob"); For each Enqueue operation, the element will be added at the back of the queue: When printing the values of
medium
1,930
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. this stack, this is the output: Julie Ana Bob Removing the first element from the Queue The Dequeue operation can be used to remove the first element from the queue. For example: queueDemo.Dequeue(); When executing the Dequeue operation, the first element that was added to the queue (“Julie”) will
medium
1,931
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. be removed: When printing the elements of the queue after executing the Dequeue method, this is the output: Ana Bob Getting the first element from the Queue To retrieve the first element from the Queue, you can use the Peek method: var firstElement = queueDemo.Peek(); Now when printing the
medium
1,932
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. firstElement, this is the output: Ana Contains operation To check if an element exists in the Queue, you can use the Contains method, and pass as a parameter the value that you want to search: var containsBob = queueDemo.Contains("Bob"); var containsSofia = queueDemo.Contains("Sofia"); When
medium
1,933
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. printing containsBob and containsSofia, this is the output: Queue contains Bob: True Queue contains Sofia: False Retrieving the number of elements in a Queue To get the amount of elements that exist in a Queue, or to check if the Queue is empty or not, you can use the Count method: var
medium
1,934
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. numberOfElements = stackDemo.Count; When printing the amountOfElements, the output is: numberOfElements: 2 Useful cases for using a Queue Some common scenarios where the Queue data structure is useful are: Task or Job Scheduling: Queues can be used to schedule and process tasks or jobs in a
medium
1,935
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. first-in-first-out (FIFO) manner, ensuring fair and ordered execution, for example, printing queues, where documents are added to the queue and printed in the order they were received. Breadth-First Search (BFS): queues are commonly used in BFS algorithms for traversing graphs or trees level by
medium
1,936
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. level. Multithreading and Task Management: queues can be used in multithreaded applications to communicate between different threads or manage tasks in a thread pool. Call center systems: where incoming calls are added to a queue and are answered by agents in the order they were received.
medium
1,937
Dotnet, Csharp, Data Structure Algorithm, Queue, Development. Conclusion The Queue is a linear data structure that follows the FIFO (First-In-First-Out) principle, and can be useful in scenarios where the first element added to the queue must be the first one to be processed. This is the link for the project in GitHub: https://github.com/henriquesd/queuedemo
medium
1,938
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. How to Measure the Relationship Between Random Variables? Hello Reader, Hope you have enjoyed my previous article about Probability Distribution 101. In this blog post, I am going to demonstrate how can we measure the relationship between Random Variables. This topic holds lot of weight as data
medium
1,940
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. science is all about various relations and depending on that various prediction that follows. Before we start, let’s see what we are going to discuss in this blog post. Random Variables Covariance Pearson correlation coefficient (PCC) Monotonic Functions Spearman Rank Correlation Coefficient (SRCC)
medium
1,941
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. Significance Test Correlation Vs Regression Correlation Vs Causation Let’s initiate our discussion with understanding what Random Variable is in the field of statistics. Random Variables Image Source: https://www.thoughtco.com/probabilities-of-rolling-two-dice-3126559 If we Google ‘Random Variable’
medium
1,942
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. we will get almost the same definition everywhere but my focus is not just on defining the definition here but to make you understand what exactly it is with the help of relevant examples. Here to make you understand the concept I am going to take an example of “Fraud Detection” which is a very
medium
1,943
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. useful case where people can relate most of the things to real life. Let’s say you work at large Bank or any payment services like Paypal, Google Pay etc. Your task is to identify Fraudulent Transaction. For this, you identified some variables that will help to catch fraudulent transaction. Amount
medium
1,944
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. Spend IP Address Number of Failed Attempts Location Time since the last transaction There could be more variables in this list but for us, this is sufficient to understand the concept of random variables. Once a transaction completes we will have value for these variables (As shown below) Since we
medium
1,945
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. are considering those variables having an impact on the transaction status whether it's a fraudulent or genuine transaction. The value for these variables cannot be determined before any transaction; However, the range or sets of value it can take is predetermined. Amount Spend:- [0, Infinity] IP
medium
1,946
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. Address:- Sets of all IP Address in the world Number of Failed Attempts:- [0,1,2,3] Time since the last transaction:- [0, Infinity] Location:- [Mumbai, Delhi, Bengaluru] Note that, for each transaction variable value would be different but what that value would be is Subject to Chance. In simpler
medium
1,947
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. term, values for each transaction would be different and what values it going to take is completely random and it is only known when the transaction gets finished. Thus these variables are nothing but termed as ‘Random Variables’ In a more formal way, we can define the Random Variable as follows:-
medium
1,948
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. A random variable is any variable whose value cannot be determined beforehand meaning before the incident. Such variables are subject to chance but the values of these variables can be restricted towards certain sets of value. For example, three failed attempts will block your account for further
medium
1,949
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. transaction. A random variable is ubiquitous in nature meaning they are presents everywhere. (Below few examples) The temperature in a day, Length of the tweet Profit per day Sales per day etc. Random variables are also known as Stochastic variables in the field statistics. There are 3 types of
medium
1,950
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. random variables Discrete:- Discrete Random Variable can take only integer value. In the above example, ‘No of failed attempts’ is a discrete random variable. Continuous:- Continuous Random Variable can take any value from a range of values. In the above example, ‘Amount Spend’ is a continuous
medium
1,951
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. random variable. Categorical:- Categorical Random Variable can take one of the limited fixed set of values. In the above example, ‘Location’ is a categorical random variable. I hope the above explanation was enough to understand the concept of Random variables. Now we will understand How to measure
medium
1,952
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. the relationship between random variables? Let’s consider the following example, You have collected data of the students about their weight and height as follows: (Heights and weights are not collected independently. In the below table, one row represents the height and weight of the same person)
medium
1,953
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. Random Variable X & Y Here, X: Height of the students Y: Weight of the students Is there any relationship between height and weight of the students? If we investigate closely we will see one of the following relationships could exist When X increases, Y also increases. When X increases, Y
medium
1,954
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. decreases. Such relationships need to be quantified in order to use it in statistical analysis. So the question arises, How do we quantify such relationships? There are 3 ways to quantify such relationship Co-variance, Pearsons Correlation Coefficient (PCC), Spearman Rank Correlation Coefficient
medium
1,955
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. (SRCC). We will be discussing the above concepts in greater details in this post. Let's start with Covariance. Covariance Covariance is pretty much similar to variance. Let’s shed some light on the variance before we start learning about the Covariance. Variance generally tells us how far data has
medium
1,956
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. been spread from it’s mean. Since mean is considered as a representative number of a dataset we generally like to know how far all other points spread out (Distance) from its mean. So basically it's average of squared distances from its mean. There are two types of variance:- Population variance
medium
1,957
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. and sample variance. Below table gives the formulation of both of its types. Source: https://www.onlinemathlearning.com/variance.html I hope the concept of variance is clear here. It was necessary to add it as it serves the base for the covariance. Covariance is a measure of how much two random
medium
1,958
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. variables vary together. It’s similar to variance, but where variance tells you how a single variable varies, co variance tells you how two variables vary together. Formulation of Covariance As we have stated covariance is much similar to the concept called variance. Thus formulation of both can be
medium
1,959
Statistics, Machine Learning, Data Science, Artificial Intelligence, Deep Learning. close to each other. Variance of X The covariance of X, Y If you closely look at the formulation of variance and covariance formulae they are very similar to each other. Basically we can say its measure of a linear relationship between two random variables. Based on the direction we can say there
medium
1,960