@ SuppressWarnings ( "unchecked" ) public static void prepareStrategy ( final String splitPath , final String recPath , final String outPath ) { int i = 0 ; File trainingFile = new File ( splitPath + "train_" + i + ".csv" ) ; File testFile = new File ( splitPath + "test_" + i + ".csv" ) ; File recFile = new File ( recPath + "recs_" + i + ".csv" ) ; DataModelIF < Long , Long > trainingModel ; DataModelIF < Long , Long > testModel ; DataModelIF < Long , Long > recModel ; try { trainingModel = new SimpleParser ( ) . parseData ( trainingFile ) ; testModel = new SimpleParser ( ) . parseData ( testFile ) ; recModel = new SimpleParser ( ) . parseData ( recFile ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; return ; } Double threshold = REL_TH ; String strategyClassName = "net.recommenders.rival.evaluation.strategy.UserTest" ; EvaluationStrategy < Long , Long > strategy = null ; try { strategy = ( EvaluationStrategy < Long , Long > ) ( Class . forName ( strategyClassName ) ) . getConstructor ( DataModelIF . class , DataModelIF . class , double . class ) . newInstance ( trainingModel , testModel , threshold ) ; } catch ( InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException e ) { e . printStackTrace ( ) ; } DataModelIF < Long , Long > modelToEval = DataModelFactory . getDefaultModel ( ) ; for ( Long user : recModel . getUsers ( ) ) { assert strategy != null ; for ( Long item : strategy . getCandidateItemsToRank ( user ) ) { if ( ! Double . isNaN ( recModel . getUserItemPreference ( user , item ) ) ) { modelToEval . addPreference ( user , item , recModel . getUserItemPreference ( user , item ) ) ; } } } try { DataModelUtils . saveDataModel ( modelToEval , outPath + "strategymodel_" + i + ".csv" , true , "\t" ) ; } catch ( FileNotFoundException | UnsupportedEncodingException e ) { e . printStackTrace ( ) ; } }
Prepares the strategies to be evaluated with the recommenders already generated .