use of org.apache.ignite.ml.math.exceptions.preprocessing.NonDoubleVectorException in project ignite by apache.
the class SimpleDatasetDataBuilder method build.
/**
* {@inheritDoc}
*/
@Override
public SimpleDatasetData build(LearningEnvironment env, Iterator<UpstreamEntry<K, V>> upstreamData, long upstreamDataSize, C ctx) {
// Prepares the matrix of features in flat column-major format.
int cols = -1;
double[] features = null;
int ptr = 0;
while (upstreamData.hasNext()) {
UpstreamEntry<K, V> entry = upstreamData.next();
Vector row = preprocessor.apply(entry.getKey(), entry.getValue()).features();
if (row.isNumeric()) {
if (cols < 0) {
cols = row.size();
features = new double[Math.toIntExact(upstreamDataSize * cols)];
} else
assert row.size() == cols : "Feature extractor must return exactly " + cols + " features";
for (int i = 0; i < cols; i++) features[Math.toIntExact(i * upstreamDataSize + ptr)] = row.get(i);
ptr++;
} else
throw new NonDoubleVectorException(row);
}
return new SimpleDatasetData(features, Math.toIntExact(upstreamDataSize));
}
Aggregations