fn next_iter(
        &mut self,
        op: &mut OpWrapper<O>,
        state: &IterState<O>,
    ) -> Result<ArgminIterData<O>, Error> {
        self.p_prev = self.p.clone();
        let apk = op.apply(&self.p)?;
        self.alpha = self.rtr.div(&self.p.dot(&apk.conj()));
        let new_param = state.get_param().scaled_add(&self.alpha, &self.p);
        self.r = self.r.scaled_add(&self.alpha, &apk);
        let rtr_n = self.r.dot(&self.r.conj());
        self.beta = rtr_n.div(&self.rtr);
        self.rtr = rtr_n;
        self.p = self
            .r
            .mul(&(F::from_f64(-1.0).unwrap()))
            .scaled_add(&self.beta, &self.p);
        let norm = self.r.dot(&self.r.conj());

        Ok(ArgminIterData::new()
            .param(new_param)
            // .cost(norm.sqrt())
            .cost(norm.norm())
            .kv(make_kv!("alpha" => self.alpha; "beta" => self.beta;)))
    }
/// Perform one iteration of CG algorithm
Perform one iteration of CG algorithm
Perform one iteration of CG algorithm
fn next_iter(
        &mut self,
        op: &mut OpWrapper<O>,
        state: &IterState<O>,
    ) -> Result<ArgminIterData<O>, Error> {
        self.p_prev = self.p.clone();
        let apk = op.apply(&self.p)?;
        self.alpha = self.rtr.div(&self.p.dot(&apk.conj()));
        let new_param = state.get_param().scaled_add(&self.alpha, &self.p);
        self.r = self.r.scaled_add(&self.alpha, &apk);
        let rtr_n = self.r.dot(&self.r.conj());
        self.beta = rtr_n.div(&self.rtr);
        self.rtr = rtr_n;
        self.p = self
            .r
            .mul(&(F::from_f64(-1.0).unwrap()))
            .scaled_add(&self.beta, &self.p);
        let norm = self.r.dot(&self.r.conj());
        Ok(ArgminIterData::new()
            .param(new_param)
            // .cost(norm.sqrt())
            .cost(norm.norm())
            .kv(make_kv!("alpha" => self.alpha; "beta" => self.beta;)))
    }
fn next_iter ( & mut self , op : & mut OpWrapper < O > , state : & IterState < O > , ) -> Result < ArgminIterData < O > , Error > { self . p_prev = self . p . clone ( ) ; let apk = op . apply ( & self . p ) ? ; self . alpha = self . rtr . div ( & self . p . dot ( & apk . conj ( ) ) ) ; let new_param = state . get_param ( ) . scaled_add ( & self . alpha , & self . p ) ; self . r = self . r . scaled_add ( & self . alpha , & apk ) ; let rtr_n = self . r . dot ( & self . r . conj ( ) ) ; self . beta = rtr_n . div ( & self . rtr ) ; self . rtr = rtr_n ; self . p = self . r . mul ( & ( F :: from_f64 ( - 1.0 ) . unwrap ( ) ) ) . scaled_add ( & self . beta , & self . p ) ; let norm = self . r . dot ( & self . r . conj ( ) ) ; Ok ( ArgminIterData :: new ( ) . param ( new_param ) // .cost(norm.sqrt()) . cost ( norm . norm ( ) ) . kv ( make_kv ! ( " " self alpha " " self beta ) ) ) }
Perform one iteration of CG algorithm
Perform one iteration of CG algorithm
&mut self
op
&mut OpWrapper<O>
state
&IterState<O>