本文整理汇总了Java中librec.intf.Recommender类的典型用法代码示例。如果您正苦于以下问题:Java Recommender类的具体用法?Java Recommender怎么用?Java Recommender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Recommender类属于librec.intf包,在下文中一共展示了Recommender类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRecommender
import librec.intf.Recommender; //导入依赖的package包/类
/**
* @return a recommender to be run
*/
protected Recommender getRecommender(SparseMatrix[] data, int fold) throws Exception {
algorithm = cf.getString("recommender");
SparseMatrix trainMatrix = data[0], testMatrix = data[1];
// output data
writeData(trainMatrix, testMatrix, fold);
switch (algorithm.toLowerCase()) {
/* baselines */
case "wrmf":
return new WRMF(trainMatrix, testMatrix, fold);
default:
throw new Exception("No recommender is specified!");
}
}
示例2: getMKey
import librec.intf.Recommender; //导入依赖的package包/类
/**
* get the current value for key which supports multiple runs
*
* @param params
* parameter-values map
* @param key
* parameter key
* @return current value for a parameter
*/
public static float getMKey(Map<String, List<Float>> params, String key) {
float alpha = 0;
if (params != null && params.containsKey(key)) {
List<Float> vals = params.get(key);
int maxIdx = vals.size() - 1;
int idx = LibRec.paramIdx > maxIdx ? maxIdx : LibRec.paramIdx;
alpha = vals.get(idx);
LibRec.isMultRun = true;
} else {
alpha = Recommender.cf.getFloat(key);
// LibRec.isMultRun = false;
}
return alpha;
}
示例3: readData
import librec.intf.Recommender; //导入依赖的package包/类
/**
* read input data
*/
protected void readData() throws Exception {
// DAO object
rateDao = new DataDAO(cf.getPath("dataset.ratings"));
// data configuration
ratingOptions = cf.getParamOptions("ratings.setup");
// data columns to use
List<String> cols = ratingOptions.getOptions("-columns");
columns = new int[cols.size()];
for (int i = 0; i < cols.size(); i++)
columns[i] = Integer.parseInt(cols.get(i));
// is first line: headline
rateDao.setHeadline(ratingOptions.contains("-headline"));
// rating threshold
binThold = ratingOptions.getFloat("-threshold");
// time unit of ratings' timestamps
timeUnit = TimeUnit.valueOf(ratingOptions.getString("--time-unit", "seconds").toUpperCase());
rateDao.setTimeUnit(timeUnit);
SparseMatrix[] data = ratingOptions.contains("--as-tensor") ? rateDao.readTensor(columns, binThold) : rateDao
.readData(columns, binThold);
rateMatrix = data[0];
timeMatrix = data[1];
Recommender.rateMatrix = rateMatrix;
Recommender.timeMatrix = timeMatrix;
Recommender.rateDao = rateDao;
Recommender.binThold = binThold;
}
示例4: preset
import librec.intf.Recommender; //导入依赖的package包/类
/**
* reset general (and static) settings
*/
protected void preset(String configFile) throws Exception {
// a new configer
cf = new FileConfiger(configFile);
// seeding the general recommender
Recommender.cf = cf;
// reset recommenders' static properties
Recommender.resetStatics = true;
IterativeRecommender.resetStatics = true;
GraphicRecommender.resetStatics = true;
// LibRec outputs
outputOptions = cf.getParamOptions("output.setup");
if (outputOptions != null) {
tempDirPath = outputOptions.getString("-dir", "./Results/");
}
// make output directory
Recommender.tempDirPath = FileIO.makeDirectory(tempDirPath);
// initialize random seed
LineConfiger evalOptions = cf.getParamOptions("evaluation.setup");
Randoms.seed(evalOptions.getLong("--rand-seed", System.currentTimeMillis())); // initial random seed
}
示例5: printEvalInfo
import librec.intf.Recommender; //导入依赖的package包/类
/**
* print out the evaluation information for a specific algorithm
*/
private void printEvalInfo(Recommender algo, Map<Measure, Double> ms) throws Exception {
String result = Recommender.getEvalInfo(ms);
// we add quota symbol to indicate the textual format of time
String time = String.format("'%s','%s'", Dates.parse(ms.get(Measure.TrainTime).longValue()),
Dates.parse(ms.get(Measure.TestTime).longValue()));
// double commas as the separation of results and configuration
StringBuilder sb = new StringBuilder();
String config = algo.toString();
sb.append(algo.algoName).append(",").append(result).append(",,");
if (!config.isEmpty())
sb.append(config).append(",");
sb.append(time).append("\n");
String evalInfo = sb.toString();
Logs.info(evalInfo);
// copy to clipboard for convenience, useful for a single run
if (outputOptions.contains("--to-clipboard")) {
Strings.toClipboard(evalInfo);
Logs.debug("Results have been copied to clipboard!");
}
// append to a specific file, useful for multiple runs
if (outputOptions.contains("--to-file")) {
String filePath = outputOptions.getString("--to-file", tempDirPath + algorithm + ".txt");
FileIO.writeString(filePath, evalInfo, true);
Logs.debug("Results have been collected to file: {}", filePath);
}
}
示例6: runRatio
import librec.intf.Recommender; //导入依赖的package包/类
/**
* Interface to run ratio-validation approach
*/
private static void runRatio() throws Exception {
DataSplitter ds = new DataSplitter(rateMatrix);
double ratio = cf.getDouble("val.ratio");
Recommender algo = getRecommender(ds.getRatio(ratio), -1);
algo.execute();
printEvalInfo(algo, algo.measures);
}
示例7: runGiven
import librec.intf.Recommender; //导入依赖的package包/类
/**
* Interface to run (Given N)-validation approach
*/
private static void runGiven() throws Exception {
DataSplitter ds = new DataSplitter(rateMatrix);
int n = cf.getInt("num.given.n");
double ratio = cf.getDouble("val.given.ratio");
Recommender algo = getRecommender(ds.getGiven(n > 0 ? n : ratio), -1);
algo.execute();
printEvalInfo(algo, algo.measures);
}
示例8: runTestFile
import librec.intf.Recommender; //导入依赖的package包/类
/**
* Interface to run testing using data from an input file
*
*/
private static void runTestFile(String path) throws Exception {
DataDAO testDao = new DataDAO(path, rateDao.getUserIds(), rateDao.getItemIds());
SparseMatrix testMatrix = testDao.readData(false);
Recommender algo = getRecommender(new SparseMatrix[] { rateMatrix, testMatrix }, -1);
algo.execute();
printEvalInfo(algo, algo.measures);
}
示例9: printEvalInfo
import librec.intf.Recommender; //导入依赖的package包/类
/**
* print out the evaluation information for a specific algorithm
*/
private static void printEvalInfo(Recommender algo, Map<Measure, Double> ms) {
String result = Recommender.getEvalInfo(ms);
String time = Dates.parse(ms.get(Measure.TrainTime).longValue()) + ","
+ Dates.parse(ms.get(Measure.TestTime).longValue());
String evalInfo = String.format("%s,%s,%s,%s", algo.algoName, result, algo.toString(), time);
Logs.info(evalInfo);
}
示例10: main
import librec.intf.Recommender; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Logs.debug(LibRec.readme());
// get configuration file
cf = new Configer("librec.conf");
// debug info
debugInfo();
// prepare data
rateDao = new DataDAO(cf.getPath("dataset.training"));
rateMatrix = rateDao.readData(cf.getDouble("val.binary.threshold"));
// config general recommender
Recommender.cf = cf;
Recommender.rateMatrix = rateMatrix;
Recommender.rateDao = rateDao;
// required: only one parameter varying for multiple run
Recommender.params = RecUtils.buildParams(cf);
// run algorithms
if (Recommender.params.size() > 0) {
// multiple run
for (Entry<String, List<Float>> en : Recommender.params.entrySet()) {
for (int i = 0, im = en.getValue().size(); i < im; i++) {
LibRec.paramIdx = i;
runAlgorithm();
// useful for some methods which do not use the parameters
// defined in Recommender.params
if (!isMultRun)
break;
}
}
} else {
// single run
runAlgorithm();
}
// collect results
String destPath = FileIO.makeDirectory("Results");
String dest = destPath + algorithm + "@" + Dates.now() + ".txt";
FileIO.copyFile("results.txt", dest);
notifyMe(dest);
}