Java 类gnu.trove.map.TObjectDoubleMap 实例源码

项目:xcc    文件:TObjectDoubleCustomHashMap.java   
/**
   * Creates a new <code>TObjectDoubleCustomHashMap</code> that contains the entries
   * in the map passed to it.
   *
   * @param map the <tt>TObjectDoubleMap</tt> to be copied.
   */
  public TObjectDoubleCustomHashMap( HashingStrategy<? super K> strategy,
TObjectDoubleMap<? extends K> map ) {

      this( strategy, map.size(), 0.5f, map.getNoEntryValue() );

      if ( map instanceof TObjectDoubleCustomHashMap ) {
          TObjectDoubleCustomHashMap hashmap = ( TObjectDoubleCustomHashMap ) map;
          this._loadFactor = hashmap._loadFactor;
          this.no_entry_value = hashmap.no_entry_value;
          this.strategy = hashmap.strategy;
          //noinspection RedundantCast
          if ( this.no_entry_value != ( double ) 0 ) {
              Arrays.fill( _values, this.no_entry_value );
          }
          setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
      }
      putAll( map );
  }
项目:HCFCore    文件:TObjectDoubleCustomHashMap.java   
/**
   * Creates a new <code>TObjectDoubleCustomHashMap</code> that contains the entries
   * in the map passed to it.
   *
   * @param map the <tt>TObjectDoubleMap</tt> to be copied.
   */
  public TObjectDoubleCustomHashMap( HashingStrategy<? super K> strategy,
TObjectDoubleMap<? extends K> map ) {

      this( strategy, map.size(), 0.5f, map.getNoEntryValue() );

      if ( map instanceof TObjectDoubleCustomHashMap ) {
          TObjectDoubleCustomHashMap hashmap = ( TObjectDoubleCustomHashMap ) map;
          this._loadFactor = hashmap._loadFactor;
          this.no_entry_value = hashmap.no_entry_value;
          this.strategy = hashmap.strategy;
          //noinspection RedundantCast
          if ( this.no_entry_value != ( double ) 0 ) {
              Arrays.fill( _values, this.no_entry_value );
          }
          setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
      }
      putAll( map );
  }
项目:HCFCore    文件:TObjectDoubleCustomHashMap.java   
/**
   * Creates a new <code>TObjectDoubleCustomHashMap</code> that contains the entries
   * in the map passed to it.
   *
   * @param map the <tt>TObjectDoubleMap</tt> to be copied.
   */
  public TObjectDoubleCustomHashMap( HashingStrategy<? super K> strategy,
TObjectDoubleMap<? extends K> map ) {

      this( strategy, map.size(), 0.5f, map.getNoEntryValue() );

      if ( map instanceof TObjectDoubleCustomHashMap ) {
          TObjectDoubleCustomHashMap hashmap = ( TObjectDoubleCustomHashMap ) map;
          this._loadFactor = hashmap._loadFactor;
          this.no_entry_value = hashmap.no_entry_value;
          this.strategy = hashmap.strategy;
          //noinspection RedundantCast
          if ( this.no_entry_value != ( double ) 0 ) {
              Arrays.fill( _values, this.no_entry_value );
          }
          setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
      }
      putAll( map );
  }
项目:trove-3.0.3    文件:TObjectDoubleHashMap.java   
/**
 * Creates a new <code>TObjectDoubleHashMap</code> that contains the entries
 * in the map passed to it.
 *
 * @param map the <tt>TObjectDoubleMap</tt> to be copied.
 */
@SuppressWarnings("rawtypes")
public TObjectDoubleHashMap( TObjectDoubleMap<? extends K> map ) {
    this( map.size(), 0.5f, map.getNoEntryValue() );
    if ( map instanceof TObjectDoubleHashMap ) {
        TObjectDoubleHashMap hashmap = ( TObjectDoubleHashMap ) map;
        this._loadFactor = hashmap._loadFactor;
        this.no_entry_value = hashmap.no_entry_value;
        //noinspection RedundantCast
        if ( this.no_entry_value != ( double ) 0 ) {
            Arrays.fill( _values, this.no_entry_value );
        }
        setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
    }
    putAll( map );
}
项目:trove-3.0.3    文件:TObjectDoubleCustomHashMap.java   
/**
   * Creates a new <code>TObjectDoubleCustomHashMap</code> that contains the entries
   * in the map passed to it.
   *
   * @param map the <tt>TObjectDoubleMap</tt> to be copied.
   */
  @SuppressWarnings({ "rawtypes", "unchecked" })
  public TObjectDoubleCustomHashMap( HashingStrategy<? super K> strategy,
TObjectDoubleMap<? extends K> map ) {

      this( strategy, map.size(), 0.5f, map.getNoEntryValue() );

      if ( map instanceof TObjectDoubleCustomHashMap ) {
          TObjectDoubleCustomHashMap hashmap = ( TObjectDoubleCustomHashMap ) map;
          this._loadFactor = hashmap._loadFactor;
          this.no_entry_value = hashmap.no_entry_value;
          this.strategy = hashmap.strategy;
          //noinspection RedundantCast
          if ( this.no_entry_value != ( double ) 0 ) {
              Arrays.fill( _values, this.no_entry_value );
          }
          setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
      }
      putAll( map );
  }
项目:cineast    文件:ScoreFusion.java   
/**
 * Fuses the object scores into the segment scores by adding every object score to the scores of
 * its segments. If an object without any of its segments was found, the first segment gets added
 * and used instead.
 * Note that this method <i>modifies {@code scoreBySegmentId} in place without changing
 * {@code scoreByObjectId}</i>.
 *
 * @param scoreBySegmentId segment ids with their respective score
 * @param scoreByObjectId object ids with their respective score
 */
public static void fuseObjectsIntoSegments(TObjectDoubleMap<String> scoreBySegmentId,
    TObjectDoubleMap<String> scoreByObjectId) {
  SegmentLookup segmentLookup = new SegmentLookup();

  Set<String> objectIds = scoreByObjectId.keySet();
  ListMultimap<String, SegmentDescriptor> segmentsByObjectId =
      segmentLookup.lookUpSegmentsOfObjects(objectIds);
  for (String objectId : segmentsByObjectId.keySet()) {
    assert scoreByObjectId.containsKey(objectId);
    double objectScore = scoreByObjectId.get(objectId);
    List<SegmentDescriptor> segments = segmentsByObjectId.get(objectId);
    if (segments.isEmpty()) {
      logger.error("Object {} has no segments", objectId);
      continue;
    }
    fuseObjectScoreIntoSegments(scoreBySegmentId, objectScore, segments);
  }
  segmentLookup.close();
}
项目:cineast    文件:ScoreFusion.java   
private static void fuseObjectScoreIntoSegments(TObjectDoubleMap<String> scoreBySegmentId,
    double objectScore, List<SegmentDescriptor> segments) {
  boolean objectSegmentsFoundInResults = false;
  for (SegmentDescriptor segment : segments) {
    boolean foundElement = scoreBySegmentId.adjustValue(segment.getSegmentId(), objectScore);
    if (foundElement) {
      objectSegmentsFoundInResults = true;
    }
  }

  if (!objectSegmentsFoundInResults) {
    SegmentDescriptor firstSegment = segments.get(0);
    String firstId = firstSegment.getSegmentId();
    scoreBySegmentId.put(firstId, objectScore);
  }
}
项目:easyrec_major    文件:TObjectDoubleCustomHashMap.java   
/**
 * Creates a new <code>TObjectDoubleCustomHashMap</code> that contains the entries
 * in the map passed to it.
 *
 * @param map the <tt>TObjectDoubleMap</tt> to be copied.
 */
public TObjectDoubleCustomHashMap( HashingStrategy<K> strategy, TObjectDoubleMap<K> map ) {
    this( strategy, map.size(), 0.5f, map.getNoEntryValue() );

    if ( map instanceof TObjectDoubleCustomHashMap ) {
        TObjectDoubleCustomHashMap hashmap = ( TObjectDoubleCustomHashMap ) map;
        this._loadFactor = hashmap._loadFactor;
        this.no_entry_value = hashmap.no_entry_value;
        this.strategy = hashmap.strategy;
        //noinspection RedundantCast
        if ( this.no_entry_value != ( double ) 0 ) {
            Arrays.fill( _values, this.no_entry_value );
        }
        setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
    }
    putAll( map );
}
项目:recalot.com    文件:TObjectDoubleCustomHashMap.java   
/**
   * Creates a new <code>TObjectDoubleCustomHashMap</code> that contains the entries
   * in the map passed to it.
   *
   * @param map the <tt>TObjectDoubleMap</tt> to be copied.
   */
  public TObjectDoubleCustomHashMap( HashingStrategy<? super K> strategy,
TObjectDoubleMap<? extends K> map ) {

      this( strategy, map.size(), 0.5f, map.getNoEntryValue() );

      if ( map instanceof TObjectDoubleCustomHashMap ) {
          TObjectDoubleCustomHashMap hashmap = ( TObjectDoubleCustomHashMap ) map;
          this._loadFactor = hashmap._loadFactor;
          this.no_entry_value = hashmap.no_entry_value;
          this.strategy = hashmap.strategy;
          //noinspection RedundantCast
          if ( this.no_entry_value != ( double ) 0 ) {
              Arrays.fill( _values, this.no_entry_value );
          }
          setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
      }
      putAll( map );
  }
项目:java-belief-propagation    文件:Coloring.java   
public static void main(String[] args) {
    Map<Integer, GraphColorNode> nodeIdToNode = initializeNodesOfPetersenGraph();

    List<Edge<Color, Color>> edges = initializeEdgesOfPetersenGraph(nodeIdToNode);

    inferenceOfMostProbableColorsOfNodes(edges);

    for (int i = 1; i <= 10; i++) {
        System.out.print(i);
        TObjectDoubleMap<Color> stateProbability = nodeIdToNode.get(i).getPosteriorProbabilities();
        for (Color state : stateProbability.keySet()) {
            System.out.print(String.format("\t %s = %.2f", state, stateProbability.get(state)));
        }
        System.out.println();
    }
}
项目:java-belief-propagation    文件:Edge.java   
/**
 * node2 -> node1
 */
public void updateMessagesNode2ToNode1() {
    TObjectDoubleMap<STATES_OF_NODE_2> node2StateToLogPriorProbabilityAndProductIncomingMessages =
            this.node2.getStateToLogPriorProbabilityAndProductIncomingMessages();

    for (STATES_OF_NODE_1 stateOfNode1 : this.node1.getStates()) {
        int i = 0;
        for (STATES_OF_NODE_2 stateOfNode2 : this.node2.getStates()) {

            double logPriorProbabilityAndProductIncomingMessages =
                    node2StateToLogPriorProbabilityAndProductIncomingMessages.get(stateOfNode2)
                            - this.getLogIncomingMessage(this.node2, stateOfNode2);

            this.bufferForUpdatingMessagesFromNode2[i] =
                    this.potential.getLogValue(stateOfNode1, stateOfNode2)
                            + logPriorProbabilityAndProductIncomingMessages;

            i += 1;
        }
        this.logNode2ToNode1MessagesNew.put(stateOfNode1, logOfSum(this.bufferForUpdatingMessagesFromNode2));
    }
}
项目:java-belief-propagation    文件:Edge.java   
/**
 * node1 -> node2
 */
public void updateMessagesNode1ToNode2() {
    TObjectDoubleMap<STATES_OF_NODE_1> node1StateToLogPriorProbabilityAndProductIncomingMessages =
            this.node1.getStateToLogPriorProbabilityAndProductIncomingMessages();

    for (STATES_OF_NODE_2 stateOfNode2 : this.node2.getStates()) {
        int i = 0;
        for (STATES_OF_NODE_1 stateOfNode1 : this.node1.getStates()) {

            double logPriorProbabilityAndProductIncomingMessages =
                    node1StateToLogPriorProbabilityAndProductIncomingMessages.get(stateOfNode1)
                            - this.getLogIncomingMessage(this.node1, stateOfNode1);

            this.bufferForUpdatingMessagesFromNode1[i] =
                    this.potential.getLogValue(stateOfNode1, stateOfNode2)
                            + logPriorProbabilityAndProductIncomingMessages;

            i += 1;
        }
        this.logNode1ToNode2MessagesNew.put(stateOfNode2, logOfSum(this.bufferForUpdatingMessagesFromNode1));
    }
}
项目:ExtensiveFormGames    文件:TestLimitedLookAheadOpponentSolver.java   
@Test
public void testEquilibriumEvalutationMiniKuhn() {
    Game miniKuhnGame = new Game();
    miniKuhnGame.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "mini_kuhn.txt");

    SequenceFormLPSolver solverP1 = new SequenceFormLPSolver(miniKuhnGame, 1);
    SequenceFormLPSolver solverP2 = new SequenceFormLPSolver(miniKuhnGame, 2);

    solverP1.solveGame();
    solverP2.solveGame();

    TObjectDoubleMap<String>[] strategyP1 = solverP1.getInformationSetActionProbabilities();
    TObjectDoubleMap<String>[] strategyP2 = solverP2.getInformationSetActionProbabilities();

    // get negated expected values
    double[] nodeEvaluationTable = miniKuhnGame.getExpectedValuesForNodes(strategyP1, strategyP2, true);

    // Compute the best strategy to commit to when the limited look-ahead player knows how much can be achieved from a node in (some) equilibrium
    LimitedLookAheadOpponentSolver solver = new LimitedLookAheadOpponentSolver(miniKuhnGame, 1, nodeEvaluationTable, 100);
    //solver.writeModelToFile(TestConfiguration.lpModelsFolder + "kuhnp1-limited-look-ahead.lp");
    solver.writeModelToFile(TestConfiguration.lpModelsFolder + "equilibrium-minikuhn-limited-look-ahead.lp");
    solver.solveGame();
    assertEquals(solverP1.getValueOfGame(), solver.getValueOfGame(), TestConfiguration.epsilon);
}
项目:ExtensiveFormGames    文件:TestLimitedLookAheadOpponentSolver.java   
@Test
public void testEquilibriumEvalutationKuhn() {
    Game kuhnGame = new Game();
    kuhnGame.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "kuhn.txt");

    SequenceFormLPSolver solverP1 = new SequenceFormLPSolver(kuhnGame, 1);
    SequenceFormLPSolver solverP2 = new SequenceFormLPSolver(kuhnGame, 2);

    solverP1.solveGame();
    solverP2.solveGame();

    TObjectDoubleMap<String>[] strategyP1 = solverP1.getInformationSetActionProbabilities();
    TObjectDoubleMap<String>[] strategyP2 = solverP2.getInformationSetActionProbabilities();

    // get negated expected values
    double[] nodeEvaluationTable = kuhnGame.getExpectedValuesForNodes(strategyP1, strategyP2, true);
    System.out.println(Arrays.toString(nodeEvaluationTable));
    // Compute the best strategy to commit to when the limited look-ahead player knows how much can be achieved from a node in (some) equilibrium
    LimitedLookAheadOpponentSolver solver = new LimitedLookAheadOpponentSolver(kuhnGame, 1, nodeEvaluationTable, 1);
    //solver.writeModelToFile(TestConfiguration.lpModelsFolder + "kuhnp1-limited-look-ahead.lp");
    solver.writeModelToFile(TestConfiguration.lpModelsFolder + "equilibrium-kuhn-limited-look-ahead.lp");
    solver.solveGame();
    System.out.println(kuhnGame);
    solver.printStrategyVarsAndGameValue();
    assertEquals(solverP1.getValueOfGame(), solver.getValueOfGame(), TestConfiguration.epsilon);
}
项目:ExtensiveFormGames    文件:TestLimitedLookAheadOpponentSolver.java   
@Test
public void testEquilibriumEvalutationKuhnP2() {
    Game kuhnGame = new Game();
    kuhnGame.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "kuhn.txt");

    SequenceFormLPSolver solverP1 = new SequenceFormLPSolver(kuhnGame, 1);
    SequenceFormLPSolver solverP2 = new SequenceFormLPSolver(kuhnGame, 2);

    solverP1.solveGame();
    solverP2.solveGame();

    TObjectDoubleMap<String>[] strategyP1 = solverP1.getInformationSetActionProbabilities();
    TObjectDoubleMap<String>[] strategyP2 = solverP2.getInformationSetActionProbabilities();

    // get negated expected values
    double[] nodeEvaluationTable = kuhnGame.getExpectedValuesForNodes(strategyP1, strategyP2, false);

    // Compute the best strategy to commit to when the limited look-ahead player knows how much can be achieved from a node in (some) equilibrium
    LimitedLookAheadOpponentSolver solver = new LimitedLookAheadOpponentSolver(kuhnGame, 2, nodeEvaluationTable, 1);
    //solver.writeModelToFile(TestConfiguration.lpModelsFolder + "kuhnp1-limited-look-ahead.lp");
    solver.writeModelToFile(TestConfiguration.lpModelsFolder + "equilibrium-kuhnp2-limited-look-ahead.lp");
    solver.solveGame();
    assertEquals(solverP2.getValueOfGame(), solver.getValueOfGame(), TestConfiguration.epsilon);
}
项目:ExtensiveFormGames    文件:TestLimitedLookAheadOpponentSolver.java   
@Test
public void testEquilibriumEvalutationPrsl() {
    Game game = new Game();
    game.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "prsl.txt");

    SequenceFormLPSolver solverP1 = new SequenceFormLPSolver(game, 1);
    SequenceFormLPSolver solverP2 = new SequenceFormLPSolver(game, 2);

    solverP1.solveGame();
    solverP2.solveGame();

    TObjectDoubleMap<String>[] strategyP1 = solverP1.getInformationSetActionProbabilities();
    TObjectDoubleMap<String>[] strategyP2 = solverP2.getInformationSetActionProbabilities();

    // get negated expected values
    double[] nodeEvaluationTable = game.getExpectedValuesForNodes(strategyP1, strategyP2, true);

    // Compute the best strategy to commit to when the limited look-ahead player knows how much can be achieved from a node in (some) equilibrium
    LimitedLookAheadOpponentSolver solver = new LimitedLookAheadOpponentSolver(game, 1, nodeEvaluationTable, 100);
    //solver.writeModelToFile(TestConfiguration.lpModelsFolder + "kuhnp1-limited-look-ahead.lp");
    solver.writeModelToFile(TestConfiguration.lpModelsFolder + "equilibrium-prsl-limited-look-ahead.lp");
    solver.solveGame();
    assertEquals(solverP1.getValueOfGame(), solver.getValueOfGame(), TestConfiguration.epsilon);
}
项目:ExtensiveFormGames    文件:TestLimitedLookAheadOpponentSolver.java   
@Test
public void testEquilibriumEvaluationLeducKJLa100() {
    Game leducGame = new Game();
    leducGame.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "leduc_KJ.txt");

    SequenceFormLPSolver solverP1 = new SequenceFormLPSolver(leducGame, 1);
    SequenceFormLPSolver solverP2 = new SequenceFormLPSolver(leducGame, 2);

    solverP1.solveGame();
    solverP2.solveGame();

    TObjectDoubleMap<String>[] strategyP1 = solverP1.getInformationSetActionProbabilities();
    TObjectDoubleMap<String>[] strategyP2 = solverP2.getInformationSetActionProbabilities();

    double[] nodeEvaluationTable = leducGame.getExpectedValuesForNodes(strategyP1, strategyP2);

    // Compute the best strategy to commit to when the limited look-ahead player knows how much can be achieved from a node in (some) equilibrium
    LimitedLookAheadOpponentSolver solver = new LimitedLookAheadOpponentSolver(leducGame, 1, nodeEvaluationTable, 100);
    solver.writeModelToFile(TestConfiguration.lpModelsFolder + "equilibrium-leducKJp1la1-limited-look-ahead.lp");
    solver.solveGame();
    System.out.println("Value of game: " + solver.getValueOfGame());
    assertEquals(solverP1.getValueOfGame(), solver.getValueOfGame(), TestConfiguration.epsilon);
}
项目:ExtensiveFormGames    文件:TestLimitedLookAheadOpponentSolver.java   
public void testEquilibriumEvaluationLeducLa1() {
    Game leducGame = new Game();
    leducGame.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "leduc.txt");

    SequenceFormLPSolver solverP1 = new SequenceFormLPSolver(leducGame, 1);
    SequenceFormLPSolver solverP2 = new SequenceFormLPSolver(leducGame, 2);

    solverP1.solveGame();
    solverP2.solveGame();

    TObjectDoubleMap<String>[] strategyP1 = solverP1.getInformationSetActionProbabilities();
    TObjectDoubleMap<String>[] strategyP2 = solverP2.getInformationSetActionProbabilities();

    double[] nodeEvaluationTable = leducGame.getExpectedValuesForNodes(strategyP1, strategyP2);

    // Compute the best strategy to commit to when the limited look-ahead player knows how much can be achieved from a node in (some) equilibrium
    LimitedLookAheadOpponentSolver solver = new LimitedLookAheadOpponentSolver(leducGame, 1, nodeEvaluationTable, 1);
    solver.writeModelToFile(TestConfiguration.lpModelsFolder + "equilibrium-leducp1la2-limited-look-ahead.lp");
    solver.solveGame();
    System.out.println("Value of game: " + solver.getValueOfGame());
    assertTrue(solverP1.getValueOfGame() <= solver.getValueOfGame());
}
项目:ExtensiveFormGames    文件:TestLimitedLookAheadOpponentSolver.java   
public void testEquilibriumEvaluationLeducLa2() {
    Game leducGame = new Game();
    leducGame.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "leduc.txt");

    SequenceFormLPSolver solverP1 = new SequenceFormLPSolver(leducGame, 1);
    SequenceFormLPSolver solverP2 = new SequenceFormLPSolver(leducGame, 2);

    solverP1.solveGame();
    solverP2.solveGame();

    TObjectDoubleMap<String>[] strategyP1 = solverP1.getInformationSetActionProbabilities();
    TObjectDoubleMap<String>[] strategyP2 = solverP2.getInformationSetActionProbabilities();

    double[] nodeEvaluationTable = leducGame.getExpectedValuesForNodes(strategyP1, strategyP2);

    // Compute the best strategy to commit to when the limited look-ahead player knows how much can be achieved from a node in (some) equilibrium
    LimitedLookAheadOpponentSolver solver = new LimitedLookAheadOpponentSolver(leducGame, 1, nodeEvaluationTable, 3);
    solver.writeModelToFile(TestConfiguration.lpModelsFolder + "equilibrium-leducp1la2-limited-look-ahead.lp");
    solver.solveGame();
    System.out.println("Value of zero-sum game: " + solver.getValueOfGame());
    System.out.println("Value of limited look-ahead game: " + solver.getValueOfGame());
    assertTrue(solverP1.getValueOfGame() <= solver.getValueOfGame());
}
项目:easyrec-PoC    文件:TObjectDoubleCustomHashMap.java   
/**
 * Creates a new <code>TObjectDoubleCustomHashMap</code> that contains the entries
 * in the map passed to it.
 *
 * @param map the <tt>TObjectDoubleMap</tt> to be copied.
 */
public TObjectDoubleCustomHashMap( HashingStrategy<K> strategy, TObjectDoubleMap<K> map ) {
    this( strategy, map.size(), 0.5f, map.getNoEntryValue() );

    if ( map instanceof TObjectDoubleCustomHashMap ) {
        TObjectDoubleCustomHashMap hashmap = ( TObjectDoubleCustomHashMap ) map;
        this._loadFactor = hashmap._loadFactor;
        this.no_entry_value = hashmap.no_entry_value;
        this.strategy = hashmap.strategy;
        //noinspection RedundantCast
        if ( this.no_entry_value != ( double ) 0 ) {
            Arrays.fill( _values, this.no_entry_value );
        }
        setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
    }
    putAll( map );
}
项目:mechaverse    文件:ElitistSelectionStrategy.java   
@Override
public List<Pair<E, E>> selectEntities(
    TObjectDoubleMap<E> entityFitnessMap, int count, RandomGenerator random) {
  if (retainTopEntityCount == 0 && removeBottomEntityCount == 0) {
    return selectionStrategy.selectEntities(entityFitnessMap, count, random);
  }

  int retainCount = Math.min(retainTopEntityCount, count);
  List<E> eliteEntities = SelectionUtil.filterAndSelectEliteEntities(
    retainCount, removeBottomEntityCount, entityFitnessMap, getMinimize());

  List<Pair<E, E>> selectedPairs = new ArrayList<>();

  for (E entity : eliteEntities) {
    selectedPairs.add(new Pair<E, E>(entity, null));
  }

  selectedPairs.addAll(selectionStrategy.selectEntities(
      entityFitnessMap, count - selectedPairs.size(), random));

  return selectedPairs;
}
项目:mechaverse    文件:SelectionUtil.java   
/**
 * Returns a list of the most fit entities and filters out the least fit entities.
 *
 * @param retainTopEntityCount the number of most fit entities to return
 * @param removeBottomEntityCount the number of least fit entities to filter out
 * @param sortedEntityList the list of entities sorted by fitness
 * @param entityFitnessMap maps each entity to its fitness
 * @return a list of the most fit entities
 */
public static <E> List<E> filterAndSelectEliteEntities(int retainTopEntityCount,
    int removeBottomEntityCount, List<E> sortedEntityList, TObjectDoubleMap<E> entityFitnessMap) {
  int removeCount = Math.min(removeBottomEntityCount, sortedEntityList.size());
  for (int cnt = 1; cnt <= removeCount; cnt++) {
    E entity = sortedEntityList.remove(sortedEntityList.size() - 1);
    entityFitnessMap.remove(entity);
  }

  int retainCount = Math.min(retainTopEntityCount, sortedEntityList.size());

  List<E> selectedEntities = new ArrayList<>();
  for (int idx = 0; idx < retainCount; idx++) {
    selectedEntities.add(sortedEntityList.get(idx));
  }
  return selectedEntities;
}
项目:mechaverse    文件:FitnessProportionalSelectionStrategy.java   
@Override
public List<Pair<E, E>> selectEntities(TObjectDoubleMap<E> entityFitnessMap, int count,
    RandomGenerator random) {
  Preconditions.checkNotNull(entityFitnessMap);
  Preconditions.checkNotNull(random);

  EnumeratedDistribution<E> distribution = getFitnessDistribution(entityFitnessMap, random);

  List<Pair<E, E>> selectedPairs = new ArrayList<>();

  if (distribution != null) {
    for (int cnt = 1; cnt <= count; cnt++) {
      E parent1 = distribution.sample();
      E parent2 = distribution.sample();

      if (distribution.getPmf().size() > 1) {
        // Ensure that parent1 != parent2.
        while (parent2 == parent1) {
          parent2 = distribution.sample();
        }
      }
      selectedPairs.add(new Pair<>(parent1, parent2));
    }
  }
  return selectedPairs;
}
项目:mechaverse    文件:FitnessProportionalSelectionStrategy.java   
private EnumeratedDistribution<E> getFitnessDistribution(
    final TObjectDoubleMap<E> entityFitnessMap, RandomGenerator random) {
  if (entityFitnessMap.isEmpty()) {
    return null;
  }
  double sum = 0;
  for (Double fitness : entityFitnessMap.values()) {
    sum += fitness;
  }

  final double fitnessSum = sum;
  final List<Pair<E, Double>> pmf = new ArrayList<>();
  entityFitnessMap.forEachEntry(new TObjectDoubleProcedure<E>() {
    @Override
    public boolean execute(E entity, double value) {
      if (fitnessSum != 0) {
        pmf.add(new Pair<>(entity, value));
      } else {
        pmf.add(new Pair<>(entity, 1.0D / entityFitnessMap.size()));
      }
      return true;
    }
  });

  return new EnumeratedDistribution<>(random, pmf);
}
项目:mechaverse    文件:TournamentSelectionStrategy.java   
@Override
public List<Pair<E, E>> selectEntities(
    TObjectDoubleMap<E> entityFitnessMap, int entityCount, RandomGenerator random) {
  Preconditions.checkNotNull(entityFitnessMap);
  Preconditions.checkNotNull(random);

  List<E> entities = new ArrayList<>(entityFitnessMap.keySet());

  List<Pair<E, E>> selectedPairs = new ArrayList<>();
  while (selectedPairs.size() < entityCount) {
    E parent1 = selectParent(entities, entityFitnessMap, random);
    E parent2 = selectParent(entities, entityFitnessMap, random);
    selectedPairs.add(new Pair<>(parent1, parent2));
  }

  return selectedPairs;
}
项目:easyrec    文件:TObjectDoubleCustomHashMap.java   
/**
 * Creates a new <code>TObjectDoubleCustomHashMap</code> that contains the entries
 * in the map passed to it.
 *
 * @param map the <tt>TObjectDoubleMap</tt> to be copied.
 */
public TObjectDoubleCustomHashMap( HashingStrategy<K> strategy, TObjectDoubleMap<K> map ) {
    this( strategy, map.size(), 0.5f, map.getNoEntryValue() );

    if ( map instanceof TObjectDoubleCustomHashMap ) {
        TObjectDoubleCustomHashMap hashmap = ( TObjectDoubleCustomHashMap ) map;
        this._loadFactor = hashmap._loadFactor;
        this.no_entry_value = hashmap.no_entry_value;
        this.strategy = hashmap.strategy;
        //noinspection RedundantCast
        if ( this.no_entry_value != ( double ) 0 ) {
            Arrays.fill( _values, this.no_entry_value );
        }
        setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
    }
    putAll( map );
}
项目:Mineworld    文件:UIScreenMetrics.java   
private static void sortMetrics(TObjectDoubleMap<String> metrics, final List<String> activities, final List<Double> values) {
    metrics.forEachEntry(new TObjectDoubleProcedure<String>() {
        public boolean execute(String s, double v) {
            boolean inserted = false;
            for (int i = 0; i < values.size() && i < METRIC_LINES; i++) {
                if (v > values.get(i)) {
                    values.add(i, v);
                    activities.add(i, s);
                    inserted = true;
                    break;
                }
            }

            if (!inserted && values.size() < METRIC_LINES) {
                activities.add(s);
                values.add(v);
            }
            return true;
        }
    });
}
项目:xcc    文件:TObjectDoubleHashMap.java   
/**
 * Creates a new <code>TObjectDoubleHashMap</code> that contains the entries
 * in the map passed to it.
 *
 * @param map the <tt>TObjectDoubleMap</tt> to be copied.
 */
public TObjectDoubleHashMap( TObjectDoubleMap<? extends K> map ) {
    this( map.size(), 0.5f, map.getNoEntryValue() );
    if ( map instanceof TObjectDoubleHashMap ) {
        TObjectDoubleHashMap hashmap = ( TObjectDoubleHashMap ) map;
        this._loadFactor = hashmap._loadFactor;
        this.no_entry_value = hashmap.no_entry_value;
        //noinspection RedundantCast
        if ( this.no_entry_value != ( double ) 0 ) {
            Arrays.fill( _values, this.no_entry_value );
        }
        setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
    }
    putAll( map );
}
项目:xcc    文件:TObjectDoubleHashMap.java   
/**
 * Compares this map with another map for equality of their stored
 * entries.
 *
 * @param other an <code>Object</code> value
 * @return a <code>boolean</code> value
 */
public boolean equals( Object other ) {
    if ( ! ( other instanceof TObjectDoubleMap ) ) {
        return false;
    }
    TObjectDoubleMap that = ( TObjectDoubleMap ) other;
    if ( that.size() != this.size() ) {
        return false;
    }
    try {
        TObjectDoubleIterator iter = this.iterator();
        while ( iter.hasNext() ) {
            iter.advance();
            Object key = iter.key();
            double value = iter.value();
            if ( value == no_entry_value ) {
                if ( !( that.get( key ) == that.getNoEntryValue() &&
                 that.containsKey( key ) ) ) {

                    return false;
                }
            } else {
                if ( value != that.get( key ) ) {
                    return false;
                }
            }
        }
    } catch ( ClassCastException ex ) {
        // unused.
    }
    return true;
}
项目:xcc    文件:TObjectDoubleCustomHashMap.java   
/**
 * Compares this map with another map for equality of their stored
 * entries.
 *
 * @param other an <code>Object</code> value
 * @return a <code>boolean</code> value
 */
public boolean equals( Object other ) {
    if ( ! ( other instanceof TObjectDoubleMap ) ) {
        return false;
    }
    TObjectDoubleMap that = ( TObjectDoubleMap ) other;
    if ( that.size() != this.size() ) {
        return false;
    }
    try {
        TObjectDoubleIterator iter = this.iterator();
        while ( iter.hasNext() ) {
            iter.advance();
            Object key = iter.key();
            double value = iter.value();
            if ( value == no_entry_value ) {
                if ( !( that.get( key ) == that.getNoEntryValue() &&
                 that.containsKey( key ) ) ) {

                    return false;
                }
            } else {
                if ( value != that.get( key ) ) {
                    return false;
                }
            }
        }
    } catch ( ClassCastException ex ) {
        // unused.
    }
    return true;
}
项目:xcc    文件:TObjectDoubleMapDecorator.java   
public void readExternal(ObjectInput in)
    throws IOException, ClassNotFoundException {

    // VERSION
    in.readByte();

    // MAP
    //noinspection unchecked
    _map = ( TObjectDoubleMap<K> ) in.readObject();
}
项目:HCFCore    文件:TObjectDoubleHashMap.java   
/**
 * Creates a new <code>TObjectDoubleHashMap</code> that contains the entries
 * in the map passed to it.
 *
 * @param map the <tt>TObjectDoubleMap</tt> to be copied.
 */
public TObjectDoubleHashMap( TObjectDoubleMap<? extends K> map ) {
    this( map.size(), 0.5f, map.getNoEntryValue() );
    if ( map instanceof TObjectDoubleHashMap ) {
        TObjectDoubleHashMap hashmap = ( TObjectDoubleHashMap ) map;
        this._loadFactor = hashmap._loadFactor;
        this.no_entry_value = hashmap.no_entry_value;
        //noinspection RedundantCast
        if ( this.no_entry_value != ( double ) 0 ) {
            Arrays.fill( _values, this.no_entry_value );
        }
        setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
    }
    putAll( map );
}
项目:HCFCore    文件:TObjectDoubleHashMap.java   
/**
 * Compares this map with another map for equality of their stored
 * entries.
 *
 * @param other an <code>Object</code> value
 * @return a <code>boolean</code> value
 */
public boolean equals( Object other ) {
    if ( ! ( other instanceof TObjectDoubleMap ) ) {
        return false;
    }
    TObjectDoubleMap that = ( TObjectDoubleMap ) other;
    if ( that.size() != this.size() ) {
        return false;
    }
    try {
        TObjectDoubleIterator iter = this.iterator();
        while ( iter.hasNext() ) {
            iter.advance();
            Object key = iter.key();
            double value = iter.value();
            if ( value == no_entry_value ) {
                if ( !( that.get( key ) == that.getNoEntryValue() &&
                 that.containsKey( key ) ) ) {

                    return false;
                }
            } else {
                if ( value != that.get( key ) ) {
                    return false;
                }
            }
        }
    } catch ( ClassCastException ex ) {
        // unused.
    }
    return true;
}
项目:HCFCore    文件:TObjectDoubleCustomHashMap.java   
/**
 * Compares this map with another map for equality of their stored
 * entries.
 *
 * @param other an <code>Object</code> value
 * @return a <code>boolean</code> value
 */
public boolean equals( Object other ) {
    if ( ! ( other instanceof TObjectDoubleMap ) ) {
        return false;
    }
    TObjectDoubleMap that = ( TObjectDoubleMap ) other;
    if ( that.size() != this.size() ) {
        return false;
    }
    try {
        TObjectDoubleIterator iter = this.iterator();
        while ( iter.hasNext() ) {
            iter.advance();
            Object key = iter.key();
            double value = iter.value();
            if ( value == no_entry_value ) {
                if ( !( that.get( key ) == that.getNoEntryValue() &&
                 that.containsKey( key ) ) ) {

                    return false;
                }
            } else {
                if ( value != that.get( key ) ) {
                    return false;
                }
            }
        }
    } catch ( ClassCastException ex ) {
        // unused.
    }
    return true;
}
项目:HCFCore    文件:TObjectDoubleMapDecorator.java   
public void readExternal(ObjectInput in)
    throws IOException, ClassNotFoundException {

    // VERSION
    in.readByte();

    // MAP
    //noinspection unchecked
    _map = ( TObjectDoubleMap<K> ) in.readObject();
}
项目:HCFCore    文件:TObjectDoubleHashMap.java   
/**
 * Creates a new <code>TObjectDoubleHashMap</code> that contains the entries
 * in the map passed to it.
 *
 * @param map the <tt>TObjectDoubleMap</tt> to be copied.
 */
public TObjectDoubleHashMap( TObjectDoubleMap<? extends K> map ) {
    this( map.size(), 0.5f, map.getNoEntryValue() );
    if ( map instanceof TObjectDoubleHashMap ) {
        TObjectDoubleHashMap hashmap = ( TObjectDoubleHashMap ) map;
        this._loadFactor = hashmap._loadFactor;
        this.no_entry_value = hashmap.no_entry_value;
        //noinspection RedundantCast
        if ( this.no_entry_value != ( double ) 0 ) {
            Arrays.fill( _values, this.no_entry_value );
        }
        setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
    }
    putAll( map );
}
项目:HCFCore    文件:TObjectDoubleHashMap.java   
/**
 * Compares this map with another map for equality of their stored
 * entries.
 *
 * @param other an <code>Object</code> value
 * @return a <code>boolean</code> value
 */
public boolean equals( Object other ) {
    if ( ! ( other instanceof TObjectDoubleMap ) ) {
        return false;
    }
    TObjectDoubleMap that = ( TObjectDoubleMap ) other;
    if ( that.size() != this.size() ) {
        return false;
    }
    try {
        TObjectDoubleIterator iter = this.iterator();
        while ( iter.hasNext() ) {
            iter.advance();
            Object key = iter.key();
            double value = iter.value();
            if ( value == no_entry_value ) {
                if ( !( that.get( key ) == that.getNoEntryValue() &&
                 that.containsKey( key ) ) ) {

                    return false;
                }
            } else {
                if ( value != that.get( key ) ) {
                    return false;
                }
            }
        }
    } catch ( ClassCastException ex ) {
        // unused.
    }
    return true;
}
项目:HCFCore    文件:TObjectDoubleCustomHashMap.java   
/**
 * Compares this map with another map for equality of their stored
 * entries.
 *
 * @param other an <code>Object</code> value
 * @return a <code>boolean</code> value
 */
public boolean equals( Object other ) {
    if ( ! ( other instanceof TObjectDoubleMap ) ) {
        return false;
    }
    TObjectDoubleMap that = ( TObjectDoubleMap ) other;
    if ( that.size() != this.size() ) {
        return false;
    }
    try {
        TObjectDoubleIterator iter = this.iterator();
        while ( iter.hasNext() ) {
            iter.advance();
            Object key = iter.key();
            double value = iter.value();
            if ( value == no_entry_value ) {
                if ( !( that.get( key ) == that.getNoEntryValue() &&
                 that.containsKey( key ) ) ) {

                    return false;
                }
            } else {
                if ( value != that.get( key ) ) {
                    return false;
                }
            }
        }
    } catch ( ClassCastException ex ) {
        // unused.
    }
    return true;
}
项目:HCFCore    文件:TObjectDoubleMapDecorator.java   
public void readExternal(ObjectInput in)
    throws IOException, ClassNotFoundException {

    // VERSION
    in.readByte();

    // MAP
    //noinspection unchecked
    _map = ( TObjectDoubleMap<K> ) in.readObject();
}
项目:java-probabilistic-earley-parser    文件:TObjectDoubleHashMap.java   
/**
 * Creates a new <code>TObjectDoubleHashMap</code> that contains the entries
 * in the map passed to it.
 *
 * @param map the <tt>TObjectDoubleMap</tt> to be copied.
 */
public TObjectDoubleHashMap(final TObjectDoubleMap<? extends K> map ) {
    this( map.size(), 0.5f, map.getNoEntryValue() );
    if ( map instanceof TObjectDoubleHashMap ) {
        final TObjectDoubleHashMap hashmap = ( TObjectDoubleHashMap ) map;
        this._loadFactor = hashmap._loadFactor;
        this.no_entry_value = hashmap.no_entry_value;
        //noinspection RedundantCast
        if ( this.no_entry_value != ( double ) 0 ) {
            Arrays.fill( _values, this.no_entry_value );
        }
        setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
    }
    putAll( map );
}