ColumnVector find_top_n(ColumnVector W, int n, double cindex){ ColumnVector out(n); int count=0; double max=0.0; out(0)=cindex; for(int i=0;i<W.rows();i++){ if(W(i)!=0.0) count +=1; if(W(i)<0.0) W(i)=(-1)*W(i); } out(1)=count; int k=2; while(k<n){ out(k)=0; max=W(0); for(int i=1;i<W.rows();i++){ if(W(i)>max){ max=W(i); out(k)=i; } } W(out(k))=0.0; k +=1; } return out; }
Uniform::Uniform (const ColumnVector& center, const ColumnVector& width) : Pdf<ColumnVector> ( center.rows() ) , _samples(DimensionGet()) { // check if inputs are consistent assert (center.rows() == width.rows()); _Lower = center - width/2.0; _Higher = center + width/2.0; _Height = 1; for (int i=1 ; i < width.rows()+1 ; i++ ) { _Height = _Height / width(i); } }
void Uniform::UniformSet (const ColumnVector& center,const ColumnVector& width) { assert(center.rows() == width.rows()); _Lower = center - width/2.0; _Higher = center + width/2.0; _Height = 1; for (int i=1 ; i < width.rows()+1 ; i++ ) { _Height = _Height / width(i); } if (this->DimensionGet() == 0) this->DimensionSet(center.rows()); assert(this->DimensionGet() == center.rows()); }
Probability Uniform::ProbabilityGet(const ColumnVector& input) const { // test if input is located in area of Uniform distribution for (int i=1; i<input.rows()+1; i++) { if ( ( input(i)>_Higher(i) ) || ( input(i) < _Lower(i) ) ) return 0; } return _Height; }
double pall_dot(RowVector feature, ColumnVector beta){ double sum=0.0; int nf=beta.rows(); omp_set_num_threads(36); #pragma omp parallel { #pragma omp for reduction(+:sum) for(int i=0;i<nf;i++) sum +=feature[i]*beta[i]; } return sum; }