コード例 #1
0
  public PopulateVirtualWorld(String prefix) {
    distribution = Configuration.getInt(prefix + "." + PAR_DISTRIB);
    applicativeLayerId = Configuration.getPid(prefix + "." + APPLICATIVE_LAYER);
    Globals.mapSize = Configuration.getLong(prefix + "." + MAP_SIZE);
    Globals.zoneSize = Configuration.getLong(prefix + "." + ZONE_SIZE);
    Globals.zoneNb = Configuration.getInt(prefix + "." + ZONE_NB);
    Globals.outOfZoneNb = Configuration.getInt(prefix + "." + OUT_OF_ZONE_NB);
    Globals.wSpeed = Configuration.getInt(prefix + "." + WSPEED);
    Globals.tSpeed = Configuration.getInt(prefix + "." + TSPEED);
    Globals.smallZoneSize = Configuration.getInt(prefix + "." + SMALL_ZONE_SIZE);
    Globals.smallZoneNb = Configuration.getInt(prefix + "." + SMALL_ZONE_NB);

    Globals.haltedToHalted = Configuration.getInt(prefix + "." + HTH);
    Globals.haltedToTravelling = Configuration.getInt(prefix + "." + HTT);
    Globals.haltedToWandering = Configuration.getInt(prefix + "." + HTW);

    Globals.travellingToTravelling = Configuration.getInt(prefix + "." + TTT);
    Globals.travellingToHalted = Configuration.getInt(prefix + "." + TTH);
    Globals.travellingToWandering = Configuration.getInt(prefix + "." + TTW);

    Globals.wanderingToWandering = Configuration.getInt(prefix + "." + WTW);
    Globals.wanderingToTravelling = Configuration.getInt(prefix + "." + WTT);
    Globals.wanderingToHalted = Configuration.getInt(prefix + "." + WTH);
    Globals.changeWanderingDirection = Configuration.getInt(prefix + "." + CWD);

    Globals.quiet = Configuration.getBoolean(prefix + "." + QUIET);
  }
コード例 #2
0
  public static void main(String[] args) throws Exception {
    String configName = args[0];
    Configuration.setConfig(new ParsedProperties(configName));
    // System.err.println("#Reading datasets from files");
    File tFile = new File(Configuration.getString("trainingFile"));
    File eFile = new File(Configuration.getString("evaluationFile"));
    String dbReaderName = "gossipLearning.RecSysDataBaseReader";

    seed = Configuration.getInt("SEED");
    numOfClusters = Configuration.getInt("numOfClusters");
    divErr = Configuration.getDouble("divErr");
    numberOfRatings = Configuration.getDouble("numOfRatings");
    numberOfAllUsers = Configuration.getDouble("numOfAllUsers");

    classifierName = Configuration.getString("classifier", null);

    prefix = "model";
    modelName = Configuration.getString(prefix, null);

    boolean isNormalize = Configuration.getBoolean("normalize");
    int polyDegree = Configuration.getInt("polyDegree");

    DataBaseReader dbReader = DataBaseReader.createDataBaseReader(dbReaderName, tFile, eFile);

    // System.err.println("#Preprocessing datasets");
    // pre-processing database
    getNumberOfUsers = new double[dbReader.getTrainingSet().getNumberOfFeatures()];
    getAverageRating = new double[dbReader.getTrainingSet().getNumberOfFeatures()];
    getNumberOfLikeableUsers = new double[dbReader.getTrainingSet().getNumberOfFeatures()];
    for (int i = 0; i < dbReader.getTrainingSet().size(); i++) {
      for (VectorEntry e : dbReader.getTrainingSet().getInstance(i)) {
        getNumberOfUsers[e.index]++;
        getAverageRating[e.index] += e.value;
      }
    }
    for (int i = 0; i < dbReader.getTrainingSet().getNumberOfFeatures(); i++) {
      getAverageRating[i] =
          getNumberOfUsers[i] == 0.0 ? 0.0 : getAverageRating[i] / getNumberOfUsers[i];
    }

    for (int i = 0; i < dbReader.getTrainingSet().size(); i++) {
      for (VectorEntry e : dbReader.getTrainingSet().getInstance(i)) {
        if (e.value > getAverageRating[e.index]) {
          getNumberOfLikeableUsers[e.index]++;
        }
      }
    }

    // System.err.println("#Extracting features");
    // feature extraction
    InstanceHolder trainingSet = new InstanceHolder((int) numberOfRatings, 11);
    for (int userID = 0; userID < dbReader.getTrainingSet().size(); userID++) {
      for (VectorEntry e : dbReader.getTrainingSet().getInstance(userID)) {
        int itemID = e.index;
        double label = e.value;
        double[] features = new double[11];
        computeUserSpecificFeatureVectorPart(
            dbReader.getTrainingSet().getInstance(userID), features);
        computeItemSpecificFinalFeatureVector(itemID, features);
        SparseVector instance = new SparseVector(features);
        trainingSet.add(instance, label);
      }
    }
    InstanceHolder testSet = new InstanceHolder((int) numberOfRatings, 11);
    for (int userID = 0; userID < dbReader.getEvalSet().size(); userID++) {
      for (VectorEntry e : dbReader.getEvalSet().getInstance(userID)) {
        int itemID = e.index;
        double label = e.value;
        double[] features = new double[11];
        computeUserSpecificFeatureVectorPart(
            dbReader.getTrainingSet().getInstance(userID), features);
        computeItemSpecificFinalFeatureVector(itemID, features);
        SparseVector instance = new SparseVector(features);
        testSet.add(instance, label);
      }
    }

    File tout = new File("tr.dat");
    File eout = new File("ev.dat");

    trainingSet.writeToFile(tout);
    testSet.writeToFile(eout);

    DataBaseReader dbr =
        DataBaseReader.createDataBaseReader("gossipLearning.DataBaseReader", tout, eout);

    if (polyDegree > 1) {
      // dbr.polynomize(polyDegree);
      // dbr.writeToFile(new File("bookcrossing_fn_" + polyDegree + ".train"), new
      // File("bookcrossing_fn_" + polyDegree + ".test"));
      // System.exit(0);
    }

    if (isNormalize) {
      dbr.standardize();
    }

    if (classifierName != null) {
      weka(dbr.getTrainingSet(), dbr.getEvalSet());
      // weka(trainingSet, testSet);
    }

    if (modelName != null) {
      golf(dbr.getTrainingSet(), dbr.getEvalSet());
      // golf(trainingSet, testSet);
    }

    tout.deleteOnExit();
    eout.deleteOnExit();
  }