summaryrefslogtreecommitdiff
path: root/tools/dataProvider.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/dataProvider.h')
-rw-r--r--tools/dataProvider.h73
1 files changed, 56 insertions, 17 deletions
diff --git a/tools/dataProvider.h b/tools/dataProvider.h
index 348d15c..4dc9c41 100644
--- a/tools/dataProvider.h
+++ b/tools/dataProvider.h
@@ -4,6 +4,7 @@
#include<Eigen/Dense>
#include "../tools/easylogging++.h"
#include<vector>
+#include<math.h>
// TODO decide how to construct training data
// One possible way for training data:
@@ -93,8 +94,8 @@ public:
}
inline std::string getQid(int x)
{
- int a,b,n=getqSize();
- a=x/n;
+ int a,b,q=getqSize();
+ a=x/q;
return getU(a)->qid;
}
inline int getqSize()
@@ -112,25 +113,63 @@ public:
return getuSize()*getqSize();
}
inline Eigen::VectorXd getVec(int x){
- int a,b,n=getqSize();
- a=x/n;
- b=x%n;
- Eigen::VectorXd vec;
+ int a,b,q=getqSize();
+ a=x/q;
+ b=x%q;
+ Eigen::VectorXd *id,*oth;
+ id = &(uniq[a]->feature);
if (single)
- return (uniq[a]->feature-other[b]->feature).cwiseAbs();
- if (b<a)
- vec=uniq[a]->feature-uniq[b]->feature;
+ oth = &(other[b]->feature);
+ else if (b<a)
+ oth = &(uniq[b]->feature);
+ else if (b<uniq.size()-1)
+ oth = &(uniq[b+1]->feature);
else
- if (b<uniq.size()-1)
- vec=uniq[a]->feature-uniq[b+1]->feature;
- else
- vec=uniq[a]->feature-other[b-uniq.size()+1]->feature;
- return vec.cwiseAbs();
+ oth = &(other[b-uniq.size()+1]->feature);
+ return (*id-*oth).cwiseAbs();
};
+ inline double getVecDot(int x,const Eigen::VectorXd &w)
+ {
+ int a,b,q=getqSize();
+ a=x/q;
+ b=x%q;
+ double res = 0;
+ Eigen::VectorXd *id,*oth;
+ id = &(uniq[a]->feature);
+ if (single)
+ oth = &(other[b]->feature);
+ else if (b<a)
+ oth = &(uniq[b]->feature);
+ else if (b<uniq.size()-1)
+ oth = &(uniq[b+1]->feature);
+ else
+ oth = &(other[b-uniq.size()+1]->feature);
+ for (int i=0;i<n;++i)
+ res += fabs((*id)[i] - (*oth)[i])*w[i];
+ return res;
+ }
+ inline void addVecw(int x,double w,Eigen::VectorXd &X)
+ {
+ int a,b,q=getqSize();
+ a=x/q;
+ b=x%q;
+ Eigen::VectorXd *id,*oth;
+ id = &(uniq[a]->feature);
+ if (single)
+ oth = &(other[b]->feature);
+ else if (b<a)
+ oth = &(uniq[b]->feature);
+ else if (b<uniq.size()-1)
+ oth = &(uniq[b+1]->feature);
+ else
+ oth = &(other[b-uniq.size()+1]->feature);
+ for (int i=0;i<n;++i)
+ X[i] += fabs((*id)[i] - (*oth)[i])*w;
+ }
inline double getL(int x){
- int a,b,n=getqSize();
- a=x/n;
- b=x%n;
+ int a,b,q=getqSize();
+ a=x/q;
+ b=x%q;
if (single)
{
if (std::fabs(other[b]->rank - a) < 1e-5)