ProteoWizard
Namespaces | Classes | Functions
pwiz::math Namespace Reference

Namespaces

namespace  MatchedFilter
 
namespace  types
 

Classes

class  LinearLeastSquares
 
class  LinearLeastSquares< LinearLeastSquaresType_LU >
 
class  LinearLeastSquares< LinearLeastSquaresType_QR >
 
class  LinearSolver
 
class  LinearSolver< LinearSolverType_LU >
 
class  LinearSolver< LinearSolverType_QR >
 
struct  OrderedPair
 
class  OrderedPairContainerRef
 wrapper class for accessing contiguous data as a container of OrderedPairs; note that it does not own the underlying data More...
 
class  Parabola
 
class  Stats
 

Functions

PWIZ_API_DECL double erf (double x)
 real error function; calls gcc-provided erf, complex version (below) on msvc
 
PWIZ_API_DECL std::complex< double > erf (const std::complex< double > &z)
 complex error function
 
PWIZ_API_DECL std::complex< double > erf_series2 (const std::complex< double > &z)
 series implementation for testing
 
template<class T >
void TransposeMultiply (const ublas::vector< T > &vector, ublas::matrix< T > &result, size_t size)
 
template<class T >
void HouseholderCornerSubstraction (ublas::matrix< T > &LeftLarge, const ublas::matrix< T > &RightSmall)
 
template<class T >
void HouseholderQR (const ublas::matrix< T > &M, ublas::matrix< T > &Q, ublas::matrix< T > &R)
 
std::ostream & operator<< (std::ostream &os, const OrderedPair &p)
 
std::istream & operator>> (std::istream &is, OrderedPair &p)
 
bool operator== (const OrderedPair &a, const OrderedPair &b)
 
bool operator!= (const OrderedPair &a, const OrderedPair &b)
 
PWIZ_API_DECL std::ostream & operator<< (std::ostream &os, const Parabola &p)
 
template<class matrix_type , class vector_type >
void Reflector (const vector_type &x, matrix_type &F)
 
template<class matrix_type , class vector_type >
matrix_type Reflector (const vector_type &x)
 
template<class matrix_type >
void qr (const matrix_type &A, matrix_type &Q, matrix_type &R)
 

Function Documentation

◆ erf() [1/2]

PWIZ_API_DECL double pwiz::math::erf ( double  x)

real error function; calls gcc-provided erf, complex version (below) on msvc

Referenced by test_real(), test_real_wrapper(), and test_series().

◆ erf() [2/2]

PWIZ_API_DECL std::complex< double > pwiz::math::erf ( const std::complex< double > &  z)

complex error function

◆ erf_series2()

PWIZ_API_DECL std::complex< double > pwiz::math::erf_series2 ( const std::complex< double > &  z)

series implementation for testing

Referenced by test_series().

◆ TransposeMultiply()

template<class T >
void pwiz::math::TransposeMultiply ( const ublas::vector< T > &  vector,
ublas::matrix< T > &  result,
size_t  size 
)

Definition at line 39 of file HouseholderQR.hpp.

42{
43 result.resize (size,size);
44 result.clear ();
45 for(unsigned int row=0; row< vector.size(); ++row)
46 {
47 for(unsigned int col=0; col < vector.size(); ++col)
48 result(row,col) = vector(col) * vector(row);
49
50 }
51}

Referenced by HouseholderQR().

◆ HouseholderCornerSubstraction()

template<class T >
void pwiz::math::HouseholderCornerSubstraction ( ublas::matrix< T > &  LeftLarge,
const ublas::matrix< T > &  RightSmall 
)

Definition at line 54 of file HouseholderQR.hpp.

56{
57 using namespace boost::numeric::ublas;
58 using namespace std;
59 if(
60 !(
61 (LeftLarge.size1() >= RightSmall.size1())
62 && (LeftLarge.size2() >= RightSmall.size2())
63 )
64 )
65 {
66 cerr << "invalid matrix dimensions" << endl;
67 return;
68 }
69
70 size_t row_offset = LeftLarge.size2() - RightSmall.size2();
71 size_t col_offset = LeftLarge.size1() - RightSmall.size1();
72
73 for(unsigned int row = 0; row < RightSmall.size2(); ++row )
74 for(unsigned int col = 0; col < RightSmall.size1(); ++col )
75 LeftLarge(col_offset+col,row_offset+row) -= RightSmall(col,row);
76}
STL namespace.

Referenced by HouseholderQR().

◆ HouseholderQR()

template<class T >
void pwiz::math::HouseholderQR ( const ublas::matrix< T > &  M,
ublas::matrix< T > &  Q,
ublas::matrix< T > &  R 
)

Definition at line 79 of file HouseholderQR.hpp.

82{
83 using namespace boost::numeric::ublas;
84 using namespace std;
85
86 if(
87 !(
88 (M.size1() == M.size2())
89 )
90 )
91 {
92 cerr << "invalid matrix dimensions" << endl;
93 return;
94 }
95 size_t size = M.size1();
96
97 // init Matrices
98 matrix<T> H, HTemp;
99 HTemp = identity_matrix<T>(size);
100 Q = identity_matrix<T>(size);
101 R = M;
102
103 // find Householder reflection matrices
104 for(unsigned int col = 0; col < size-1; ++col)
105 {
106 // create X vector
107 ublas::vector<T> RRowView = column(R,col);
108 vector_range< ublas::vector<T> > X2 (RRowView, range (col, size));
109 ublas::vector<T> X = X2;
110
111 // X -> U~
112 if(X(0) >= 0)
113 X(0) += norm_2(X);
114 else
115 X(0) += -1*norm_2(X);
116
117 HTemp.resize(X.size(),X.size(),true);
118
119 TransposeMultiply(X, HTemp, X.size());
120
121 // HTemp = the 2UUt part of H
122 HTemp *= ( 2 / inner_prod(X,X) );
123
124 // H = I - 2UUt
125 H = identity_matrix<T>(size);
126 HouseholderCornerSubstraction(H,HTemp);
127
128 // add H to Q and R
129 Q = prod(Q,H);
130 R = prod(H,R);
131 }
132}
H
Definition Chemistry.hpp:80

References H, HouseholderCornerSubstraction(), and TransposeMultiply().

Referenced by main().

◆ operator<<() [1/2]

std::ostream & pwiz::math::operator<< ( std::ostream &  os,
const OrderedPair p 
)
inline

Definition at line 49 of file OrderedPair.hpp.

50{
51 os << "(" << p.x << "," << p.y << ")";
52 return os;
53}

References pwiz::math::OrderedPair::x, and pwiz::math::OrderedPair::y.

◆ operator>>()

std::istream & pwiz::math::operator>> ( std::istream &  is,
OrderedPair p 
)
inline

Definition at line 56 of file OrderedPair.hpp.

57{
58 char open='\0', comma='\0', close='\0';
59 is >> open >> p.x >> comma >> p.y >> close;
60 if (!is) return is;
61 if (open!='(' || comma!=',' || close!=')')
62 throw std::runtime_error("[OrderedPair::operator>>] Unexpected input.");
63 return is;
64}

References pwiz::math::OrderedPair::x, and pwiz::math::OrderedPair::y.

◆ operator==()

bool pwiz::math::operator== ( const OrderedPair a,
const OrderedPair b 
)
inline

Definition at line 67 of file OrderedPair.hpp.

68{
69 return a.x==b.x && a.y==b.y;
70}

References pwiz::math::OrderedPair::x, and pwiz::math::OrderedPair::y.

◆ operator!=()

bool pwiz::math::operator!= ( const OrderedPair a,
const OrderedPair b 
)
inline

Definition at line 73 of file OrderedPair.hpp.

74{
75 return !(a == b);
76}

◆ operator<<() [2/2]

PWIZ_API_DECL std::ostream & pwiz::math::operator<< ( std::ostream &  os,
const Parabola p 
)

◆ Reflector() [1/2]

template<class matrix_type , class vector_type >
void pwiz::math::Reflector ( const vector_type &  x,
matrix_type &  F 
)

Definition at line 39 of file qr.hpp.

40{
41 using namespace boost::numeric::ublas;
42
43 typedef typename matrix_type::value_type value_type;
44
45 unit_vector<value_type> e1(x.size(), 0);
46
47 //v_k = -sgn( x(1) ) * inner_prod(x) * e1 + x;
48 double x_2 = norm_2(x);
49 boost::numeric::ublas::vector<value_type>
50 v_k((x(0) >= 0 ? x_2 : -1 * x_2) * e1 + x);
51
52 //v_k = v_k / norm_2(v_k);
53 double norm_vk = norm_2(v_k);
54 if (norm_vk != 0)
55 v_k /= norm_2(v_k);
56
57 // F = A(k:m,k:n) - 2 * outer_prod(v_k, v_k) * A(k:m,k:n)
58 identity_matrix<value_type> eye(v_k.size());
59 F = matrix_type(v_k.size(), v_k.size());
60
61 F = eye - 2. * outer_prod(v_k, v_k);
62}
F
Definition Chemistry.hpp:81
KernelTraitsBase< Kernel >::space_type::abscissa_type x

References F, and x.

Referenced by qr(), and testReflector().

◆ Reflector() [2/2]

template<class matrix_type , class vector_type >
matrix_type pwiz::math::Reflector ( const vector_type &  x)

Definition at line 69 of file qr.hpp.

70{
71 using namespace boost::numeric::ublas;
72
73 matrix_type F(x.size(), x.size());
74
75 Reflector<matrix_type, vector_type>(x, F);
76
77 return F;
78}

References F, and x.

◆ qr()

template<class matrix_type >
void pwiz::math::qr ( const matrix_type &  A,
matrix_type &  Q,
matrix_type &  R 
)

Definition at line 81 of file qr.hpp.

82{
83 using namespace boost::numeric::ublas;
84
85 typedef typename matrix_type::size_type size_type;
86 typedef typename matrix_type::value_type value_type;
87
88 // TODO resize Q and R to match the needed size.
89 int m=A.size1();
90 int n=A.size2();
91
92 identity_matrix<value_type> ident(m);
93 if (Q.size1() != ident.size1() || Q.size2() != ident.size2())
94 Q = matrix_type(m, m);
95 Q.assign(ident);
96
97 R.clear();
98 R = A;
99
100 for (size_type k=0; k< R.size1() && k<R.size2(); k++)
101 {
102 slice s1(k, 1, m - k);
103 slice s2(k, 0, m - k);
104 unit_vector<value_type> e1(m - k, 0);
105
106 // x = A(k:m, k);
107 matrix_vector_slice<matrix_type> x(R, s1, s2);
108 matrix_type F(x.size(), x.size());
109
110 Reflector(x, F);
111
112 matrix_type temp = subrange(R, k, m, k, n);
113 //F = prod(F, temp);
114 subrange(R, k, m, k, n) = prod(F, temp);
115
116 // <<---------------------------------------------->>
117 // forming Q
118 identity_matrix<value_type> iqk(A.size1());
119 matrix_type Q_k(iqk);
120
121 subrange(Q_k, Q_k.size1() - F.size1(), Q_k.size1(),
122 Q_k.size2() - F.size2(), Q_k.size2()) = F;
123
124 Q = prod(Q, Q_k);
125 }
126}
#define A
Kernel k
void Reflector(const vector_type &x, matrix_type &F)
Definition qr.hpp:39

References A, F, k, Reflector(), and x.

Referenced by pwiz::math::LinearSolver< LinearSolverType_QR >::solve().