Esempio n. 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));
  }
Esempio n. 2
0
  @Override
  public void run() {
    List<SocialVertex> egos = stateService.get();
    /*
     * get new and old plans
     */
    List<Plan> newState = new ArrayList<Plan>(egos.size());
    List<Plan> oldState = new ArrayList<Plan>(egos.size());

    for (SocialVertex ego : egos) {
      Person person = ego.getPerson().getPerson();
      if (person.getPlans().get(0).isSelected()) {
        newState.add(person.getPlans().get(0));
        oldState.add(person.getPlans().get(1));
      } else {
        newState.add(person.getPlans().get(1));
        oldState.add(person.getPlans().get(0));
      }
    }
    /*
     * get scores
     */
    double newScore = 0;
    for (int i = 0; i < newState.size(); i++) newScore += newState.get(i).getScore();

    double oldScore = 0;
    for (int i = 0; i < oldState.size(); i++) oldScore += oldState.get(i).getScore();
    /*
     * calculate transition probability
     */
    double delta = oldScore - newScore;
    double pi = 1 / (1 + Math.exp(delta));

    //		piSum += pi;
    /*
     * accept/reject
     */
    List<Plan> remove = null;
    if (random.nextDouble() < pi) {
      /*
       * accept state
       */
      remove = oldState;
      //			acceptedStates++;
      accept = true;
    } else {
      /*
       * reject state
       */
      remove = newState;
      accept = false;
    }
    /*
     * remove plans
     */
    for (int i = 0; i < remove.size(); i++) {
      Plan plan = remove.get(i);
      Person person = plan.getPerson();
      person.getPlans().remove(plan);
      person.setSelectedPlan(person.getPlans().get(0));
    }
  }