-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
31 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package density | ||
|
||
import "github.com/itsubaki/q/quantum/qubit" | ||
|
||
// State is a quantum state. | ||
type State struct { | ||
Probability float64 | ||
Qubit *qubit.Qubit | ||
} | ||
|
||
// Normalize normalizes the probabilities of an ensemble. | ||
func Normalize(ensemble []State) []State { | ||
var sum float64 | ||
for _, s := range ensemble { | ||
sum += s.Probability | ||
} | ||
|
||
for i := range ensemble { | ||
ensemble[i].Probability = ensemble[i].Probability / sum | ||
} | ||
|
||
return ensemble | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package density_test |