pub struct MultiWavelengthGradientDescent {
pub iterations: usize,
pub initialization_iterations: usize,
pub amplitude_step: f64,
pub opd_step: f64,
pub max_backtracks: usize,
pub epsilon: f64,
}Expand description
Fits one shared nondispersive OPD and a positive amplitude for each wavelength.
Every forward evaluation uses O_c = A_c exp(i 2π d / λ_c), with vacuum
wavelengths in metres. All fixed channel kernels and sparse intensity mixtures
come from the compiled spectral model. The objective is the frame-weighted
mean of valid-pixel (sqrt(prediction + epsilon) - sqrt(max(measurement, 0) + epsilon))²,
including known detector gain/background. Analytic adjoints differentiate the
objective into amplitudes and the real shared OPD; there is no independent
channel phase update. A full-data backtracking step projects amplitudes to
at least sqrt(epsilon) and OPD to its explicit half-open interval.
The phase coordinate for descent is q = 2π d / min(λ). Both real gradients
are multiplied by the common-grid pixel count before applying their separate
step multipliers. Backtracking halves one common multiplier until the full
objective is non-increasing. Failure to find such a step stops cleanly and is
reported by runtime.stopped_early; this nonconvex solver cannot guarantee
recovery of a branch missed by initialization.
Automatic initialization reconstructs independent fields with spectral AP, then uses referenced synthetic-wavelength unwrapping. Every initial OPD pixel must be valid. An explicit OPD/amplitude start can bypass that initializer. A reference region is fixed pixelwise at its known OPD throughout optimization; explicit piston offsets instead fix the initial spatial mean OPD. Absolute reference, nondispersive OPD, registered grids, and matched effective resolution remain assumptions. Pupils, source powers, geometry, gain, and background are fixed.
§Example
use fpm_rs::{Result, algorithms::{MultiWavelengthGradientDescent, MultiWavelengthSolverResult},
measurements::MeasurementRead, reconstruction::{PhaseReference,
SpectralReconstructionProblem, SyntheticWavelengthUnwrapper}};
fn solve<M: MeasurementRead>(problem: &SpectralReconstructionProblem<M>,
reference: &PhaseReference) -> Result<MultiWavelengthSolverResult> {
let unwrapper = SyntheticWavelengthUnwrapper::new((-1e-6, 2e-6))?;
MultiWavelengthGradientDescent::default().run(problem, &unwrapper, reference)
}§References
L. Bian, J. Suo, G. Zheng, K. Guo, F. Chen, and Q. Dai,
“Fourier ptychographic reconstruction using Wirtinger flow optimization”,
Optics Express 23(4), 4856–4866 (2015), for FPM loss-gradient optimization.
The shared-OPD chain rule, smoothed amplitude loss, box/gauge projections, and
monotone full-data backtracking are implementation extensions, not that paper’s solver.
See SyntheticWavelengthUnwrapper for the initialization method and reference.
Fields§
§iterations: usizePositive maximum number of accepted full-data joint updates.
initialization_iterations: usizePositive number of spectral AP passes when automatic initialization is used.
amplitude_step: f64Finite positive multiplier for the pixel-count-scaled real amplitude gradient.
opd_step: f64Finite positive multiplier for the pixel-count-scaled phase-coordinate gradient.
max_backtracks: usizePositive maximum number of step trials per update, halving the common multiplier.
epsilon: f64Finite positive intensity smoothing and squared minimum amplitude.
Implementations§
Source§impl MultiWavelengthGradientDescent
impl MultiWavelengthGradientDescent
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Checks positive iteration/trial counts, step multipliers, and numerical smoothing.
initialization_iterations is checked only by the automatic run path.
Sourcepub fn run<M: MeasurementRead>(
&self,
problem: &SpectralReconstructionProblem<M>,
unwrapper: &SyntheticWavelengthUnwrapper,
reference: &PhaseReference,
) -> Result<MultiWavelengthSolverResult>
pub fn run<M: MeasurementRead>( &self, problem: &SpectralReconstructionProblem<M>, unwrapper: &SyntheticWavelengthUnwrapper, reference: &PhaseReference, ) -> Result<MultiWavelengthSolverResult>
Reconstructs independent fields, unwraps their phases, then jointly refines OPD/amplitudes.
Requires independent model storage and at least two wavelengths. Rejects
any invalid phase-unwrapped initialization pixel; use run_from_opd for
an externally supplied finite branch when phase fusion cannot initialize it.
The result retains the pre-fit unwrapping diagnostics and independent AP trace.
Sourcepub fn run_with_options<M: MeasurementRead>(
&self,
problem: &SpectralReconstructionProblem<M>,
unwrapper: &SyntheticWavelengthUnwrapper,
reference: &PhaseReference,
options: &SpectralCheckpointOptions,
) -> Result<MultiWavelengthSolverResult>
pub fn run_with_options<M: MeasurementRead>( &self, problem: &SpectralReconstructionProblem<M>, unwrapper: &SyntheticWavelengthUnwrapper, reference: &PhaseReference, options: &SpectralCheckpointOptions, ) -> Result<MultiWavelengthSolverResult>
Runs automatic AP/phase initialization with optional accepted-update checkpoint files. The final checkpoint retains initialization records and never repeats them on resume.
Sourcepub fn run_from_opd<M: MeasurementRead>(
&self,
problem: &SpectralReconstructionProblem<M>,
opd_range_m: (f64, f64),
reference: &PhaseReference,
opd_m: Array2<f64>,
amplitudes: Vec<Array2<f64>>,
) -> Result<MultiWavelengthSolverResult>
pub fn run_from_opd<M: MeasurementRead>( &self, problem: &SpectralReconstructionProblem<M>, opd_range_m: (f64, f64), reference: &PhaseReference, opd_m: Array2<f64>, amplitudes: Vec<Array2<f64>>, ) -> Result<MultiWavelengthSolverResult>
Jointly refines owned finite C-contiguous OPD and channel amplitudes on the common grid.
OPD is in metres and must be inside opd_range_m = [lower, upper).
Amplitudes must be finite and nonnegative, one array per channel, and are
floored at sqrt(epsilon). This bypasses phase unwrapping, so the interval
may exceed a synthetic period; the caller supplies the correct fringe branch.
A region reference fixes selected pixels to its known in-range OPD. Offsets
must contain one finite piston per channel, and retain the initial OPD mean;
no phase is subtracted from the already unwrapped explicit start.
Sourcepub fn run_from_opd_with_options<M: MeasurementRead>(
&self,
problem: &SpectralReconstructionProblem<M>,
opd_range_m: (f64, f64),
reference: &PhaseReference,
opd_m: Array2<f64>,
amplitudes: Vec<Array2<f64>>,
options: &SpectralCheckpointOptions,
) -> Result<MultiWavelengthSolverResult>
pub fn run_from_opd_with_options<M: MeasurementRead>( &self, problem: &SpectralReconstructionProblem<M>, opd_range_m: (f64, f64), reference: &PhaseReference, opd_m: Array2<f64>, amplitudes: Vec<Array2<f64>>, options: &SpectralCheckpointOptions, ) -> Result<MultiWavelengthSolverResult>
Fits explicit OPD/amplitude starts while saving periodic accepted-state checkpoints.
Scientific input and gauge contracts are identical to run_from_opd.
Sourcepub fn run_from_checkpoint<M: MeasurementRead>(
&self,
problem: &SpectralReconstructionProblem<M>,
checkpoint: SpectralReconstructionCheckpoint,
) -> Result<MultiWavelengthSolverResult>
pub fn run_from_checkpoint<M: MeasurementRead>( &self, problem: &SpectralReconstructionProblem<M>, checkpoint: SpectralReconstructionCheckpoint, ) -> Result<MultiWavelengthSolverResult>
Resumes the saved joint OPD state without initialization or another gauge projection.
iterations is the total target; all other solver options, detector values,
masks/weights, and ordered compiled model metadata must match the checkpoint.
Sourcepub fn run_from_checkpoint_with_options<M: MeasurementRead>(
&self,
problem: &SpectralReconstructionProblem<M>,
checkpoint: SpectralReconstructionCheckpoint,
options: &SpectralCheckpointOptions,
) -> Result<MultiWavelengthSolverResult>
pub fn run_from_checkpoint_with_options<M: MeasurementRead>( &self, problem: &SpectralReconstructionProblem<M>, checkpoint: SpectralReconstructionCheckpoint, options: &SpectralCheckpointOptions, ) -> Result<MultiWavelengthSolverResult>
Resumes joint state and optionally continues periodic accepted-update checkpoint output.
Trait Implementations§
Source§impl Clone for MultiWavelengthGradientDescent
impl Clone for MultiWavelengthGradientDescent
Source§fn clone(&self) -> MultiWavelengthGradientDescent
fn clone(&self) -> MultiWavelengthGradientDescent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'de> Deserialize<'de> for MultiWavelengthGradientDescent
impl<'de> Deserialize<'de> for MultiWavelengthGradientDescent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for MultiWavelengthGradientDescent
impl RefUnwindSafe for MultiWavelengthGradientDescent
impl Send for MultiWavelengthGradientDescent
impl Sync for MultiWavelengthGradientDescent
impl Unpin for MultiWavelengthGradientDescent
impl UnsafeUnpin for MultiWavelengthGradientDescent
impl UnwindSafe for MultiWavelengthGradientDescent
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
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> ⓘ
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> ⓘ
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