HiggsDetector

Struct HiggsDetector 

Source
pub struct HiggsDetector { /* private fields */ }
Expand description

Specialized detector for Higgs bosons in collision data

Implementations§

Source§

impl HiggsDetector

Source

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}
Source

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}
Source

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

Source§

fn clone(&self) -> HiggsDetector

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HiggsDetector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V