pub struct QuantumScoreDiffusion { /* private fields */ }
Expand description
Quantum Score-Based Diffusion
Implementations§
Source§impl QuantumScoreDiffusion
impl QuantumScoreDiffusion
Sourcepub fn new(
data_dim: usize,
num_qubits: usize,
num_noise_levels: usize,
) -> Result<Self>
pub fn new( data_dim: usize, num_qubits: usize, num_noise_levels: usize, ) -> Result<Self>
Create new score-based diffusion model
Examples found in repository?
examples/quantum_diffusion.rs (lines 170-174)
168fn score_diffusion_demo() -> Result<()> {
169 // Create score-based model
170 let model = QuantumScoreDiffusion::new(
171 2, // data dimension
172 4, // num qubits
173 10, // noise levels
174 )?;
175
176 println!(" Created quantum score-based diffusion model");
177 println!(" - Noise levels: {:?}", model.noise_levels());
178
179 // Test score estimation
180 let x = Array1::from_vec(vec![0.5, -0.3]);
181 let noise_level = 0.1;
182
183 let score = model.estimate_score(&x, noise_level)?;
184 println!("\n Score estimation:");
185 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
186 println!(" - Noise level: {:.3}", noise_level);
187 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
188
189 // Langevin sampling
190 println!("\n Langevin sampling:");
191 let init = Array1::from_vec(vec![2.0, 2.0]);
192 let num_steps = 100;
193 let step_size = 0.01;
194
195 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
196
197 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
198 println!(
199 " - After {} steps: [{:.3}, {:.3}]",
200 num_steps, sample[0], sample[1]
201 );
202 println!(
203 " - Distance moved: {:.3}",
204 ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
205 );
206
207 Ok(())
208}
Sourcepub fn estimate_score(
&self,
x: &Array1<f64>,
noise_level: f64,
) -> Result<Array1<f64>>
pub fn estimate_score( &self, x: &Array1<f64>, noise_level: f64, ) -> Result<Array1<f64>>
Estimate score (gradient of log density)
Examples found in repository?
examples/quantum_diffusion.rs (line 183)
168fn score_diffusion_demo() -> Result<()> {
169 // Create score-based model
170 let model = QuantumScoreDiffusion::new(
171 2, // data dimension
172 4, // num qubits
173 10, // noise levels
174 )?;
175
176 println!(" Created quantum score-based diffusion model");
177 println!(" - Noise levels: {:?}", model.noise_levels());
178
179 // Test score estimation
180 let x = Array1::from_vec(vec![0.5, -0.3]);
181 let noise_level = 0.1;
182
183 let score = model.estimate_score(&x, noise_level)?;
184 println!("\n Score estimation:");
185 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
186 println!(" - Noise level: {:.3}", noise_level);
187 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
188
189 // Langevin sampling
190 println!("\n Langevin sampling:");
191 let init = Array1::from_vec(vec![2.0, 2.0]);
192 let num_steps = 100;
193 let step_size = 0.01;
194
195 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
196
197 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
198 println!(
199 " - After {} steps: [{:.3}, {:.3}]",
200 num_steps, sample[0], sample[1]
201 );
202 println!(
203 " - Distance moved: {:.3}",
204 ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
205 );
206
207 Ok(())
208}
Sourcepub fn langevin_sample(
&self,
init: Array1<f64>,
noise_level: f64,
num_steps: usize,
step_size: f64,
) -> Result<Array1<f64>>
pub fn langevin_sample( &self, init: Array1<f64>, noise_level: f64, num_steps: usize, step_size: f64, ) -> Result<Array1<f64>>
Langevin dynamics sampling
Examples found in repository?
examples/quantum_diffusion.rs (line 195)
168fn score_diffusion_demo() -> Result<()> {
169 // Create score-based model
170 let model = QuantumScoreDiffusion::new(
171 2, // data dimension
172 4, // num qubits
173 10, // noise levels
174 )?;
175
176 println!(" Created quantum score-based diffusion model");
177 println!(" - Noise levels: {:?}", model.noise_levels());
178
179 // Test score estimation
180 let x = Array1::from_vec(vec![0.5, -0.3]);
181 let noise_level = 0.1;
182
183 let score = model.estimate_score(&x, noise_level)?;
184 println!("\n Score estimation:");
185 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
186 println!(" - Noise level: {:.3}", noise_level);
187 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
188
189 // Langevin sampling
190 println!("\n Langevin sampling:");
191 let init = Array1::from_vec(vec![2.0, 2.0]);
192 let num_steps = 100;
193 let step_size = 0.01;
194
195 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
196
197 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
198 println!(
199 " - After {} steps: [{:.3}, {:.3}]",
200 num_steps, sample[0], sample[1]
201 );
202 println!(
203 " - Distance moved: {:.3}",
204 ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
205 );
206
207 Ok(())
208}
Sourcepub fn noise_levels(&self) -> &Array1<f64>
pub fn noise_levels(&self) -> &Array1<f64>
Get noise levels
Examples found in repository?
examples/quantum_diffusion.rs (line 177)
168fn score_diffusion_demo() -> Result<()> {
169 // Create score-based model
170 let model = QuantumScoreDiffusion::new(
171 2, // data dimension
172 4, // num qubits
173 10, // noise levels
174 )?;
175
176 println!(" Created quantum score-based diffusion model");
177 println!(" - Noise levels: {:?}", model.noise_levels());
178
179 // Test score estimation
180 let x = Array1::from_vec(vec![0.5, -0.3]);
181 let noise_level = 0.1;
182
183 let score = model.estimate_score(&x, noise_level)?;
184 println!("\n Score estimation:");
185 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
186 println!(" - Noise level: {:.3}", noise_level);
187 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
188
189 // Langevin sampling
190 println!("\n Langevin sampling:");
191 let init = Array1::from_vec(vec![2.0, 2.0]);
192 let num_steps = 100;
193 let step_size = 0.01;
194
195 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
196
197 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
198 println!(
199 " - After {} steps: [{:.3}, {:.3}]",
200 num_steps, sample[0], sample[1]
201 );
202 println!(
203 " - Distance moved: {:.3}",
204 ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
205 );
206
207 Ok(())
208}
Auto Trait Implementations§
impl Freeze for QuantumScoreDiffusion
impl RefUnwindSafe for QuantumScoreDiffusion
impl Send for QuantumScoreDiffusion
impl Sync for QuantumScoreDiffusion
impl Unpin for QuantumScoreDiffusion
impl UnwindSafe for QuantumScoreDiffusion
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> 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.