/** * Creates a new <code>TIntDoubleHashMap</code> instance containing * all of the entries in the map passed in. * * @param map a <tt>TIntDoubleMap</tt> that will be duplicated. */ public TIntDoubleHashMap( TIntDoubleMap map ) { super( map.size() ); if ( map instanceof TIntDoubleHashMap ) { TIntDoubleHashMap hashmap = ( TIntDoubleHashMap ) map; this._loadFactor = hashmap._loadFactor; this.no_entry_key = hashmap.no_entry_key; this.no_entry_value = hashmap.no_entry_value; //noinspection RedundantCast if ( this.no_entry_key != ( int ) 0 ) { Arrays.fill( _set, this.no_entry_key ); } //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 ); }
public static Data getData() { if (data != null) return data; MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); Integer[] dimsObj = DimensionManager.getIDs(); TIntDoubleMap map = new TIntDoubleHashMap(dimsObj.length); for (Integer dim : dimsObj) { map.put(dim, mean(server.worldTickTimes.get(dim)) * 1.0E-6D); } double meanTickTime = mean(server.tickTimeArray) * 1.0E-6D; int total = (int) (Runtime.getRuntime().totalMemory() / 1024 / 1024); int max = (int) (Runtime.getRuntime().maxMemory() / 1024 / 1024); int free = (int) (Runtime.getRuntime().freeMemory() / 1024 / 1024); data = new Data(meanTickTime, map, free, total, max); return data; }
/** * cosine similarity * @param v0 * @param v1 * @return */ public double calcSimilarity(ConceptVector v0, ConceptVector v1) { // double sum = 0.0; // ConceptIterator it0 = v0.iterator(); // while (it0.next()) { // double value1 = v1.get(it0.getId()); // if (value1 > 0) { // sum += it0.getValue() * value1; // } // } // // return sum / ( v0.getNorm2() * v1.getNorm2()); TIntDoubleMap X = new TIntDoubleHashMap(); TIntDoubleMap Y = new TIntDoubleHashMap(); ConceptIterator it = v0.iterator(); while (it.next()) { X.put(it.getId(), it.getValue()); } it = v1.iterator(); while (it.next()) { Y.put(it.getId(), it.getValue()); } return SimUtils.cosineSimilarity(X, Y); }
public static double cosineSimilarity(TIntDoubleMap X, TIntDoubleMap Y) { double xDotX = 0.0; double yDotY = 0.0; double xDotY = 0.0; for (int id : X.keys()) { double x = X.get(id); xDotX += x * x; if (Y.containsKey(id)) { xDotY += x * Y.get(id); } } for (double y : Y.values()) { yDotY += y * y; } return xDotX * yDotY != 0 ? xDotY / Math.sqrt(xDotX * yDotY): 0.0; }
/** * Normalize a vector to unit length. * @param X * @return */ public static TIntDoubleMap normalizeVector(TIntDoubleMap X) { TIntDoubleHashMap Y = new TIntDoubleHashMap(); double sumSquares = 0.0; for (double x : X.values()) { sumSquares += x * x; } if (sumSquares != 0.0) { double norm = Math.sqrt(sumSquares); for (int id : X.keys()) { Y.put(id, X.get(id) / norm); } return Y; } return X; }
@Test public void testInitialGetStrategyVarMap() { Game kuhnGame = new Game(); kuhnGame.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "kuhn.txt"); // This test checks that strategy vars are initialized correctly CounterFactualRegretSolver solver = new CounterFactualRegretSolver(kuhnGame); TIntDoubleMap[] map = solver.getInformationSetActionProbabilitiesByActionId(); for (int informationSetId = 0; informationSetId < kuhnGame.getNumInformationSets(1); informationSetId++) { int numActions = kuhnGame.getNumActionsAtInformationSet(1, informationSetId); for (int actionId = 0; actionId < numActions; actionId++) { assertEquals(1.0 / numActions, map[informationSetId].get(actionId), TestConfiguration.epsilon); } } }
protected void writeSimnilarity(int element1Id, double element1Score, TIntObjectIterator<ElementSimilarityScoring> it, boolean bR2L) throws SerializationException, IOException, NoScoreFoundException { TIntDoubleMap elementsScores = new TIntDoubleHashMap(); while (it.hasNext()) { it.advance(); int element2Id = it.key(); if (elementFilter == null || elementFilter.isRelevantElementForCalculation(element2Id)) { double element2Score = elementFeatureScoreStorage.getElementScore(element2Id); ElementSimilarityScoring similarityScoring = it.value(); double similarityScore = bR2L ? similarityScoring.getSimilarityScore(element2Score, element1Score) : similarityScoring.getSimilarityScore(element1Score, element2Score); if (similarityScore > 0) elementsScores.put(element2Id, similarityScore); } } LinkedHashMap<Integer, Double> sortedElementScores = SortUtil.sortMapByValue(elementsScores,true); if (vectorTruncater != null) sortedElementScores = vectorTruncater.truncate(sortedElementScores); if (bR2L) outR2LDevice.write(element1Id, sortedElementScores); else outL2RDevice.write(element1Id, sortedElementScores); }
/** {@inheritDoc} */ public void putAll( TIntDoubleMap map ) { ensureCapacity( map.size() ); TIntDoubleIterator iter = map.iterator(); while ( iter.hasNext() ) { iter.advance(); this.put( iter.key(), iter.value() ); } }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TIntDoubleMap ) ) { return false; } TIntDoubleMap that = ( TIntDoubleMap ) other; if ( that.size() != this.size() ) { return false; } double[] values = _values; byte[] states = _states; double this_no_entry_value = getNoEntryValue(); double that_no_entry_value = that.getNoEntryValue(); for ( int i = values.length; i-- > 0; ) { if ( states[i] == FULL ) { int key = _set[i]; double that_value = that.get( key ); double this_value = values[i]; if ( ( this_value != that_value ) && ( this_value != this_no_entry_value ) && ( that_value != that_no_entry_value ) ) { return false; } } } return true; }
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP _map = ( TIntDoubleMap ) in.readObject(); }
public Data(double meanTickTime, TIntDoubleMap map, int free, int total, int max) { this.meanTickTime = meanTickTime; this.tMap = map; this.free = free; this.total = total; this.max = max; }
/** {@inheritDoc} */ @Override public void putAll( TIntDoubleMap map ) { ensureCapacity( map.size() ); TIntDoubleIterator iter = map.iterator(); while ( iter.hasNext() ) { iter.advance(); this.put( iter.key(), iter.value() ); } }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TIntDoubleMap ) ) { return false; } TIntDoubleMap that = ( TIntDoubleMap ) other; if ( that.size() != this.size() ) { return false; } TDoubleOffheapArray values = _values; TByteOffheapArray states = _states; double this_no_entry_value = getNoEntryValue(); double that_no_entry_value = that.getNoEntryValue(); for ( int i = capacity(); i-- > 0; ) { if ( states.get( i ) == FULL ) { int key = _set.get( i ); double that_value = that.get( key ); double this_value = values.get( i ); if ( ( this_value != that_value ) && ( this_value != this_no_entry_value ) && ( that_value != that_no_entry_value ) ) { return false; } } } return true; }
@Override public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP _map = ( TIntDoubleMap ) in.readObject(); }
private static mt_dbl encodeDbl(TIntDoubleMap t_dbl, int timestampsSize) { LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_dbl)); double[] values = new double[timestampsSize]; int values_len = 0; for (int i = 0; i < values.length; ++i) { if (t_dbl.containsKey(i)) values[values_len++] = t_dbl.get(i); } mt_dbl result = new mt_dbl(); result.presence = createPresenceBitset(t_dbl.keySet(), timestampsSize); result.values = Arrays.copyOf(values, values_len); return result; }
/** * Creates a new matrix; the matrix has no capacity bounds. */ public SparseDoubleMatrix(int m, int n){ matrix = new TIntObjectHashMap<TIntDoubleMap>(); M = m; N = n; numberOfEntries = 0; }
/** * Gets the value at row i, column j; not yet set values are 0 * @param i * @param j * @return */ public Double get(int i, int j){ TIntDoubleMap row = matrix.get(i); if (row != null){ double value = row.get(j); return value; } // System.out.println("get not ex"); return 0.0; }
/** * Gets the value at row i, column j as boolean * @param i * @param j * @return */ public boolean getBool(int i, int j){ TIntDoubleMap row = matrix.get(i); if (row != null){ double value = row.get(j); return value!=0; } // System.out.println("get not ex"); return false; }