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 178-182)
176fn score_diffusion_demo() -> Result<()> {
177 // Create score-based model
178 let model = QuantumScoreDiffusion::new(
179 2, // data dimension
180 4, // num qubits
181 10, // noise levels
182 )?;
183
184 println!(" Created quantum score-based diffusion model");
185 println!(" - Noise levels: {:?}", model.noise_levels());
186
187 // Test score estimation
188 let x = Array1::from_vec(vec![0.5, -0.3]);
189 let noise_level = 0.1;
190
191 let score = model.estimate_score(&x, noise_level)?;
192 println!("\n Score estimation:");
193 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
194 println!(" - Noise level: {noise_level:.3}");
195 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
196
197 // Langevin sampling
198 println!("\n Langevin sampling:");
199 let init = Array1::from_vec(vec![2.0, 2.0]);
200 let num_steps = 100;
201 let step_size = 0.01;
202
203 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
204
205 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
206 println!(
207 " - After {} steps: [{:.3}, {:.3}]",
208 num_steps, sample[0], sample[1]
209 );
210 println!(
211 " - Distance moved: {:.3}",
212 (sample[0] - init[0]).hypot(sample[1] - init[1])
213 );
214
215 Ok(())
216}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 191)
176fn score_diffusion_demo() -> Result<()> {
177 // Create score-based model
178 let model = QuantumScoreDiffusion::new(
179 2, // data dimension
180 4, // num qubits
181 10, // noise levels
182 )?;
183
184 println!(" Created quantum score-based diffusion model");
185 println!(" - Noise levels: {:?}", model.noise_levels());
186
187 // Test score estimation
188 let x = Array1::from_vec(vec![0.5, -0.3]);
189 let noise_level = 0.1;
190
191 let score = model.estimate_score(&x, noise_level)?;
192 println!("\n Score estimation:");
193 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
194 println!(" - Noise level: {noise_level:.3}");
195 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
196
197 // Langevin sampling
198 println!("\n Langevin sampling:");
199 let init = Array1::from_vec(vec![2.0, 2.0]);
200 let num_steps = 100;
201 let step_size = 0.01;
202
203 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
204
205 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
206 println!(
207 " - After {} steps: [{:.3}, {:.3}]",
208 num_steps, sample[0], sample[1]
209 );
210 println!(
211 " - Distance moved: {:.3}",
212 (sample[0] - init[0]).hypot(sample[1] - init[1])
213 );
214
215 Ok(())
216}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 203)
176fn score_diffusion_demo() -> Result<()> {
177 // Create score-based model
178 let model = QuantumScoreDiffusion::new(
179 2, // data dimension
180 4, // num qubits
181 10, // noise levels
182 )?;
183
184 println!(" Created quantum score-based diffusion model");
185 println!(" - Noise levels: {:?}", model.noise_levels());
186
187 // Test score estimation
188 let x = Array1::from_vec(vec![0.5, -0.3]);
189 let noise_level = 0.1;
190
191 let score = model.estimate_score(&x, noise_level)?;
192 println!("\n Score estimation:");
193 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
194 println!(" - Noise level: {noise_level:.3}");
195 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
196
197 // Langevin sampling
198 println!("\n Langevin sampling:");
199 let init = Array1::from_vec(vec![2.0, 2.0]);
200 let num_steps = 100;
201 let step_size = 0.01;
202
203 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
204
205 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
206 println!(
207 " - After {} steps: [{:.3}, {:.3}]",
208 num_steps, sample[0], sample[1]
209 );
210 println!(
211 " - Distance moved: {:.3}",
212 (sample[0] - init[0]).hypot(sample[1] - init[1])
213 );
214
215 Ok(())
216}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 185)
176fn score_diffusion_demo() -> Result<()> {
177 // Create score-based model
178 let model = QuantumScoreDiffusion::new(
179 2, // data dimension
180 4, // num qubits
181 10, // noise levels
182 )?;
183
184 println!(" Created quantum score-based diffusion model");
185 println!(" - Noise levels: {:?}", model.noise_levels());
186
187 // Test score estimation
188 let x = Array1::from_vec(vec![0.5, -0.3]);
189 let noise_level = 0.1;
190
191 let score = model.estimate_score(&x, noise_level)?;
192 println!("\n Score estimation:");
193 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
194 println!(" - Noise level: {noise_level:.3}");
195 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
196
197 // Langevin sampling
198 println!("\n Langevin sampling:");
199 let init = Array1::from_vec(vec![2.0, 2.0]);
200 let num_steps = 100;
201 let step_size = 0.01;
202
203 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
204
205 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
206 println!(
207 " - After {} steps: [{:.3}, {:.3}]",
208 num_steps, sample[0], sample[1]
209 );
210 println!(
211 " - Distance moved: {:.3}",
212 (sample[0] - init[0]).hypot(sample[1] - init[1])
213 );
214
215 Ok(())
216}Auto Trait Implementations§
impl Freeze for QuantumScoreDiffusion
impl RefUnwindSafe for QuantumScoreDiffusion
impl Send for QuantumScoreDiffusion
impl Sync for QuantumScoreDiffusion
impl Unpin for QuantumScoreDiffusion
impl UnsafeUnpin 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.