@Override public FloatColumn top(int n) { FloatArrayList top = new FloatArrayList(); float[] values = data.toFloatArray(); FloatArrays.parallelQuickSort(values, descendingComparator); for (int i = 0; i < n && i < values.length; i++) { top.add(values[i]); } return new FloatColumn(name() + "[Top " + n + "]", top); }
@Override public int size() { return data.size(); }
public FloatColumn set(int i, float val) { data.set(i, val); return this; }
/** * Returns a new FloatColumn containing a value for each value in this column, truncating if necessary. * * A widening primitive conversion from an int to a float does not lose information about the overall magnitude * of a numeric value. It may, however, result in loss of precision - that is, the result may lose some of the * least significant bits of the value. In this case, the resulting floating-point value will be a correctly * rounded version of the integer value, using IEEE 754 round-to-nearest mode. * * Despite the fact that a loss of precision may occur, a widening primitive conversion never results in a * run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public FloatColumn asFloatColumn() { FloatArrayList values = new FloatArrayList(); for (int d : data) { values.add(d); } values.trim(); return FloatColumn.create(this.name(), values.elements()); }
@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)); }
public FloatArrayList toFloatArray() { FloatArrayList output = new FloatArrayList(data.size()); for (long aData : data) { output.add(aData); } return output; }
private void execute(){ Spectrum spec; FloatArrayList pixelsValues = new FloatArrayList(); FloatArrayList meanValues = new FloatArrayList(); for (String sourceBand : this.sourceBands) { pixelsValues.clear(); Band band = this.sourceProduct.getBand(sourceBand); for (int intIndex = 0; intIndex < this.spectrumClassReferencePixels.getXPixelPositions().size(); intIndex++) { int x = this.spectrumClassReferencePixels.getXPixelPositions().getInt(intIndex); int y = this.spectrumClassReferencePixels.getYPixelPositions().getInt(intIndex); pixelsValues.add(band.getSampleFloat(x, y)); } double sum = 0; for (float value : pixelsValues) { sum += value; } meanValues.add((float) sum / pixelsValues.size()); } spec = new Spectrum(spectrumClassReferencePixels.getClassName(), meanValues.toFloatArray(new float[meanValues.size()])); this.spectrumContainer.addElements(spec); }
public static FloatColumn create(final String name) { return new FloatColumn(name, new FloatArrayList()); }
public FloatColumn append(float i) { data.add(i); return this; }
public static FloatColumn create(String name, FloatArrayList floats) { FloatColumn column = new FloatColumn(name, floats.size()); column.data = new FloatArrayList(floats.size()); column.data.addAll(floats); return column; }
public Features(int numFeatures) { this.values = new FloatArrayList(numFeatures); this.values.size(numFeatures); }
/** * Add the vector specified. This is a vector addition that does an * element-by-element addition. * * @param other the vector to add. */ public void add(FloatDenseVector other) { if (isSingleton) { throw new RuntimeException("Cannot add to singleton vector"); } if (other.isSingleton) { ensureCapacity(other.singletonIndex + 1); entries.set(other.singletonIndex, entries.getFloat(other.singletonIndex) + other.singletonValue); } else { ensureCapacity(other.entries.size()); for (int i = 0; i < other.entries.size(); ++i) { entries.set(i, entries.getFloat(i) + other.entries.getFloat(i)); } } }
/** * Returns a float representation of the data at the given index. Some precision may be lost, and if the value is * to large to be cast to a float, an exception is thrown. * * @throws ClassCastException if the value can't be cast to ta float */ public float getFloat(int row) { return data.getFloat(row); }
private FloatArrayList getModelInternalActivations(INDArray testFeatures) { FloatArrayList floats = new FloatArrayList(); predictiveModel.feedForward(testFeatures).stream().forEach(indArray -> floats.addAll(FloatArrayList.wrap(indArray.data().asFloat()))); return floats; }
public void prepareToNormalize(RecordType record, int indexOfRecord) { mean = 0; stdev = 0; int count = 0; delegate.prepareToNormalize(record, indexOfRecord); values.clear(); for (int i = 0; i < numberOfFeatures(); i++) { final float v = delegate.produceFeature(record, i); values.add(v); mean += v; count += 1; } mean /= count; double variance = 0; for (double value : values) { final double difference = value - mean; variance += difference * difference; } stdev = Math.sqrt(variance); delegate.prepareToNormalize(record, indexOfRecord); normalizedCalled = true; }
private void serializeList(final DataOutput out, final List list) throws IOException { Class oCls = list.getClass(); if (oCls.equals(IntArrayList.class)) { serialize(out, ((IntArrayList) list).toIntArray()); } else if (oCls.equals(FloatArrayList.class)) { serialize(out, ((FloatArrayList) list).toFloatArray()); } else if (oCls.equals(DoubleArrayList.class)) { serialize(out, ((DoubleArrayList) list).toDoubleArray()); } else if (oCls.equals(ShortArrayList.class)) { serialize(out, ((ShortArrayList) list).toShortArray()); } else if (oCls.equals(ByteArrayList.class)) { serialize(out, ((ByteArrayList) list).toByteArray()); } else if (oCls.equals(LongArrayList.class)) { serialize(out, ((LongArrayList) list).toLongArray()); } else if (oCls.equals(BooleanArrayList.class)) { serialize(out, ((BooleanArrayList) list).toBooleanArray()); } else if (oCls.equals(CharArrayList.class)) { serialize(out, ((CharArrayList) list).toCharArray()); } else { serialize(out, list.size()); for (Object obj : list) { serialize(out, obj); } } }
float[] vectorElementsArray = new float[vectorLine.getVectorElements().size()]; vectorElementsArray = vectorLine.getVectorElements().toArray(vectorElementsArray); int[] vectorShape = vectorProperties.getVectors()[vectorLine.getVectorId()].getVectorDimension(); vectorArrays[vectorIndexInArray] = Nd4j.create(vectorElementsArray, vectorShape, 'c');