コード例 #1
0
  @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));
  }
コード例 #2
0
ファイル: MyColorizer.java プロジェクト: spatialsmart/matsim
  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());
    }
  }
コード例 #3
0
  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);
  }