@Override protected void put(int[] ng, double[] scores) throws IOException { final float[] f = new float[scores.length]; for (int i = 0; i < scores.length; i++) { f[i] = (float) scores[i]; } map2.put(new NGram(ng), f); }
/** * Adds the given world to the world manager. It may be retrieved by name * from now on. * * @param world The world to be added */ private void addWorld(WorldAdapter world) { this.loadedWorlds.put(world.getWorldName(), world); }
@Override public LabelMapper getLabelMapper(String outputName) { LabelMapper cached = cachedLabelMaper.get(outputName); if (cached != null) { return cached; } else { cached = getInternalLabelMapper(outputName, 0); cachedLabelMaper.put(outputName, cached); return cached; } }
@Override public Group getOrCreateGroup( String name ) { // Check if this is the first group we get/create if ( this.groupMap == null ) { this.groupMap = new Object2ObjectOpenHashMap<>(); PermissionGroup group = new PermissionGroup( this, name ); this.groupMap.put( name, group ); return group; } Group group = this.groupMap.get( name ); if ( group == null ) { group = new PermissionGroup( this, name ); this.groupMap.put( name, group ); } return group; }
@Override public float update(@Nonnull final Object feature, final float weight, final float gradient) { IWeightValue auxWeight = auxWeights.get(feature); if (auxWeight == null) { auxWeight = new WeightValue.WeightValueParamsF2(weight, 0.f, 0.f); auxWeights.put(feature, auxWeight); } else { auxWeight.set(weight); } return update(auxWeight, gradient); }
@Override public float update(@Nonnull final Object feature, final float weight, final float gradient) { IWeightValue auxWeight = auxWeights.get(feature); if (auxWeight == null) { auxWeight = new WeightValue.WeightValueParamsF2(weight, 0.f, 0.f); auxWeights.put(feature, auxWeight); } else { auxWeight.set(weight); } return update(auxWeight, gradient); }
@Override public float update(@Nonnull final Object feature, final float weight, final float gradient) { IWeightValue auxWeight = auxWeights.get(feature); if (auxWeight == null) { auxWeight = new WeightValue.WeightValueParamsF2(weight, 0.f, 0.f); auxWeights.put(feature, auxWeight); } else { auxWeight.set(weight); } return update(auxWeight, gradient); }
@Override protected void setW(@Nonnull Feature x, float nextWi) { String j = x.getFeature(); assert (j != null); Entry entry = _map.get(j); if (entry == null) { float[] Vf = initV(); entry = new Entry(nextWi, Vf); _map.put(j, entry); } else { entry.W = nextWi; } }
/** * Log the performance of a model. The model is identified by a prefix. Use "best" if you are only * tracking the performance of the best model, by score. Use bestAUC if you are tracking the performance * of the model that got best AUC on the test set. Use final for the model created at the end of the * training process, irrespective of performance. * * @param prefix Identifies a specific model. * @param numExamplesUsed The number of training examples seen by the model. Note that examples used in training several times count several times. * @param epoch The number of epochs used to train the model. * @param score The score obtained at numExamplesUsed and epoch for the model. * @param auc The AUC on the test set, or NaN. */ public void log(String prefix, long numExamplesUsed, int epoch, double score, double auc) { ObjectArrayList<Performance> defaultValue = new ObjectArrayList<>(); bestScore = Math.min(bestScore, score); bestAUC = Math.max(bestAUC, auc); log.getOrDefault(prefix, defaultValue).add(new Performance(numExamplesUsed, epoch, score, auc)); if (defaultValue.size() > 0) { log.put(prefix, defaultValue); } }
/** * Add a record to the set of records. * * @param record */ public void add(BEDRecord record) { ObjectArrayList<BEDRecord> recordList = store.get(record.chromosome); if (recordList == null) { recordList = new ObjectArrayList<>(); store.put(record.chromosome, recordList); } recordList.add(record); }
/** * Log the performance of a model. The model is identified by a prefix. Use "best" if you are only * tracking the performance of the best model, by score. Use bestAUC if you are tracking the performance * of the model that got best AUC on the test set. Use final for the model created at the end of the * training process, irrespective of performance. * * @param prefix Identifies a specific model. * @param numExamplesUsed The number of training examples seen by the model. Note that examples used in training several times count several times. * @param epoch The number of epochs used to train the model. * @param metricValues values of performance metrics. */ public void logMetrics(String prefix, long numExamplesUsed, int epoch, double... metricValues) { ObjectArrayList<Performance> defaultValue = new ObjectArrayList<>(); for (int metricIndex = 0; metricIndex < metricValues.length; metricIndex++) { if (metricValues[metricIndex] == metricValues[metricIndex]) { // not NaN if (performanceLargeIsBest[metricIndex]) { bestPerformances[metricIndex] = Math.max(bestPerformances[metricIndex], metricValues[metricIndex]); } else { bestPerformances[metricIndex] = Math.min(bestPerformances[metricIndex], metricValues[metricIndex]); } } } log.getOrDefault(prefix, defaultValue).add(new Performance(numExamplesUsed, epoch, performanceNames, metricValues)); if (defaultValue.size() > 0) { log.put(prefix, defaultValue); } }
@Override public float getV(@Nonnull Feature x, int f) { String j = x.getFeature(); assert (j != null); final float[] V; Entry entry = _map.get(j); if (entry == null) { V = initV(); entry = new Entry(0.f, V); _map.put(j, entry); } else { V = entry.Vf; assert (V != null); } return V[f]; }
@Override protected void setV(@Nonnull Feature x, int f, float nextVif) { String j = x.getFeature(); assert (j != null); final float[] V; Entry entry = _map.get(j); if (entry == null) { V = initV(); entry = new Entry(0.f, V); _map.put(j, entry); } else { V = entry.Vf; assert (V != null); } V[f] = nextVif; }
/** * Move a player to a new chunk. This is done so we know which player is in which chunk so we can unload unneeded * Chunks better and faster. * * @param x The x-coordinate of the chunk * @param z The z-coordinate of the chunk * @param player The player which should be set into the chunk */ public void movePlayerToChunk(int x, int z, io.gomint.server.entity.EntityPlayer player) { ChunkAdapter oldChunk = this.players.get(player); ChunkAdapter newChunk = this.loadChunk(x, z, true); if (oldChunk == null) { newChunk.addPlayer(player); this.players.put(player, newChunk); } if (oldChunk != null && !oldChunk.equals(newChunk)) { oldChunk.removePlayer(player); newChunk.addPlayer(player); this.players.put(player, newChunk); } }
@Override public float update(@Nonnull final Object feature, final float weight, final float gradient) { IWeightValue auxWeight = auxWeights.get(feature); if (auxWeight == null) { auxWeight = new WeightValue.WeightValueParamsF2(weight, 0.f, 0.f); auxWeights.put(feature, auxWeight); } else { auxWeight.set(weight); } final float newWeight = update(auxWeight, gradient); if (newWeight == 0.f) { auxWeights.remove(feature); } return newWeight; }
@Override public void set(K k, K cond, int v) { if (!distributions.containsKey(cond)) { Object2IntFrequencyDistributionFastutil<K> fd = new Object2IntFrequencyDistributionFastutil<K>(); fd.set(k, v); distributions.put(cond, fd); marginals.increment(k, v); sumOfAllCounts += v; } else { Object2IntFrequencyDistribution<K> fd = distributions.get(cond); int rv = fd.get(k); fd.set(k, v); distributions.put(cond, fd); marginals.increment(k, -rv + v); sumOfAllCounts = sumOfAllCounts - rv + v; } }
Object k = keyRefOI.getPrimitiveJavaObject(f0); Object v = valueRefOI.getPrimitiveWritableObject(valueRefOI.copyObject(f1)); map.put(k, v);
if ( numberOfDocuments != index[ i ].numberOfDocuments ) throw new IllegalArgumentException( "All indices must have the same number of documents" ); indices.add( index[ i ].field ); if ( index[ i ].termProcessor != null ) termProcessors.put( index[ i ].field, index[ i ].termProcessor ); havePositions &= index[ i ].hasPositions;
@Override public DocumentIterator visit( Term node ) throws QueryBuilderVisitorException { try { // Get the current index reader for this node, or instantiate one lazily if necessary. IndexReader indexReader = term2IndexReader.get( node ); if ( indexReader == null ) term2IndexReader.put( node, indexReader = curr.top().getReader( bufferSize ) ); if ( node.term != null && marker.equals( node.term ) ) { return indexReader.documents( currentTerm ).weight( weight() ); } else if ( node.termNumber != -1 ) return indexReader.documents( node.termNumber ).weight( weight() ); return indexReader.documents( node.term ).weight( weight() ); } catch ( IOException e ) { throw new QueryBuilderVisitorException( e ); } }
@Override public DocumentIterator visit( Term node ) throws QueryBuilderVisitorException { try { // Get the current index reader for this node, or instantiate one lazily if necessary. IndexReader indexReader = term2IndexReader.get( node ); if ( indexReader == null ) term2IndexReader.put( node, indexReader = curr.top().getReader( bufferSize ) ); if ( node.term != null && marker.equals( node.term ) ) { return indexReader.documents( currentTerm ).weight( weight() ); } else if ( node.termNumber != -1 ) return indexReader.documents( node.termNumber ).weight( weight() ); return indexReader.documents( node.term ).weight( weight() ); } catch ( IOException e ) { throw new QueryBuilderVisitorException( e ); } }