29 #ifndef gramSchmidt_hpp
30 #define gramSchmidt_hpp
51 template<
int progress=0,
typename eigenTout,
typename eigenTin>
54 out.resize(in.rows(), in.cols());
56 out.col(0) = in.col(0);
58 for(
int i=1;i< in.cols(); ++i)
62 std::cout << i+1 <<
"/" << in.cols() <<
"\n";
67 out.col(i) = in.col(i) - ((in.col(i).matrix().dot(out.col(0).matrix())) / (out.col(0).matrix().dot(out.col(0).matrix())) )* out.col(0);
71 out.col(i) = out.col(i) - ((out.col(i).matrix().dot(out.col(j).matrix()))/(out.col(j).matrix().dot(out.col(j).matrix())))* out.col(j);
75 for(
int i=0; i<out.cols(); ++i)
77 out.col(i) = out.col(i)/ out.col(i).matrix().norm();
97 template<
int progress=0,
typename eigenTout,
typename eigenTin,
typename eigenTWin>
98 void gramSchmidt(eigenTout & out,
const eigenTin & in,
const eigenTWin & window)
102 out.col(0) = in.col(0);
104 for(
int i=1;i< in.cols(); ++i)
108 std::cout << i+1 <<
"/" << in.cols() <<
"\n";
113 out.col(i) = in.col(i) - (((in.col(i)*window).matrix().dot(out.col(0).matrix())) / ( (out.col(0)*window).matrix().dot(out.col(0).matrix())) )* out.col(0);
115 for(
int j=1;j<i; ++j)
117 out.col(i) = out.col(i) - (( (out.col(i)*window).matrix().dot(out.col(j).matrix()))/((out.col(j)*window).matrix().dot(out.col(j).matrix())))* out.col(j);
121 for(
int i=0; i<out.cols(); ++i)
123 out.col(i) = out.col(i)/ (out.col(i)*window.sqrt()).matrix().norm();
131 template<
int progress=0,
typename eigenT>
132 void baseSpectrum(eigenT & bspect, eigenT & gsspect)
134 bspect.resize(gsspect.rows(), gsspect.cols());
138 for(
int i=0; i< gsspect.rows(); ++i)
140 bspect(i,i) = gsspect(i,i);
142 for(
int j=i-1; j >=0; --j)
144 bspect.row(i) -= gsspect(i,j)*bspect.row(j);
162 template<
int progress=0,
typename eigenTout,
typename eigenTout2,
typename eigenTin>
166 typename eigenTin::Scalar normPix = 1.0
169 typedef typename eigenTout::Scalar Scalar;
171 out.resize(in.rows(), in.cols());
175 gsspect.resize(in.cols(), in.cols());
178 out.col(0) = in.col(0);
181 for(
int i=1;i< in.cols(); ++i)
185 std::cout << i+1 <<
"/" << in.cols() <<
"\n";
190 gsspect(i,0) = ((in.col(i).matrix().dot(out.col(0).matrix())) / (out.col(0).matrix().dot(out.col(0).matrix())) );
191 out.col(i) = in.col(i) - gsspect(i,0) * out.col(0);
193 for(
int j=1;j<i; ++j)
195 gsspect(i,j) = ((out.col(i).matrix().dot(out.col(j).matrix()))/(out.col(j).matrix().dot(out.col(j).matrix())));
196 out.col(i) = out.col(i) - gsspect(i,j)* out.col(j);
201 baseSpectrum(spect, gsspect);
205 for(
int i=0; i<out.cols(); ++i)
207 norm = sqrt(out.col(i).square().sum() / normPix);
void gramSchmidt(eigenTout &out, const eigenTin &in, const eigenTWin &window)
Perform Gram-Schmidt ortogonalization of a basis set on a window, and normalize the result.
void gramSchmidtSpectrum(eigenTout &out, eigenTout2 &spect, const eigenTin &in, typename eigenTin::Scalar normPix=1.0)
Perform Gram-Schmidt ortogonalization of a basis set, and normalize the result, while recording the s...