93 if (multivariate==
true)
diagonal=
false;
94 if (multivariate==
false)
diagonal=
true;
97 if(type==
"GAUSSIAN" || type==
"gaussian"){
99 }
else if(type==
"UNIFORM" || type==
"uniform"){
101 }
else if(type==
"TRIANGULAR" || type==
"triangular"){
104 plumed_merror(type+
" is an invalid kernel type\n");
112 det=1;
for(
unsigned i=0;i<
width.size();++i) det*=
width[i];
115 Invert(mymatrix,myinv);
double logd;
121 for(
unsigned i=0;i<
width.size();++i) det*=
width[i];
122 volume=pow( 2*
pi, 0.5*ncv ) * pow( det, 0.5 );
126 for(
unsigned i=1;i<ncv;i+=2) dfact*=static_cast<double>(i);
127 volume=( pow(
pi, (ncv-1)/2 ) ) * ( pow( 2., (ncv+1)/2 ) ) / dfact;
130 for(
unsigned i=1;i<ncv/2;++i) fact*=static_cast<double>(i);
131 volume=pow(
pi,ncv/2 ) / fact;
136 plumed_merror(
"not a valid kernel type");
149 else plumed_merror(
"No valid kernel type");
155 std::vector<double> support( ncv );
161 Matrix<double> myautovec(ncv,ncv); std::vector<double> myautoval(ncv);
162 diagMat(myinv,myautoval,myautovec);
163 double maxautoval;maxautoval=0.;
164 unsigned ind_maxautoval;
165 for (
unsigned i=0;i<ncv;i++){
166 if(myautoval[i]>maxautoval){maxautoval=myautoval[i];ind_maxautoval=i;}
168 for(
unsigned i=0;i<ncv;++i){
169 double extent=fabs(sqrt(maxautoval)*myautovec(i,ind_maxautoval));
177 plumed_assert(
ndim()==dx.size() );
178 std::vector<unsigned> support( dx.size() );
180 for(
unsigned i=0;i<dx.size();++i) support[i]=static_cast<unsigned>(ceil( vv[i]/dx[i] ));
185 plumed_dbg_assert( pos.size()==
ndim() && derivatives.size()==
ndim() );
187 if( usederiv ) plumed_massert(
ktype!=
uniform,
"step function can not be differentiated" );
192 for(
unsigned i=0;i<
ndim();++i){
193 derivatives[i]=-pos[i]->difference(
center[i] ) /
width[i];
194 r2+=derivatives[i]*derivatives[i];
195 derivatives[i] /=
width[i];
199 for(
unsigned i=0;i<mymatrix.
nrows();++i){
200 double dp_i, dp_j; derivatives[i]=0;
201 dp_i=pos[i]->difference(
center[i] );
202 for(
unsigned j=0;j<mymatrix.
ncols();++j){
204 else dp_j=pos[j]->difference(
center[j] );
206 derivatives[i]+=mymatrix(i,j)*dp_j;
207 r2+=dp_i*dp_j*mymatrix(i,j);
213 kval=
height*std::exp(-0.5*r2); kderiv=-kval;
219 kderiv=-1; kval=
height*( 1. - fabs(r) );
228 plumed_merror(
"Not a valid kernel type");
232 for(
unsigned i=0;i<
ndim();++i) derivatives[i]*=kderiv;
237 std::string sss; ifile->
scanField(
"multivariate",sss);
238 std::vector<double> cc( valnames.size() ), sig;
242 sig.resize( valnames.size() );
243 for(
unsigned i=0;i<valnames.size();++i){
245 ifile->
scanField(
"sigma_"+valnames[i],sig[i]);
247 }
else if( sss==
"true" ){
249 unsigned ncv=valnames.size();
250 sig.resize( (ncv*(ncv+1))/2 );
252 for(
unsigned i=0;i<ncv;++i){
254 for(
unsigned j=0;j<ncv-i;j++){ ifile->
scanField(
"sigma_" +valnames[j+i] +
"_" + valnames[j], lower(j+i,j) ); upper(j,j+i)=lower(j+i,j); }
257 mult(lower,upper,mymult);
Invert( mymult, invmatrix );
259 for(
unsigned i=0;i<ncv;i++){
260 for(
unsigned j=i;j<ncv;j++){ sig[k]=invmatrix(i,j); k++; }
263 plumed_merror(
"multivariate flag should equal true or false");
266 return new KernelFunctions( cc, sig,
"gaussian", multivariate ,h,
false);
std::vector< unsigned > getSupport(const std::vector< double > &dx) const
Get the support.
static KernelFunctions * read(IFile *ifile, const std::vector< std::string > &valnames)
Read a kernel function from a file.
int Invert(const Matrix< T > &A, Matrix< double > &inverse)
double evaluate(const std::vector< Value * > &pos, std::vector< double > &derivatives, bool usederiv=true) const
Evaluate the kernel function.
double height
The height of the kernel.
Matrix< double > getMatrix() const
Convert the width into matrix form.
unsigned ncols() const
Return the number of columns.
double getCutoff(const double &width) const
Get the cutoff for a kernel.
std::vector< double > getContinuousSupport() const
get it in continuous form
unsigned ndim() const
Get the dimensionality of the kernel.
std::vector< double > center
The center of the kernel function.
void mult(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
enum PLMD::KernelFunctions::@4 ktype
What type of kernel are we using.
unsigned nrows() const
Return the number of rows.
std::vector< double > width
The width of the kernel.
bool diagonal
Is the metric matrix diagonal.
int logdet(const Matrix< T > &M, double &ldet)
int diagMat(const Matrix< T > &A, std::vector< double > &eigenvals, Matrix< double > &eigenvecs)
const double pi(3.141592653589793238462643383279502884197169399375105820974944592307)
PI.
IFile & scanField(const std::string &, double &)
Read a double field.
KernelFunctions(const std::vector< double > &at, const std::vector< double > &sig, const std::string &type, const bool multivariate, const double &w, const bool norm)
T norm(const std::vector< T > &A)
Calculate the dot product between a vector and itself.