ProteoWizard
matops.h
Go to the documentation of this file.
1 // $Id: matops.h 1814 2010-02-16 22:52:44Z chambm $
2 //
3 // Copyright 2009 Spielberg Family Center for Applied Proteomics
4 // Cedars Sinai Medical Center, Los Angeles, California 90048
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 
19 #ifndef MATOPS
20 #define MATOPS
21 
22 #include <complex>
23 #include <vector>
24 #include <fstream>
25 #include <iostream>
26 
27 using namespace std;
28 
29 vector<int> d2i(vector<double>);
30 vector<double> i2d(vector<int>);
31 vector<vector<int> > d2i(vector<vector<double> >);
32 vector<vector<double> > i2d(vector<vector<int> >);
33 
34 bool operator == (vector<double> &,vector<double> &);
35 bool operator == (vector<vector<double> > &, vector<vector<double> > &);
36 vector<vector<double> > eig(vector<vector<double> >);
37 vector<vector<double> > eig2(vector<vector<double> >);
38 vector<double> cm(vector<vector<double> > positions, vector<double> weights = vector<double>(0));
39 vector<vector<double> > cov(vector<vector<double> >, vector<double> = vector<double>(0));
40 double mean_angle(vector<vector<double> > pts, vector<double> c);
41 vector<double> operator + (vector<double>,vector<double>);
42 void operator += (vector<int>&, vector<int>);
43 void operator += (vector<double>&, vector<double>);
44 void operator += (vector<complex<double> >&, vector<complex<double> >);
45 void operator *= (vector<double>&, double);
46 vector<int> operator + (vector<int>,vector<int>);
47 vector<int> operator - (vector<int>,vector<int>);
48 vector<double> operator - (vector<double>,vector<double>);
49 vector<vector<double> >operator +(vector<vector<double> >,vector<vector<double> >);
50 vector<vector<complex<double> > > operator +
51  (vector<vector<complex<double> > >&,vector<vector<complex<double> > >&);
52 void operator += (vector<vector<double> >&, vector<vector<double> >);
53 void operator += (vector<vector<complex<double> > >&,
54  vector<vector<complex<double> > >&);
55 vector<vector<double> >operator -(vector<vector<double> >,vector<vector<double> > );
56 double operator * (vector<double>,vector<double>); // inner product
57 double operator * (vector<complex<double> >,vector<complex<double> >); // inner product
58 int operator * (vector<int>,vector<int>); // inner product
59 double operator * (vector<int>,vector<double>); // inner product
60 vector<vector<double> > operator % (vector<double>,vector<double>); //outer prod
61 vector<vector<int> > operator % (vector<int>,vector<int>); //outer prod
62 vector<double> operator * (double,vector<double>); // scalar mult
63 vector<complex<double> > operator * (double,vector<complex<double> > );
64 vector<int> operator * (int,vector<int>); // scalar mult
65 vector<double> operator * (double,vector<int>); // scalar mult
66 vector<vector<double> > operator * (double,vector<vector<double> >); //scal mult
67 vector<vector<double> > operator * (double,vector<vector<int> >); //scal mult
68 vector<double> operator * (vector<vector<double> >,vector<double>); // mat * vect
69 vector<double> operator * (vector<vector<double> >,vector<int>); // mat * vect
70 vector<int> operator * (vector<vector<int> >,vector<int>); // mat * vect
71 vector<vector<double> > operator *
72  (vector<vector<double> >,vector<vector<double> >); // mat * mat
73 vector<vector<complex<double> > > operator *
74  (vector<vector<complex<double> > >,vector<vector<complex<double> > >); // mat * mat
75 vector<vector<double> > transpose(vector<vector<double> >);
76 vector<vector<int> > transpose(vector<vector<int> >);
77 vector<vector<complex<double> > > transpose(vector<vector<complex<double> > >);
78 double norm(vector<double>);
79 double norm(vector<int>);
80 vector<double> operator ^ (vector<double>,vector<double>); // cross product
81 vector<double> e(int,int);
82 vector<vector<double> > inverse(vector<vector<double> >);
83 ostream& operator<<(ostream& out,vector<vector<complex<double> > > v);
84 ostream& operator<<(ostream& out,vector<complex<double> > v);
85 ostream& operator<<(ostream& out,vector<vector<double> > v);
86 ostream& operator<<(ostream& out,vector<vector<int> > v);
87 ostream& operator<<(ostream& out,vector<double> v);
88 ostream& operator<<(ostream& out,vector<int> v);
89 ostream& operator<<(ostream& out,vector<bool> v);
90 vector<vector<double> > ident(int);
91 vector<double> zero(int);
92 vector<vector<double> > zero_mat(int);
93 vector<vector<double> > rotmat(vector<double>,double);
94 vector<double> rotate(vector<double>,vector<double>,double);
95 vector<vector<double> > rot_align(vector<double> v, vector<double> target);
96 double trace(vector<vector<double> >);
97 void rep_rot(vector<vector<double> >,vector<double> *, double *);
98 double quad_form(vector<double>,vector<vector<double> >,vector<double>);
99 double quad_form(vector<int>,vector<vector<double> >,vector<int>);
100 vector<vector<double> > diag(vector<double>);
101 vector<double> euler(vector<double>); // theta, phi
102 int epsilon(int,int,int);
103 vector<vector<double> > kill_row(vector<vector<double> >, int);
104 vector<vector<double> > kill_col(vector<vector<double> >, int);
105 double determinant(vector<vector<double> >);
106 
107 vector<double> getNormal(const vector<double> &, const vector<double> &);
108 double getAngle(const vector<double> &, const vector<double> &);
109 double getAngle(const vector<double> &, const vector<double> &, const vector<double> &normal);
110 
111 vector<complex<double> > operator + (vector<complex<double> >&,
112  vector<complex<double> >&);
113 vector<double> projection(vector<double> v, vector< vector<double> > space);
114 vector<vector<double> > matrix_fracture(vector<vector<double> >, int);
115 vector<vector<double> > rank_reduce(vector<bool> dof, vector<vector<double> >);
116 vector<double> rank_reduce(vector<bool> dof, vector<double>);
117 vector<int> rank_reduce(vector<bool> dof, vector<int>);
118 vector<vector<double> > matrix_fracture(vector<vector<double> >,int);
119 vector<double> expand(vector<bool> dof, vector<double>);
120 double ran01();
121 double rnd_gaussian(double sd=1);
122 vector<double> mean_and_sigma(vector<double> v);
123 vector<double> reject_outliers(vector<double>);
124 vector<int> histogram(vector<double>,double bin_size=1.0);
125 vector<int> sort(vector<int>);
126 vector<double> sort(vector<double>);
127 vector<int> ranks(vector<double>);
128 double max(vector<double> v);
129 double min(vector<double> v);
130 int max(vector<int> v);
131 int min(vector<int> v);
132 vector<int> reorder(vector<int>);
133 vector<vector<double> > permute(vector<vector<double> >, vector<int>);
134 vector<double> permute(vector<double>, vector<int>);
135 
136 class LU {
137  vector<vector<double> > mat_;
138  vector<int> indx_;
139  int d_;
140 public:
141  LU(vector<vector<double> >);
142  vector<vector<double> > mat();
143  vector<int> indx();
144  int d();
145 };
146 
147 
148 vector<double> lubksb(LU,vector<double>);
149 vector<double> linefit(vector<double>,vector<double>);
150 vector<double> linefit_or(vector<double>,vector<double>); // outlier rejection
151 vector< vector<double> > axisfit( vector< vector<double> > p );
152 double angle(double,double);
153 double angle(vector<double>);
154 
155 vector<complex<double> > fourier(vector<double> &v, int n, vector<double> &s,
156  vector<double> &c);
157 vector<complex<double> > fourier2(vector<double> *v, int n, vector<double> *s,
158  vector<double> *c,vector<int> q);
159 double fourier_sum(vector<complex<double> > f, double x);
160 vector<double> parabola_fit (vector<double> x,vector<double> y);
161 vector<double> gaussian_fit (vector<double> x,vector<double> y);
162 vector<double> gaussian_fit (vector<vector<double> > v);
163 int argmax (vector<double>);
164 
165 vector<double> splined(vector<double> &);
166 double spline(vector<double> &f, vector<double> &d2f, double x);
167 vector<vector<double> > spline_dy2(vector<vector<double> > &);
168 double spline2 (vector<vector<double> > &f, vector<vector<double> > &d2f_dx2,
169  double x, double y);
170 vector<double> dspline(vector<double> &, vector<double> &, double);
171 vector<double> dspline2(vector<vector<double> > &f, vector<vector<double> > &ft,
172  vector<vector<double> > &dx2, vector<vector<double> > &dy2,
173  double, double);
174 vector<double> circle_fit(vector<vector<double> > &, vector<double>);
175 vector<double> circle_fit_or(vector<vector<double> > &, vector<double>);
176 vector<vector<double> > orthogonal_basis(vector<vector<double> >);
177 double binomial (int n, int k, double p);
178 void concatenate(vector<vector<int> > &a, vector<vector<int> > &b);
179 void concatenate(vector<int> &a, vector<int> &b);
180 void concatenate_all(int a, vector<vector<int> > &b);
181 vector<vector<int> > partition(int balls, int urns, int min, int max);
182 vector<vector<int> > partition2(int balls, int urns, int min, int max);
183 #endif