Skip to main content

MultiWavelengthGradientDescent

Struct MultiWavelengthGradientDescent 

Source
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: usize

Positive maximum number of accepted full-data joint updates.

§initialization_iterations: usize

Positive number of spectral AP passes when automatic initialization is used.

§amplitude_step: f64

Finite positive multiplier for the pixel-count-scaled real amplitude gradient.

§opd_step: f64

Finite positive multiplier for the pixel-count-scaled phase-coordinate gradient.

§max_backtracks: usize

Positive maximum number of step trials per update, halving the common multiplier.

§epsilon: f64

Finite positive intensity smoothing and squared minimum amplitude.

Implementations§

Source§

impl MultiWavelengthGradientDescent

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> MultiWavelengthGradientDescent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MultiWavelengthGradientDescent

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for MultiWavelengthGradientDescent

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for MultiWavelengthGradientDescent

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for MultiWavelengthGradientDescent

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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
§

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

§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
§

fn size(&self) -> usize

The size of the key in bytes.
§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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<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.
§

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

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,