argmin/solver/landweber/
mod.rs

1// Copyright 2018-2020 argmin developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8//! Landweber iteration
9//!
10//! [Landweber](struct.Landweber.html)
11//!
12//! # References
13//!
14//! [0] Landweber, L. (1951): An iteration formula for Fredholm integral equations of the first
15//! kind. Amer. J. Math. 73, 615–624
16//! [1] https://en.wikipedia.org/wiki/Landweber_iteration
17
18use crate::prelude::*;
19use serde::{Deserialize, Serialize};
20
21/// The Landweber iteration is a solver for ill-posed linear inverse problems.
22///
23/// In iteration `k`, the new parameter vector `x_{k+1}` is calculated from the previous parameter
24/// vector `x_k` and the gradient at `x_k` according to the following update rule:
25///
26/// `x_{k+1} = x_k - omega * \nabla f(x_k)`
27///
28/// [Example](https://github.com/argmin-rs/argmin/blob/master/examples/landweber.rs)
29///
30/// # References
31///
32/// [0] Landweber, L. (1951): An iteration formula for Fredholm integral equations of the first
33/// kind. Amer. J. Math. 73, 615–624
34/// [1] https://en.wikipedia.org/wiki/Landweber_iteration
35#[derive(Clone, Serialize, Deserialize)]
36pub struct Landweber<F> {
37    /// omega
38    omega: F,
39}
40
41impl<F> Landweber<F> {
42    /// Constructor
43    pub fn new(omega: F) -> Self {
44        Landweber { omega }
45    }
46}
47
48impl<O, F> Solver<O> for Landweber<F>
49where
50    O: ArgminOp<Float = F>,
51    O::Param: ArgminScaledSub<O::Param, O::Float, O::Param>,
52    F: ArgminFloat,
53{
54    const NAME: &'static str = "Landweber";
55
56    fn next_iter(
57        &mut self,
58        op: &mut OpWrapper<O>,
59        state: &IterState<O>,
60    ) -> Result<ArgminIterData<O>, Error> {
61        let param = state.get_param();
62        let grad = op.gradient(&param)?;
63        let new_param = param.scaled_sub(&self.omega, &grad);
64        Ok(ArgminIterData::new().param(new_param))
65    }
66}
67
68#[cfg(test)]
69mod tests {
70    use super::*;
71    use crate::test_trait_impl;
72
73    test_trait_impl!(landweber, Landweber<f64>);
74}