CategoricalDistribution function
Warning
This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.
Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.
Namespace: Microsoft.Quantum.Random
Package: Microsoft.Quantum.QSharp.Foundation
Returns a discrete categorical distribution, in which the probability for each of a finite list of given outcomes is explicitly specified.
function CategoricalDistribution (probs : Double[]) : Microsoft.Quantum.Random.DiscreteDistribution
Input
probs : Double[]
The probabilities for each outcome from the categorical distribution. These probabilities may not be normalized, but must all be non-negative.
Output : DiscreteDistribution
The index i
with probability probs[i] / sum
, where sum
is the sum
of probs
given by Fold(PlusD, 0.0, probs)
.
Example
The following Q# code will display 0 with probability 30% and 1 with probability 70%:
let dist = CategoricalDistribution([0.3, 0.7]);
Message($"Got sample: {dist::Sample()}");
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for