@Override
  public void analyze(Graph g, Map<String, DescriptiveStatistics> statsMap) {
    int sumMale = 0;
    int cntMale = 0;
    int sumFemale = 0;
    int cntFemale = 0;

    TObjectDoubleHashMap<Vertex> values = module.values(g.getVertices());
    TObjectDoubleIterator<Vertex> it = values.iterator();
    for (int i = 0; i < values.size(); i++) {
      it.advance();
      SocialVertex v = (SocialVertex) it.key();
      double k = it.value();

      if (v.getPerson().getPerson().getSex() != null) {
        if (v.getPerson().getPerson().getSex().equalsIgnoreCase("m")) {
          sumMale += k;
          cntMale++;
        } else if (v.getPerson().getPerson().getSex().equalsIgnoreCase("f")) {
          sumFemale += k;
          cntFemale++;
        }
      }
    }

    double k_mean_male = sumMale / (double) cntMale;
    double k_mean_female = sumFemale / (double) cntFemale;

    logger.info(
        String.format("k_mean_male = %1$s, k_mean_female = %2$s.", k_mean_male, k_mean_female));
  }
Exemple #2
0
  public MyColorizer(TObjectDoubleHashMap<?> values) {
    this.values = values;

    max = -Double.MAX_VALUE;
    min = Double.MAX_VALUE;

    TObjectDoubleIterator<?> it = values.iterator();
    for (int i = 0; i < values.size(); i++) {
      it.advance();
      max = Math.max(max, it.value());
      min = Math.min(min, it.value());
    }
  }
  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();
    }
  }
 @SuppressWarnings("unchecked")
 public PajekClusteringColorizer(Graph g) {
   super();
   clustering = Transitivity.getInstance().localClusteringCoefficients((Set<V>) g.getVertices());
   c_min = StatUtils.min(clustering.getValues());
   c_max = StatUtils.max(clustering.getValues());
 }
Exemple #5
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;
  }
  public void test() {
    SparseGraphBuilder builder = new SparseGraphBuilder();
    SparseGraph graph = builder.createGraph();

    SparseVertex v1 = builder.addVertex(graph);
    SparseVertex v2 = builder.addVertex(graph);
    SparseVertex v3 = builder.addVertex(graph);
    SparseVertex v4 = builder.addVertex(graph);
    SparseVertex v5 = builder.addVertex(graph);
    SparseVertex v6 = builder.addVertex(graph);

    builder.addEdge(graph, v1, v2);
    builder.addEdge(graph, v2, v3);
    builder.addEdge(graph, v3, v4);
    builder.addEdge(graph, v4, v5);
    builder.addEdge(graph, v5, v6);
    builder.addEdge(graph, v6, v1);
    builder.addEdge(graph, v2, v5);

    Degree degree = Degree.getInstance();

    DescriptiveStatistics stats = degree.statistics(graph.getVertices());
    assertEquals(2.33, stats.getMean(), 0.01);
    assertEquals(2.0, stats.getMin());
    assertEquals(3.0, stats.getMax());

    TObjectDoubleHashMap<? extends Vertex> values = degree.values(graph.getVertices());
    TObjectDoubleIterator<? extends Vertex> it = values.iterator();

    int count2 = 0;
    int count3 = 0;
    for (int i = 0; i < values.size(); i++) {
      it.advance();
      if (it.value() == 2) count2++;
      else if (it.value() == 3) count3++;
    }

    assertEquals(4, count2);
    assertEquals(2, count3);

    assertEquals(-0.166, degree.assortativity(graph), 0.001);
  }
 private static TObjectDoubleHashMap<String> parseParamFile(String paramsFile) {
   TObjectDoubleHashMap<String> startParamList = new TObjectDoubleHashMap<String>();
   try {
     BufferedReader fis = new BufferedReader(new FileReader(paramsFile));
     String pattern = null;
     int count = 0;
     while ((pattern = fis.readLine()) != null) {
       StringTokenizer st = new StringTokenizer(pattern.trim(), "\t");
       String paramName = st.nextToken().trim();
       String rest = st.nextToken().trim();
       String[] arr = rest.split(",");
       double value = new Double(arr[0].trim());
       boolean sign = new Boolean(arr[1].trim());
       LDouble val = new LDouble(value, sign);
       startParamList.put(paramName, val.exponentiate());
       if (count % 100000 == 0) System.out.println("Processed param number:" + count);
       count++;
     }
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
   return startParamList;
 }
 public FastFrameIdentifier(
     TObjectDoubleHashMap<String> paramList,
     String reg,
     double l,
     THashMap<String, THashSet<String>> frameMap,
     THashMap<String, THashSet<String>> wnRelationCache,
     THashMap<String, THashSet<String>> hvCorrespondenceMap,
     Map<String, Set<String>> relatedWordsForWord,
     Map<String, Map<String, Set<String>>> revisedRelationsMap,
     Map<String, String> hvLemmas) {
   super(paramList, reg, l, null, frameMap);
   initializeParameterIndexes();
   this.mParamList = paramList;
   mReg = reg;
   mLambda = l;
   mFrameMap = frameMap;
   totalNumberOfParams = paramList.size();
   initializeParameters();
   mLookupChart = new TIntObjectHashMap<LogFormula>();
   mHvCorrespondenceMap = hvCorrespondenceMap;
   mRelatedWordsForWord = relatedWordsForWord;
   mRevisedRelationsMap = revisedRelationsMap;
   mHVLemmas = hvLemmas;
 }
Exemple #9
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);
 }