/usr/include/relion-1.3/src/ml_model.h is in librelion-dev-common 1.3+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | /***************************************************************************
*
* Author: "Sjors H.W. Scheres"
* MRC Laboratory of Molecular Biology
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This complete copyright notice must be included in any revised version of the
* source code. Additional authorship citations may be added, but existing
* author citations must be preserved.
***************************************************************************/
#ifndef ML_MODEL_H_
#define ML_MODEL_H_
#include "src/projector.h"
#include "src/backprojector.h"
#include "src/metadata_table.h"
#include "src/exp_model.h"
#include "src/healpix_sampling.h"
#define ML_BLOB_ORDER 0
#define ML_BLOB_RADIUS 1.9
#define ML_BLOB_ALPHA 15
class MlModel
{
public:
// Dimension of the references (2D or 3D)
int ref_dim;
// Original size of the images
int ori_size;
// Pixel size (in Angstrom)
double pixel_size;
// Current size of the images to be used in the expectation
int current_size;
// Current resolution (in 1/Ang)
double current_resolution;
// Number of classes
int nr_classes;
// Number of image groups with separate sigma2_noise spectra
int nr_groups;
// Number of particles in each group
std::vector<long int> nr_particles_group;
// Number of directions (size of pdf_direction);
int nr_directions;
// Log-likelihood target value
double LL;
// Padding factor
int padding_factor;
// Fourier space interpolator
int interpolator;
// Minimum number of shells to perform linear interpolation
int r_min_nn;
// Average Pmax of the normalised probability distributions
double ave_Pmax;
// Average normalisation correction factor
double avg_norm_correction;
// Variance in the origin offsets
double sigma2_offset;
// Fudge factor to adjust estimated tau2_class spectra
double tau2_fudge_factor;
// Vector with all reference images
std::vector<MultidimArray<double> > Iref;
// One projector for each class;
std::vector<Projector > PPref;
// One name for each group
std::vector<FileName> group_names;
// One noise spectrum for each group
std::vector<MultidimArray<double > > sigma2_noise;
// One intensity scale for each group
std::vector<double> scale_correction;
// One intensity B-factor for each group
std::vector<double> bfactor_correction;
// Prior information: one restrained power_class spectrum for each class (inverse of right-hand side in Wiener-filter-like update formula)
std::vector<MultidimArray<double > > tau2_class;
// Radial average of the estimated variance in the reconstruction (inverse of left-hand side in Wiener-filter-like update formula)
std::vector<MultidimArray<double > > sigma2_class;
// FSC spectra between random halves of the data
std::vector<MultidimArray<double > > fsc_halves_class;
// One likelihood vs prior ratio spectrum for each class
std::vector<MultidimArray<double > > data_vs_prior_class;
// One value for each class
std::vector<double > pdf_class;
// One array for each class
std::vector<MultidimArray<double> > pdf_direction;
// Priors for offsets for each class (only in 2D)
std::vector<Matrix1D<double> > prior_offset_class;
// Mode for orientational prior distributions
int orientational_prior_mode;
// Variance in rot angle for the orientational pdf
double sigma2_rot;
// Variance in tilt angle for the orientational pdf
double sigma2_tilt;
// Variance in psi angle for the orientational pdf
double sigma2_psi;
// Estimated accuracy at which rotations can be assigned, one for each class
std::vector<double> acc_rot;
// Estimated accuracy at which translations can be assigned, one for each class
std::vector<double> acc_trans;
// Spectral contribution to orientability of individual particles, one for each class
std::vector<MultidimArray<double > > orientability_contrib;
public:
// Constructor
MlModel()
{
clear();
}
// Destructor
~MlModel()
{
clear();
}
// Clear everything
void clear()
{
Iref.clear();
PPref.clear();
group_names.clear();
sigma2_noise.clear();
scale_correction.clear();
bfactor_correction.clear();
tau2_class.clear();
fsc_halves_class.clear();
sigma2_class.clear();
data_vs_prior_class.clear();
pdf_class.clear();
pdf_direction.clear();
nr_particles_group.clear();
ref_dim = ori_size = nr_classes = nr_groups = nr_directions = interpolator = r_min_nn = padding_factor = 0;
ave_Pmax = avg_norm_correction = LL = sigma2_offset = tau2_fudge_factor = 0.;
sigma2_rot = sigma2_tilt = sigma2_psi = 0.;
acc_rot.clear();
acc_trans.clear();
orientability_contrib.clear();
}
// Initialise vectors with the right size
void initialise();
//Read a model from a file
void read(FileName fn_in);
// Write a model to disc
void write(FileName fn_out, HealpixSampling &sampling);
//Read a tau-spectrum from a STAR file
void readTauSpectrum(FileName fn_tau, int verb);
// Read images from disc and initialise
// Also set do_average_unaligned and do_generate_seeds flags
void readImages(FileName fn_ref, int _ori_size, Experiment &_mydata,
bool &do_average_unaligned, bool &do_generate_seeds, bool &refs_are_ctf_corrected);
// Given the Experiment of the already expanded dataset of movieframes, expand the current MlModel to contain all movie frames
// Make a new group for each unique rlnGroupName in the expanded Experiment, copying the values from the groups in the current MlModel
// For that: remove "00000i@" as well as movie extension from the rlnGroupName in the expanded Experiment and compare with group_names in current MlModel
void expandToMovieFrames(Experiment &moviedataexpand, int running_avg_side);
double getResolution(int ipix) { return (double)ipix/(pixel_size * ori_size); }
double getResolutionAngstrom(int ipix) { return (ipix==0) ? 999. : (pixel_size * ori_size)/(double)ipix; }
int getPixelFromResolution(double resol) { return (int)(resol * pixel_size * ori_size); }
/** Initialise pdf_orient arrays to the given size
* If the pdf_orient vectors were empty, resize them to the given size and initialise with an even distribution
* If they were not empty, check that the new size is equal to the old one, and otherwise throw an exception
* because one cannot use an old pdf_orient with size unequal to the new one
*/
void initialisePdfDirection(int newsize);
// Set FourierTransforms in Projector of each class
// current_size will determine the size of the transform (in number of Fourier shells) to be held in the projector
void setFourierTransformMaps(bool update_tau2_spectra, int nr_threads = 1);
/* Initialises the radial average of the data-versus-prior ratio
*/
void initialiseDataVersusPrior(bool fix_tau);
};
class MlWsumModel: public MlModel
{
public:
// One backprojector for CTF-corrected estimate of each class;
std::vector<BackProjector > BPref;
// Store the sum of the weights inside each group
// That is the number of particles inside each group
std::vector<double> sumw_group;
// For the refinement of group intensity scales and bfactors
// For each group store weighted sums of experimental image times reference image as a function of resolution
std::vector<MultidimArray<double > > wsum_signal_product_spectra;
// For each group store weighted sums of squared reference as a function of resolution
std::vector<MultidimArray<double > > wsum_reference_power_spectra;
// Constructor
MlWsumModel()
{
clear();
}
// Destructor
~MlWsumModel()
{
clear();
}
// Clear everything
void clear()
{
BPref.clear();
sumw_group.clear();
MlModel::clear();
}
// Initialise all weighted sums (according to size of corresponding model
void initialise(MlModel &_model, FileName fn_sym = "c1");
// Initialize all weighted sums to zero (with resizing the BPrefs to current_size)
void initZeros();
// Pack entire structure into one large MultidimArray<double> for reading/writing to disc
// To save memory, the model itself will be cleared after packing.
void pack(MultidimArray<double> &packed);
// Fill the model again using unpack (this is the inverse operation from pack)
void unpack(MultidimArray<double> &packed);
// Pack entire structure into one large MultidimArray<double> for shipping over with MPI
// To save memory, the model itself will be cleared after packing.
// If the whole thing becomes bigger than 1Gb (see MAX_PACK_SIZE in ml_model.cpp), then break it up into pieces because MPI cannot handle very large messages
// When broken up: nr_pieces > 1
void pack(MultidimArray<double> &packed, int &piece, int &nr_pieces, bool do_clear=true);
// Fill the model again using unpack (this is the inverse operation from pack)
void unpack(MultidimArray<double> &packed, int piece, bool do_clear=true);
};
#endif /* ML_MODEL_H_ */
|