/usr/include/relion-1.3/src/numerical_recipes.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 | /***************************************************************************
*
* 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.
***************************************************************************/
/***************************************************************************
*
* Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
*
* Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
* All comments concerning this program package may be sent to the
* e-mail address 'xmipp@cnb.csic.es'
***************************************************************************/
#ifndef _NUMERICAL_HH
# define _NUMERICAL_HH
#include <math.h>
#include "src/memory.h"
#include "src/macros.h"
#include "src/error.h"
/*****************************************************************************/
/* Variable and prototype definitions for the Numerical Core */
/*****************************************************************************/
//@defgroup NumericalRecipes Functions from the Numerical Recipes
//@ingroup DataLibrary
//@{
// Utilities --------------------------------------------------------------
void nrerror(const char error_text[]);
// Random numbers ---------------------------------------------------------
double ran1(int *idum); // Uniform random
double gasdev(int *idum); // Gaussian random
double tdev(double nu, int *idum); // t-student random
// Bessel functions --------------------------------------------------------
double bessj0(double x);
double bessj3_5(double x);
double bessj1_5(double x);
double bessi0(double x);
double bessi1(double x);
double bessi0_5(double x);
double bessi1_5(double x);
double bessi2(double x);
double bessi3(double x);
double bessi2_5(double x);
double bessi3_5(double x);
double bessi4(double x);
// Special functions -------------------------------------------------------
double gammln(double xx);
double gammp(double a, double x);
double betacf(double a, double b, double x);
double betai(double a, double b, double x);
// Singular value descomposition of matrix a (numerical recipes, chapter 2-6 for details)
void svdcmp(double *a, int m, int n, double *w, double *v);
void svbksb(double *u, double *w, double *v, int m, int n, double *b, double *x);
// Optimization ------------------------------------------------------------
void powell(double *p, double *xi, int n, double ftol, int &iter,
double &fret, double(*func)(double *, void *), void *prm,
bool show);
// Working with matrices ---------------------------------------------------
// LU decomposition
#define TINY 1.0e-20;
/* Chapter 2 Section 3: LU DECOMPOSITION */
template <class T>
void ludcmp(T *a, int n, int *indx, T *d)
{
int i, imax, j, k;
T big, dum, sum, temp;
T *vv;
ask_Tvector(vv, 1, n);
*d = (T)1.0;
for (i = 1;i <= n;i++)
{
big = (T)0.0;
for (j = 1;j <= n;j++)
if ((temp = (T)fabs((double)a[i*n+j])) > big)
big = temp;
if (big == (T)0.0)
nrerror("Singular matrix in routine LUDCMP");
vv[i] = (T)1.0 / big;
}
for (j = 1;j <= n;j++)
{
for (i = 1;i < j;i++)
{
sum = a[i*n+j];
for (k = 1;k < i;k++)
sum -= a[i*n+k] * a[k*n+j];
a[i*n+j] = sum;
}
big = (T)0.0;
for (i = j;i <= n;i++)
{
sum = a[i*n+j];
for (k = 1;k < j;k++)
sum -= a[i*n+k] * a[k*n+j];
a[i*n+j] = sum;
if ((dum = vv[i] * (T)fabs((double)sum)) >= big)
{
big = dum;
imax = i;
}
}
if (j != imax)
{
for (k = 1;k <= n;k++)
{
dum = a[imax*n+k];
a[imax*n+k] = a[j*n+k];
a[j*n+k] = dum;
}
*d = -(*d);
vv[imax] = vv[j];
}
indx[j] = imax;
if (a[j*n+j] == 0.0)
a[j*n+j] = (T) TINY;
if (j != n)
{
dum = (T)1.0 / (a[j*n+j]);
for (i = j + 1;i <= n;i++)
a[i*n+j] *= dum;
}
}
free_Tvector(vv, 1, n);
}
#undef TINY
// Solve Ax=b
/* Chapter 2 Section 3: LU BACKWARD-FORWARD SUBSTITUTION */
template <class T>
void lubksb(T *a, int n, int *indx, T b[])
{
int i, ii = 0, ip, j;
T sum;
for (i = 1;i <= n;i++)
{
ip = indx[i];
sum = b[ip];
b[ip] = b[i];
if (ii)
for (j = ii;j <= i - 1;j++)
sum -= a[i*n+j] * b[j];
else if (sum)
ii = i;
b[i] = sum;
}
for (i = n;i >= 1;i--)
{
sum = b[i];
for (j = i + 1;j <= n;j++)
sum -= a[i*n+j] * b[j];
b[i] = sum / a[i*n+i];
}
}
/* Chapter 2, Section 1. Gauss-Jordan equation system resolution ----------- */
// Solve Ax=b (b=matrix)
template <class T>
void gaussj(T *a, int n, T *b, int m)
{
T temp;
int *indxc, *indxr, *ipiv;
int i, icol, irow, j, k, l, ll;
T big, dum;
double pivinv;
ask_Tvector(indxc, 1, n);
ask_Tvector(indxr, 1, n);
ask_Tvector(ipiv, 1, n);
for (j = 1;j <= n;j++)
ipiv[j] = 0;
for (i = 1;i <= n;i++)
{
big = (T)0;
for (j = 1;j <= n;j++)
if (ipiv[j] != 1)
for (k = 1;k <= n;k++)
{
if (ipiv[k] == 0)
{
if (fabs((double)a[j*n+k]) >= (double) big)
{
big = ABS(a[j*n+k]);
irow = j;
icol = k;
}
}
else if (ipiv[k] > 1)
nrerror("GAUSSJ: Singular Matrix-1");
}
++(ipiv[icol]);
if (irow != icol)
{
for (l = 1;l <= n;l++)
SWAP(a[irow*n+l], a[icol*n+l], temp)
for (l = 1;l <= m;l++)
SWAP(b[irow*n+l], b[icol*n+l], temp)
}
indxr[i] = irow;
indxc[i] = icol;
if (a[icol*n+icol] == 0.0)
nrerror("GAUSSJ: Singular Matrix-2");
pivinv = 1.0f / a[icol*n+icol];
a[icol*n+icol] = (T)1;
for (l = 1;l <= n;l++)
a[icol*n+l] = (T)(pivinv * a[icol*n+l]);
for (l = 1;l <= m;l++)
b[icol*n+l] = (T)(pivinv * b[icol*n+l]);
for (ll = 1;ll <= n;ll++)
if (ll != icol)
{
dum = a[ll*n+icol];
a[ll*n+icol] = (T)0;
for (l = 1;l <= n;l++)
a[ll*n+l] -= a[icol*n+l] * dum;
for (l = 1;l <= m;l++)
b[ll*n+l] -= b[icol*n+l] * dum;
}
}
for (l = n;l >= 1;l--)
{
if (indxr[l] != indxc[l])
for (k = 1;k <= n;k++)
SWAP(a[k*n+indxr[l]], a[k*n+indxc[l]], temp);
}
free_Tvector(ipiv, 1, n);
free_Tvector(indxr, 1, n);
free_Tvector(indxc, 1, n);
}
#endif
|