private void analyzeIntern(
      Set<Trajectory> trajectories, String purpose, TObjectDoubleHashMap<Trajectory> distancesMap) {
    TDoubleArrayList arrivals = new TDoubleArrayList(trajectories.size());
    TDoubleArrayList distances = new TDoubleArrayList(trajectories.size());

    for (Trajectory t : trajectories) {
      for (int i = 0; i < t.getElements().size(); i += 2) {
        if (purpose == null || ((Activity) t.getElements().get(i)).getType().equals(purpose)) {
          double start = t.getTransitions().get(i);
          arrivals.add(start);
          distances.add(distancesMap.get(t));
        }
      }
    }

    TDoubleDoubleHashMap map =
        Correlations.mean(arrivals.toNativeArray(), distances.toNativeArray(), 3600);
    //		Discretizer d = FixedSampleSizeDiscretizer.create(arrivals.toNativeArray(), 100, 100);
    //		TDoubleDoubleHashMap map = Correlations.mean(arrivals.toNativeArray(),
    // distances.toNativeArray(), d);
    try {
      if (purpose == null)
        StatsWriter.writeHistogram(
            map, "arr", "dist", String.format("%1$s/dist_arr.txt", getOutputDirectory()));
      else
        StatsWriter.writeHistogram(
            map,
            "arr",
            "dist",
            String.format("%1$s/dist_arr.%2$s.txt", getOutputDirectory(), purpose));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
示例#2
0
  public static Set<? extends Person> weightedCopy(
      Collection<? extends Person> persons, Factory factory, int N, Random random) {
    if (persons.size() == N) {
      return new HashSet<>(persons); // TODO weights are left untouched
    } else if (persons.size() > N) {
      throw new IllegalArgumentException("Cannot shrink population.");
    }

    List<Person> templates = new ArrayList<>(persons);
    /*
     * get max weight
     */
    TObjectDoubleHashMap<Person> weights = new TObjectDoubleHashMap<>(persons.size());
    double maxW = 0;
    for (Person person : persons) {
      String wStr = person.getAttribute(CommonKeys.PERSON_WEIGHT);
      double w = 0;
      if (wStr != null) {
        w = Double.parseDouble(wStr);
      }
      weights.put(person, w);
      maxW = Math.max(w, maxW);
    }
    /*
     * adjust weight so that max weight equals probability 1
     */
    ProgressLogger.init(N, 2, 10);
    Set<Person> clones = new HashSet<>();
    while (clones.size() < N) {
      Person template = templates.get(random.nextInt(templates.size()));
      double w = weights.get(template);
      double p = w / maxW;
      if (p > random.nextDouble()) {
        StringBuilder builder = new StringBuilder();
        builder.append(template.getId());
        builder.append("clone");
        builder.append(clones.size());

        Person clone = PersonUtils.deepCopy(template, builder.toString(), factory);
        clone.setAttribute(CommonKeys.PERSON_WEIGHT, "1.0");
        clones.add(clone);
        ProgressLogger.step();
      }
    }

    return clones;
  }
示例#3
0
  @SuppressWarnings("unchecked")
  protected double getValue(Object object) {
    double r = values.get(object);

    return r;
  }
 @Override
 public String getVertexFillColor(V ego) {
   double c = clustering.get(ego);
   double color = (c - c_min) / (c_max - c_min);
   return getColor(color);
 }