it.unimi.dsi.fastutil.floats.FloatArrayList Java Examples

The following examples show how to use it.unimi.dsi.fastutil.floats.FloatArrayList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvroRecordConverter.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
@Override
public void end() {
  if (elementClass == boolean.class) {
    parent.add(((BooleanArrayList) container).toBooleanArray());
  } else if (elementClass == byte.class) {
    parent.add(((ByteArrayList) container).toByteArray());
  } else if (elementClass == char.class) {
    parent.add(((CharArrayList) container).toCharArray());
  } else if (elementClass == short.class) {
    parent.add(((ShortArrayList) container).toShortArray());
  } else if (elementClass == int.class) {
    parent.add(((IntArrayList) container).toIntArray());
  } else if (elementClass == long.class) {
    parent.add(((LongArrayList) container).toLongArray());
  } else if (elementClass == float.class) {
    parent.add(((FloatArrayList) container).toFloatArray());
  } else if (elementClass == double.class) {
    parent.add(((DoubleArrayList) container).toDoubleArray());
  } else {
    parent.add(((ArrayList) container).toArray());
  }
}
 
Example #2
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Override
public FloatColumn lag(int n) {
  final int srcPos = n >= 0 ? 0 : 0 - n;
  final float[] dest = new float[size()];
  final int destPos = n <= 0 ? 0 : n;
  final int length = n >= 0 ? size() - n : size() + n;

  for (int i = 0; i < size(); i++) {
    dest[i] = FloatColumnType.missingValueIndicator();
  }

  float[] array = data.toFloatArray();

  System.arraycopy(array, srcPos, dest, destPos, length);
  return new FloatColumn(name() + " lag(" + n + ")", new FloatArrayList(dest));
}
 
Example #3
Source File: RatingTask.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
protected FloatList recommend(Model recommender, int userIndex) {
    ReferenceModule testModule = testModules[userIndex];
    ArrayInstance copy = new ArrayInstance(testMarker.getQualityOrder(), testMarker.getQuantityOrder());
    List<Integer2FloatKeyValue> rateList = new ArrayList<>(testModule.getSize());
    for (DataInstance instance : testModule) {
        copy.copyInstance(instance);
        recommender.predict(copy);
        rateList.add(new Integer2FloatKeyValue(copy.getQualityFeature(itemDimension), copy.getQuantityMark()));
    }

    FloatList recommendList = new FloatArrayList(rateList.size());
    for (Integer2FloatKeyValue keyValue : rateList) {
        recommendList.add(keyValue.getValue());
    }
    return recommendList;
}
 
Example #4
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Override
public FloatColumn lag(int n) {
  final int srcPos = n >= 0 ? 0 : 0 - n;
  final float[] dest = new float[size()];
  final int destPos = n <= 0 ? 0 : n;
  final int length = n >= 0 ? size() - n : size() + n;

  for (int i = 0; i < size(); i++) {
    dest[i] = FloatColumnType.missingValueIndicator();
  }

  float[] array = data.toFloatArray();

  System.arraycopy(array, srcPos, dest, destPos, length);
  return new FloatColumn(name() + " lag(" + n + ")", new FloatArrayList(dest));
}
 
Example #5
Source File: FloatDataSet.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Initialises the data set with specified data.
 * </p>
 * Note: The method copies values from specified double arrays.
 *
 * @param xValues X coordinates
 * @param yValues Y coordinates
 * @param nSamples number of samples to be copied
 * @param copy true: makes an internal copy, false: use the pointer as is (saves memory allocation
 * @return itself
 */
public FloatDataSet set(final float[] xValues, final float[] yValues, final int nSamples, final boolean copy) {
    AssertUtils.notNull("X coordinates", xValues);
    AssertUtils.notNull("Y coordinates", yValues);
    AssertUtils.equalFloatArrays(xValues, yValues);
    if (nSamples >= 0) {
        AssertUtils.indexInBounds(nSamples, xValues.length + 1, "xValues bounds");
        AssertUtils.indexInBounds(nSamples, yValues.length + 1, "yValues bounds");
    }
    final int nSamplesToAdd = nSamples >= 0 ? Math.min(nSamples, xValues.length) : xValues.length;

    lock().writeLockGuard(() -> {
        getDataLabelMap().clear();
        getDataStyleMap().clear();
        if (copy) {
            if (this.xValues == null) {
                this.xValues = new FloatArrayList();
            }
            if (this.yValues == null) {
                this.yValues = new FloatArrayList();
            }
            resize(0);

            this.xValues.addElements(0, xValues, 0, nSamplesToAdd);
            this.yValues.addElements(0, yValues, 0, nSamplesToAdd);
        } else {
            this.xValues = FloatArrayList.wrap(xValues, nSamplesToAdd);
            this.yValues = FloatArrayList.wrap(yValues, nSamplesToAdd);
        }

        // invalidate ranges
        getAxisDescriptions().forEach(AxisDescription::clear);
    });
    return fireInvalidated(new UpdatedDataEvent(this));
}
 
Example #6
Source File: ValueInTransformFunction.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private static float[] filterFloats(FloatSet floatSet, float[] source) {
  FloatList floatList = new FloatArrayList();
  for (float value : source) {
    if (floatSet.contains(value)) {
      floatList.add(value);
    }
  }
  if (floatList.size() == source.length) {
    return source;
  } else {
    return floatList.toFloatArray();
  }
}
 
Example #7
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
public static FloatColumn create(String name, int initialSize) {
  FloatColumn column = new FloatColumn(name, new FloatArrayList(initialSize));
  for (int i = 0; i < initialSize; i++) {
    column.appendMissing();
  }
  return column;
}
 
Example #8
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
public static FloatColumn create(String name, int initialSize) {
  FloatColumn column = new FloatColumn(name, new FloatArrayList(initialSize));
  for (int i = 0; i < initialSize; i++) {
    column.appendMissing();
  }
  return column;
}
 
Example #9
Source File: LuceneEngine.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
/**
 * 检索文档
 * 
 * @param query
 * @param sort
 * @param offset
 * @param size
 * @return
 */
public KeyValue<List<Document>, FloatList> retrieveDocuments(Query query, Sort sort, int offset, int size) {
    try {
        readLock.lock();
        lockRead();
        synchronized (this.semaphore) {
            if (this.transienceManager.isChanged() || this.persistenceManager.isChanged()) {
                this.searcher = new LuceneSearcher(this.transienceManager, this.persistenceManager);
            }
        }
        ScoreDoc[] search = null;
        int begin = offset;
        int end = offset + size;
        if (sort == null) {
            search = this.searcher.search(query, end).scoreDocs;
        } else {
            search = this.searcher.search(query, end, sort).scoreDocs;
        }
        end = search.length;
        size = end - begin;
        size = size < 0 ? 0 : size;
        ArrayList<Document> documents = new ArrayList<>(size);
        FloatList scores = new FloatArrayList(size);
        for (int index = begin; index < end; index++) {
            ScoreDoc score = search[index];
            Document document = this.searcher.doc(score.doc);
            documents.add(document);
            scores.add(score.score);
        }
        return new KeyValue<>(documents, scores);
    } catch (Exception exception) {
        throw new StorageException(exception);
    } finally {
        unlockRead();
        readLock.unlock();
    }
}
 
Example #10
Source File: AbstractRatingEvaluatorTestCase.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
@Override
protected FloatList getRight(MathVector vector) {
    FloatList recommendList = new FloatArrayList(vector.getElementSize());
    for (VectorScalar scalar : vector) {
        if (RandomUtility.randomFloat(1F) < 0.5F) {
            recommendList.add(scalar.getValue());
        } else {
            recommendList.add(scalar.getValue() * 0.5F);
        }
    }
    return recommendList;
}
 
Example #11
Source File: AbstractRatingEvaluatorTestCase.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
@Override
protected FloatList getLeft(MathVector vector) {
    FloatList scoreList = new FloatArrayList(vector.getElementSize());
    for (VectorScalar scalar : vector) {
        scoreList.add(scalar.getValue());
    }
    return scoreList;
}
 
Example #12
Source File: RatingTask.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
protected FloatList check(int userIndex) {
    ReferenceModule testModule = testModules[userIndex];
    FloatList scoreList = new FloatArrayList(testModule.getSize());
    for (DataInstance instance : testModule) {
        scoreList.add(instance.getQuantityMark());
    }
    return scoreList;
}
 
Example #13
Source File: PersonalityDiagnosisModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
/**
 * initialization
 *
 * @throws ModelException if error occurs
 */
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    prior = 1F / userSize;
    sigma = configuration.getFloat("recommender.PersonalityDiagnosis.sigma");

    FloatSet sorts = new FloatRBTreeSet();
    for (MatrixScalar term : scoreMatrix) {
        sorts.add(term.getValue());
    }
    sorts.remove(0F);
    scores = new FloatArrayList(sorts);
}
 
Example #14
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
private FloatColumn(String name, FloatArrayList data) {
  super(FloatColumnType.instance(), name);
  setPrintFormatter(NumberColumnFormatter.floatingPointDefault());
  this.data = data;
}
 
Example #15
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
public static FloatColumn create(String name) {
  return new FloatColumn(name, new FloatArrayList());
}
 
Example #16
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
public static FloatColumn create(String name, float... arr) {
  return new FloatColumn(name, new FloatArrayList(arr));
}
 
Example #17
Source File: AttributeStores.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
FloatAttributeStore(AttributeInfo attrInfo) {
    super(attrInfo);
    this.list = new FloatArrayList();
}
 
Example #18
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
private FloatColumn(String name, FloatArrayList data) {
  super(FloatColumnType.instance(), name);
  setPrintFormatter(NumberColumnFormatter.floatingPointDefault());
  this.data = data;
}
 
Example #19
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
public static FloatColumn create(String name) {
  return new FloatColumn(name, new FloatArrayList());
}
 
Example #20
Source File: FloatColumn.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
public static FloatColumn create(String name, float... arr) {
  return new FloatColumn(name, new FloatArrayList(arr));
}
 
Example #21
Source File: FloatToIdMap.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public FloatToIdMap() {
  _valueToIdMap = new Float2IntOpenHashMap();
  _valueToIdMap.defaultReturnValue(INVALID_KEY);
  _idToValueMap = new FloatArrayList();
}
 
Example #22
Source File: ArbiterStatusListener.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public void onCandidateIteration(CandidateInfo candidateInfo, Object candidate, int iteration) {
    double score;
    long numParams;
    int numLayers;
    String modelConfigJson;
    int totalNumUpdates;
    if(candidate instanceof MultiLayerNetwork){
        MultiLayerNetwork m = (MultiLayerNetwork)candidate;
        score = m.score();
        numParams = m.numParams();
        numLayers = m.getnLayers();
        modelConfigJson = m.getLayerWiseConfigurations().toJson();
        totalNumUpdates = m.getLayerWiseConfigurations().getIterationCount();
    } else if(candidate instanceof ComputationGraph) {
        ComputationGraph cg = (ComputationGraph)candidate;
        score = cg.score();
        numParams = cg.numParams();
        numLayers = cg.getNumLayers();
        modelConfigJson = cg.getConfiguration().toJson();
        totalNumUpdates = cg.getConfiguration().getIterationCount();
    } else {
        score = 0;
        numParams = 0;
        numLayers = 0;
        totalNumUpdates = 0;
        modelConfigJson = "";
    }

    int idx = candidateInfo.getIndex();

    Pair<IntArrayList, FloatArrayList> pair = candidateScoreVsIter.computeIfAbsent(idx, k -> new Pair<>(new IntArrayList(), new FloatArrayList()));

    IntArrayList iter = pair.getFirst();
    FloatArrayList scores = pair.getSecond();

    //Do we need subsampling to avoid having too many data points?
    int subsamplingFreq = candidateScoreVsIterSubsampleFreq.computeIfAbsent(idx, k -> 1);
    if(iteration / subsamplingFreq > MAX_SCORE_VS_ITER_PTS){
        //Double subsampling frequency and re-parse data
        subsamplingFreq *= 2;
        candidateScoreVsIterSubsampleFreq.put(idx, subsamplingFreq);

        IntArrayList newIter = new IntArrayList();
        FloatArrayList newScores = new FloatArrayList();
        for( int i=0; i<iter.size(); i++ ){
            int it = iter.get(i);
            if(it % subsamplingFreq == 0){
                newIter.add(it);
                newScores.add(scores.get(i));
            }
        }

        iter = newIter;
        scores = newScores;
        candidateScoreVsIter.put(idx, new Pair<>(iter, scores));
    }

    if(iteration % subsamplingFreq == 0) {
        iter.add(iteration);
        scores.add((float) score);
    }


    int[] iters = iter.toIntArray();
    float[] fScores = new float[iters.length];
    for( int i=0; i<iters.length; i++ ){
        fScores[i] = scores.get(i);
    }

    ModelInfoPersistable p = new ModelInfoPersistable.Builder()
            .timestamp(candidateInfo.getCreatedTime())
            .sessionId(sessionId)
            .workerId(String.valueOf(candidateInfo.getIndex()))
            .modelIdx(candidateInfo.getIndex())
            .score(candidateInfo.getScore())
            .status(candidateInfo.getCandidateStatus())
            .scoreVsIter(iters, fScores)
            .lastUpdateTime(System.currentTimeMillis())
            .numParameters(numParams)
            .numLayers(numLayers)
            .totalNumUpdates(totalNumUpdates)
            .paramSpaceValues(candidateInfo.getFlatParams())
            .modelConfigJson(modelConfigJson)
            .exceptionStackTrace(candidateInfo.getExceptionStackTrace())
            .build();


    lastModelInfoPersistable.put(candidateInfo.getIndex(), p);
    statsStorage.putUpdate(p);
}
 
Example #23
Source File: FloatDataSet.java    From chart-fx with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new instance of <code>FloatDataSet</code>.
 *
 * @param name name of this DataSet.
 * @param initalSize initial buffer size
 * @throws IllegalArgumentException if <code>name</code> is <code>null</code>
 */
public FloatDataSet(final String name, final int initalSize) {
    super(name, 2);
    AssertUtils.gtEqThanZero("initalSize", initalSize);
    xValues = new FloatArrayList(initalSize);
    yValues = new FloatArrayList(initalSize);
}