Files
Jungfraujoch/image_analysis/scale_merge/AndersonMixing.h
T
leonarski_f afbe844b20
Build Packages / Create release (push) Successful in 17s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 4m41s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 20m49s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 13m6s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 23m44s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 7m28s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 11m50s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 14m9s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 16m25s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 15m42s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 20m50s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 20m36s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 22m18s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 23m29s
Build Packages / Generate python client (push) Successful in 30s
Build Packages / Build documentation (push) Successful in 1m10s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 21m38s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 17m8s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 23m10s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 19m16s
Build Packages / Unit tests (push) Successful in 2h8m4s
Build Packages / Validation Battery (push) Successful in 40m53s
v1.0.0-rc.178 (#88)
* Rugnux: Processes serial crystallography data from XFELs - SACLA (MPCCD), PAL-XFEL and European XFEL (CXI), LCLS (XTC) and SwissFEL Alvra (JUNGFRAU with a CrystFEL module geometry) - with several files or Jungfraujoch master files merged in one run (`rugnux *_master.h5`).
* Rugnux: Stills processing takes a known unit cell and space group as a starting point, finds the beam centre (and, with a cell, the detector distance) from the images, detects the saturation level in other facilities' files and refines the placement of individual detector panels.
* Rugnux: The stills report gives R_split and CC1/2 from frame half-sets, comparable with CrystFEL.
* jfjoch_viewer: Opens the same XFEL file formats.
* Validation: A stills battery checks Rugnux against deposited structures from SACLA, PAL-XFEL, LCLS, European XFEL and SwissFEL.
* Rugnux: More reliable convergence of rotation scaling, and live molecular replacement starts as soon as the model is uploaded.
* jfjoch_broker: Initialize clears the previous dataset's bearer tokens, image buffer and live Rugnux status, and a slow CUDA JIT cache is reported at start.

Reviewed-on: #88
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-10-21 11:20:01 +02:00

47 lines
2.0 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <cstdint>
#include <deque>
#include <vector>
#include <Eigen/Dense>
// Acceleration of a fixed-point iteration x -> F(x) that converges linearly. Each round hands in the
// state x it started from and F(x), where one plain round took it; the residual r = F(x) - x is what
// the plain iteration would step. The state the next round starts from is F(x) corrected by the
// combination of the last few rounds' steps that best cancels r, so the slow directions the plain
// iteration creeps along - a handful of them, whose contraction is close to one - are taken in a few
// rounds. Where r = 0 the correction is 0: the fixed point is the plain iteration's.
//
// Each component carries a weight in the norm r is measured in; a component of weight 0 takes F(x)
// unchanged and is not part of the fit. The history is dropped, and the round is a plain one, when
// the set of components of non-zero weight changed, since the differences of the history are then
// differences of different things.
//
// Acceleration is for a map that contracts. A residual that grows from one round to the next says the
// iteration is not on its way to a fixed point here - it walks, or the map itself moved - and
// extrapolating from its history takes it further along the walk. From that round on every round is
// a plain one.
class AndersonMixing {
public:
explicit AndersonMixing(int depth) : depth(depth) {}
std::vector<double> Next(const std::vector<double> &x, const std::vector<double> &fx,
const std::vector<double> &w);
int Restarts() const { return restarts; }
bool Stopped() const { return stopped; }
private:
int depth;
int restarts = 0;
bool stopped = false;
std::deque<Eigen::VectorXd> dx, dr; // x and r differences of consecutive rounds, newest last
Eigen::VectorXd x_last, r_last;
std::vector<uint8_t> support_last;
double r_norm_last = 0.0;
};