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 169-173)
167fn score_diffusion_demo() -> Result<()> {
168 // Create score-based model
169 let model = QuantumScoreDiffusion::new(
170 2, // data dimension
171 4, // num qubits
172 10, // noise levels
173 )?;
174
175 println!(" Created quantum score-based diffusion model");
176 println!(" - Noise levels: {:?}", model.noise_levels());
177
178 // Test score estimation
179 let x = Array1::from_vec(vec![0.5, -0.3]);
180 let noise_level = 0.1;
181
182 let score = model.estimate_score(&x, noise_level)?;
183 println!("\n Score estimation:");
184 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
185 println!(" - Noise level: {:.3}", noise_level);
186 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
187
188 // Langevin sampling
189 println!("\n Langevin sampling:");
190 let init = Array1::from_vec(vec![2.0, 2.0]);
191 let num_steps = 100;
192 let step_size = 0.01;
193
194 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
195
196 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
197 println!(
198 " - After {} steps: [{:.3}, {:.3}]",
199 num_steps, sample[0], sample[1]
200 );
201 println!(
202 " - Distance moved: {:.3}",
203 ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
204 );
205
206 Ok(())
207}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 182)
167fn score_diffusion_demo() -> Result<()> {
168 // Create score-based model
169 let model = QuantumScoreDiffusion::new(
170 2, // data dimension
171 4, // num qubits
172 10, // noise levels
173 )?;
174
175 println!(" Created quantum score-based diffusion model");
176 println!(" - Noise levels: {:?}", model.noise_levels());
177
178 // Test score estimation
179 let x = Array1::from_vec(vec![0.5, -0.3]);
180 let noise_level = 0.1;
181
182 let score = model.estimate_score(&x, noise_level)?;
183 println!("\n Score estimation:");
184 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
185 println!(" - Noise level: {:.3}", noise_level);
186 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
187
188 // Langevin sampling
189 println!("\n Langevin sampling:");
190 let init = Array1::from_vec(vec![2.0, 2.0]);
191 let num_steps = 100;
192 let step_size = 0.01;
193
194 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
195
196 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
197 println!(
198 " - After {} steps: [{:.3}, {:.3}]",
199 num_steps, sample[0], sample[1]
200 );
201 println!(
202 " - Distance moved: {:.3}",
203 ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
204 );
205
206 Ok(())
207}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 194)
167fn score_diffusion_demo() -> Result<()> {
168 // Create score-based model
169 let model = QuantumScoreDiffusion::new(
170 2, // data dimension
171 4, // num qubits
172 10, // noise levels
173 )?;
174
175 println!(" Created quantum score-based diffusion model");
176 println!(" - Noise levels: {:?}", model.noise_levels());
177
178 // Test score estimation
179 let x = Array1::from_vec(vec![0.5, -0.3]);
180 let noise_level = 0.1;
181
182 let score = model.estimate_score(&x, noise_level)?;
183 println!("\n Score estimation:");
184 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
185 println!(" - Noise level: {:.3}", noise_level);
186 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
187
188 // Langevin sampling
189 println!("\n Langevin sampling:");
190 let init = Array1::from_vec(vec![2.0, 2.0]);
191 let num_steps = 100;
192 let step_size = 0.01;
193
194 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
195
196 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
197 println!(
198 " - After {} steps: [{:.3}, {:.3}]",
199 num_steps, sample[0], sample[1]
200 );
201 println!(
202 " - Distance moved: {:.3}",
203 ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
204 );
205
206 Ok(())
207}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 176)
167fn score_diffusion_demo() -> Result<()> {
168 // Create score-based model
169 let model = QuantumScoreDiffusion::new(
170 2, // data dimension
171 4, // num qubits
172 10, // noise levels
173 )?;
174
175 println!(" Created quantum score-based diffusion model");
176 println!(" - Noise levels: {:?}", model.noise_levels());
177
178 // Test score estimation
179 let x = Array1::from_vec(vec![0.5, -0.3]);
180 let noise_level = 0.1;
181
182 let score = model.estimate_score(&x, noise_level)?;
183 println!("\n Score estimation:");
184 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
185 println!(" - Noise level: {:.3}", noise_level);
186 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
187
188 // Langevin sampling
189 println!("\n Langevin sampling:");
190 let init = Array1::from_vec(vec![2.0, 2.0]);
191 let num_steps = 100;
192 let step_size = 0.01;
193
194 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
195
196 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
197 println!(
198 " - After {} steps: [{:.3}, {:.3}]",
199 num_steps, sample[0], sample[1]
200 );
201 println!(
202 " - Distance moved: {:.3}",
203 ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
204 );
205
206 Ok(())
207}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.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.