/** * Method fieldToDouble returns a {@link Function} that returns the double in the given named field or position. * * @param fields the field to select, only first field will be honored * @return the double value in the selected field */ public static ToDoubleFunction<TupleEntry> fieldToDouble( Fields fields ) { Objects.requireNonNull( fields ); return value -> value.getDouble( fields ); }
/** * Method fieldToDouble returns a {@link Function} that returns the double in the given named field or position. * * @param name the field to select * @return the double value in the selected field */ public static ToDoubleFunction<TupleEntry> fieldToDouble( Comparable name ) { Objects.requireNonNull( name ); return value -> value.getDouble( name ); }
public double calculate( TupleEntry tupleEntry ) { return predictor.calculate( tupleEntry.getDouble( index ) ); } }
@Override public void aggregate( FlowProcess flowProcess, AggregatorCall<Context> aggregatorCall ) { Context context = aggregatorCall.getContext(); TupleEntry arguments = aggregatorCall.getArguments(); context.sum += arguments.getDouble( 0 ); context.count += 1L; }
aggregate[i] = 0D; aggregate[i] = ((Double)aggregate[i]) + nextValue.getDouble(i); break;
@Override public void aggregate( FlowProcess flowProcess, AggregatorCall<Pair<Double[], Tuple>> aggregatorCall ) { TupleEntry arguments = aggregatorCall.getArguments(); if( arguments.getObject( 0 ) == null ) return; Double[] sum = aggregatorCall.getContext().getLhs(); double value = sum[ 0 ] == null ? 0 : sum[ 0 ]; sum[ 0 ] = value + arguments.getDouble( 0 ); }
@Override public void operate( FlowProcess flowProcess, BufferCall<DecisionContext> bufferCall ) { double[] results = bufferCall.getContext().results; Arrays.fill( results, 0 ); // clear before use Iterator<TupleEntry> iterator = bufferCall.getArgumentsIterator(); int count = 0; while( iterator.hasNext() ) { TupleEntry next = iterator.next(); Double score = next.getDouble( 0 ); results[ count++ ] += score; } double prediction = selection.predict( results ); LOG.debug( "prediction: {}", prediction ); bufferCall.getOutputCollector().add( bufferCall.getContext().result( prediction ) ); } }
@Override public Tuple aggregate( FlowProcess flowProcess, TupleEntry args, Tuple context ) { if( context == null ) return args.getTupleCopy(); else if( args.getObject( 0 ) == null ) return context; context.set( 0, context.getDouble( 0 ) + args.getDouble( 0 ) ); return context; }
@Override public void aggregate( FlowProcess flowProcess, AggregatorCall<Context> aggregatorCall ) { Context context = aggregatorCall.getContext(); TupleEntry arguments = aggregatorCall.getArguments(); if( arguments.getObject( 0 ) == null ) { context.nulls++; return; } context.sum += arguments.getDouble( 0 ); context.count += arguments.getLong( 1 ); }
@Override public Tuple aggregate( FlowProcess flowProcess, TupleEntry args, Tuple context ) { if( context == null ) context = Tuple.size( 2 ); if( include == Include.NO_NULLS && args.getObject( 0 ) == null ) return context; context.set( 0, context.getDouble( 0 ) + args.getDouble( 0 ) ); context.set( 1, context.getLong( 1 ) + 1 ); return context; }
private void writePrimitive(TupleEntry record, PrimitiveType field) { switch (field.getPrimitiveTypeName()) { case BINARY: recordConsumer.addBinary(Binary.fromString(record.getString(field.getName()))); break; case BOOLEAN: recordConsumer.addBoolean(record.getBoolean(field.getName())); break; case INT32: recordConsumer.addInteger(record.getInteger(field.getName())); break; case INT64: recordConsumer.addLong(record.getLong(field.getName())); break; case DOUBLE: recordConsumer.addDouble(record.getDouble(field.getName())); break; case FLOAT: recordConsumer.addFloat(record.getFloat(field.getName())); break; case FIXED_LEN_BYTE_ARRAY: throw new UnsupportedOperationException("Fixed len byte array type not implemented"); case INT96: throw new UnsupportedOperationException("Int96 type not implemented"); default: throw new UnsupportedOperationException(field.getName() + " type not implemented"); } } }
private void writePrimitive(TupleEntry record, PrimitiveType field) { switch (field.getPrimitiveTypeName()) { case BINARY: recordConsumer.addBinary(Binary.fromString(record.getString(field.getName()))); break; case BOOLEAN: recordConsumer.addBoolean(record.getBoolean(field.getName())); break; case INT32: recordConsumer.addInteger(record.getInteger(field.getName())); break; case INT64: recordConsumer.addLong(record.getLong(field.getName())); break; case DOUBLE: recordConsumer.addDouble(record.getDouble(field.getName())); break; case FLOAT: recordConsumer.addFloat(record.getFloat(field.getName())); break; case FIXED_LEN_BYTE_ARRAY: throw new UnsupportedOperationException("Fixed len byte array type not implemented"); case INT96: throw new UnsupportedOperationException("Int96 type not implemented"); default: throw new UnsupportedOperationException(field.getName() + " type not implemented"); } } }
private void writePrimitive(TupleEntry record, PrimitiveType field) { switch (field.getPrimitiveTypeName()) { case BINARY: recordConsumer.addBinary(Binary.fromString(record.getString(field.getName()))); break; case BOOLEAN: recordConsumer.addBoolean(record.getBoolean(field.getName())); break; case INT32: recordConsumer.addInteger(record.getInteger(field.getName())); break; case INT64: recordConsumer.addLong(record.getLong(field.getName())); break; case DOUBLE: recordConsumer.addDouble(record.getDouble(field.getName())); break; case FLOAT: recordConsumer.addFloat(record.getFloat(field.getName())); break; case FIXED_LEN_BYTE_ARRAY: throw new UnsupportedOperationException("Fixed len byte array type not implemented"); case INT96: throw new UnsupportedOperationException("Int96 type not implemented"); default: throw new UnsupportedOperationException(field.getName() + " type not implemented"); } } }
private void writePrimitive(TupleEntry record, PrimitiveType field) { switch (field.getPrimitiveTypeName()) { case BINARY: recordConsumer.addBinary(Binary.fromString(record.getString(field.getName()))); break; case BOOLEAN: recordConsumer.addBoolean(record.getBoolean(field.getName())); break; case INT32: recordConsumer.addInteger(record.getInteger(field.getName())); break; case INT64: recordConsumer.addLong(record.getLong(field.getName())); break; case DOUBLE: recordConsumer.addDouble(record.getDouble(field.getName())); break; case FLOAT: recordConsumer.addFloat(record.getFloat(field.getName())); break; case FIXED_LEN_BYTE_ARRAY: throw new UnsupportedOperationException("Fixed len byte array type not implemented"); case INT96: throw new UnsupportedOperationException("Int96 type not implemented"); default: throw new UnsupportedOperationException(field.getName() + " type not implemented"); } } }
@Test public void testCoerceCanonicalUnknown() { Tuple tuple = new Tuple( 1 ); TupleEntry results = new TupleEntry( Fields.UNKNOWN, tuple ); assertEquals( 1, results.getObject( 0 ) ); assertEquals( 1, results.getInteger( 0 ) ); assertEquals( 1, results.getShort( 0 ) ); assertEquals( 1L, results.getLong( 0 ) ); assertEquals( 1.0F, results.getFloat( 0 ) ); assertEquals( 1.0D, results.getDouble( 0 ) ); assertEquals( "1", results.getString( 0 ) ); }