pub struct HiggsDetector { /* private fields */ }Expand description
Specialized detector for Higgs bosons in collision data
Implementations§
Source§impl HiggsDetector
impl HiggsDetector
Sourcepub fn new(num_qubits: usize) -> Result<Self>
pub fn new(num_qubits: usize) -> Result<Self>
Creates a new Higgs detector
Examples found in repository?
examples/hep_classification.rs (line 93)
16fn main() -> Result<()> {
17 println!("Quantum High-Energy Physics Classification Example");
18 println!("=================================================");
19
20 // Create a quantum classifier for high-energy physics data
21 let num_qubits = 8;
22 let feature_dim = 8;
23 let num_classes = 2;
24
25 println!("Creating HEP quantum classifier with {num_qubits} qubits...");
26 let mut classifier = HEPQuantumClassifier::new(
27 num_qubits,
28 feature_dim,
29 num_classes,
30 quantrs2_ml::hep::HEPEncodingMethod::HybridEncoding,
31 vec!["background".to_string(), "higgs".to_string()],
32 )?;
33
34 // Generate synthetic training data
35 println!("Generating synthetic training data...");
36 let (training_particles, training_labels) = generate_synthetic_data(500);
37
38 println!("Training quantum classifier...");
39 let start = Instant::now();
40 let metrics = classifier.train_on_particles(
41 &training_particles,
42 &training_labels,
43 20, // epochs
44 0.05, // learning rate
45 )?;
46
47 println!("Training completed in {:.2?}", start.elapsed());
48 println!("Final loss: {:.4}", metrics.final_loss);
49
50 // Generate test data
51 println!("Generating test data...");
52 let (test_particles, test_labels) = generate_synthetic_data(100);
53
54 // Evaluate classifier
55 println!("Evaluating classifier...");
56 // Convert test data to ndarray format
57 let num_samples = test_particles.len();
58 let mut test_features = Array2::zeros((num_samples, classifier.feature_dimension));
59 let mut test_labels_array = Array1::zeros(num_samples);
60
61 for (i, particle) in test_particles.iter().enumerate() {
62 let features = classifier.extract_features(particle)?;
63 for j in 0..features.len() {
64 test_features[[i, j]] = features[j];
65 }
66 test_labels_array[i] = test_labels[i] as f64;
67 }
68
69 let evaluation = classifier.evaluate(&test_features, &test_labels_array)?;
70
71 println!("Evaluation results:");
72 println!(" Overall accuracy: {:.2}%", evaluation.accuracy * 100.0);
73
74 println!("Class accuracies:");
75 for (i, &acc) in evaluation.class_accuracies.iter().enumerate() {
76 println!(" {}: {:.2}%", evaluation.class_labels[i], acc * 100.0);
77 }
78
79 // Create a test collision event
80 println!("\nClassifying a test collision event...");
81 let event = create_test_collision_event();
82
83 // Run classification
84 let classifications = classifier.classify_event(&event)?;
85
86 println!("Event classification results:");
87 for (i, (class, confidence)) in classifications.iter().enumerate() {
88 println!(" Particle {i}: {class} (confidence: {confidence:.2})");
89 }
90
91 // Create a Higgs detector
92 println!("\nCreating Higgs detector...");
93 let higgs_detector = quantrs2_ml::hep::HiggsDetector::new(num_qubits)?;
94
95 // Detect Higgs
96 let higgs_detections = higgs_detector.detect_higgs(&event)?;
97
98 println!("Higgs detection results:");
99 let higgs_count = higgs_detections.iter().filter(|&&x| x).count();
100 println!(" Found {higgs_count} potential Higgs particles");
101
102 Ok(())
103}Sourcepub fn detect_higgs(&self, event: &CollisionEvent) -> Result<Vec<bool>>
pub fn detect_higgs(&self, event: &CollisionEvent) -> Result<Vec<bool>>
Detects Higgs bosons in a collision event
Examples found in repository?
examples/hep_classification.rs (line 96)
16fn main() -> Result<()> {
17 println!("Quantum High-Energy Physics Classification Example");
18 println!("=================================================");
19
20 // Create a quantum classifier for high-energy physics data
21 let num_qubits = 8;
22 let feature_dim = 8;
23 let num_classes = 2;
24
25 println!("Creating HEP quantum classifier with {num_qubits} qubits...");
26 let mut classifier = HEPQuantumClassifier::new(
27 num_qubits,
28 feature_dim,
29 num_classes,
30 quantrs2_ml::hep::HEPEncodingMethod::HybridEncoding,
31 vec!["background".to_string(), "higgs".to_string()],
32 )?;
33
34 // Generate synthetic training data
35 println!("Generating synthetic training data...");
36 let (training_particles, training_labels) = generate_synthetic_data(500);
37
38 println!("Training quantum classifier...");
39 let start = Instant::now();
40 let metrics = classifier.train_on_particles(
41 &training_particles,
42 &training_labels,
43 20, // epochs
44 0.05, // learning rate
45 )?;
46
47 println!("Training completed in {:.2?}", start.elapsed());
48 println!("Final loss: {:.4}", metrics.final_loss);
49
50 // Generate test data
51 println!("Generating test data...");
52 let (test_particles, test_labels) = generate_synthetic_data(100);
53
54 // Evaluate classifier
55 println!("Evaluating classifier...");
56 // Convert test data to ndarray format
57 let num_samples = test_particles.len();
58 let mut test_features = Array2::zeros((num_samples, classifier.feature_dimension));
59 let mut test_labels_array = Array1::zeros(num_samples);
60
61 for (i, particle) in test_particles.iter().enumerate() {
62 let features = classifier.extract_features(particle)?;
63 for j in 0..features.len() {
64 test_features[[i, j]] = features[j];
65 }
66 test_labels_array[i] = test_labels[i] as f64;
67 }
68
69 let evaluation = classifier.evaluate(&test_features, &test_labels_array)?;
70
71 println!("Evaluation results:");
72 println!(" Overall accuracy: {:.2}%", evaluation.accuracy * 100.0);
73
74 println!("Class accuracies:");
75 for (i, &acc) in evaluation.class_accuracies.iter().enumerate() {
76 println!(" {}: {:.2}%", evaluation.class_labels[i], acc * 100.0);
77 }
78
79 // Create a test collision event
80 println!("\nClassifying a test collision event...");
81 let event = create_test_collision_event();
82
83 // Run classification
84 let classifications = classifier.classify_event(&event)?;
85
86 println!("Event classification results:");
87 for (i, (class, confidence)) in classifications.iter().enumerate() {
88 println!(" Particle {i}: {class} (confidence: {confidence:.2})");
89 }
90
91 // Create a Higgs detector
92 println!("\nCreating Higgs detector...");
93 let higgs_detector = quantrs2_ml::hep::HiggsDetector::new(num_qubits)?;
94
95 // Detect Higgs
96 let higgs_detections = higgs_detector.detect_higgs(&event)?;
97
98 println!("Higgs detection results:");
99 let higgs_count = higgs_detections.iter().filter(|&&x| x).count();
100 println!(" Found {higgs_count} potential Higgs particles");
101
102 Ok(())
103}Sourcepub fn score_particle(&self, particle: &ParticleFeatures) -> Result<f64>
pub fn score_particle(&self, particle: &ParticleFeatures) -> Result<f64>
Computes a score for a particle (higher = more likely to be a Higgs)
Trait Implementations§
Source§impl Clone for HiggsDetector
impl Clone for HiggsDetector
Source§fn clone(&self) -> HiggsDetector
fn clone(&self) -> HiggsDetector
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HiggsDetector
impl RefUnwindSafe for HiggsDetector
impl Send for HiggsDetector
impl Sync for HiggsDetector
impl Unpin for HiggsDetector
impl UnwindSafe for HiggsDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.