org.datavec.api.writable.FloatWritable Java Examples
The following examples show how to use
org.datavec.api.writable.FloatWritable.
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: NativeAudioRecordReader.java From DataVec with Apache License 2.0 | 6 votes |
protected List<Writable> loadData(File file, InputStream inputStream) throws IOException { List<Writable> ret = new ArrayList<>(); try (FFmpegFrameGrabber grabber = inputStream != null ? new FFmpegFrameGrabber(inputStream) : new FFmpegFrameGrabber(file.getAbsolutePath())) { grabber.setSampleFormat(AV_SAMPLE_FMT_FLT); grabber.start(); Frame frame; while ((frame = grabber.grab()) != null) { while (frame.samples != null && frame.samples[0].hasRemaining()) { for (int i = 0; i < frame.samples.length; i++) { ret.add(new FloatWritable(((FloatBuffer) frame.samples[i]).get())); } } } } return ret; }
Example #2
Source File: NativeAudioRecordReader.java From deeplearning4j with Apache License 2.0 | 6 votes |
protected List<Writable> loadData(File file, InputStream inputStream) throws IOException { List<Writable> ret = new ArrayList<>(); try (FFmpegFrameGrabber grabber = inputStream != null ? new FFmpegFrameGrabber(inputStream) : new FFmpegFrameGrabber(file.getAbsolutePath())) { grabber.setSampleFormat(AV_SAMPLE_FMT_FLT); grabber.start(); Frame frame; while ((frame = grabber.grab()) != null) { while (frame.samples != null && frame.samples[0].hasRemaining()) { for (int i = 0; i < frame.samples.length; i++) { ret.add(new FloatWritable(((FloatBuffer) frame.samples[i]).get())); } } } } return ret; }
Example #3
Source File: FeatureRecordReader.java From FancyBing with GNU General Public License v3.0 | 5 votes |
protected List<Writable> parseLine(String line) { String[] split = line.split(LABEL_DELIMITER, -1); float clsLabel = Float.parseFloat(split[0]); float regLabel = Float.parseFloat(split[1]); List<Writable> ret = new ArrayList<>(); char[] chs = split[2].toCharArray(); int rotation = RANDOM.nextInt(8); chs = transfer(chs, rotation); int v = 0; for (int i = 0; i < chs.length; i++) { v = Integer.parseInt(Character.toString(chs[i])); if (i < 8 * 361 || i >= 9 * 361) { ret.add(new FloatWritable(v)); } else { if (v > 1) { ret.add(new FloatWritable((float)(Math.exp(-(v-1) * 0.1)))); } else { ret.add(new FloatWritable(v)); } } } ret.add(new IntWritable(rotateIndex((int) clsLabel, rotation))); // class label ret.add(new FloatWritable(regLabel)); // value regression label return ret; }
Example #4
Source File: JDBCRecordReaderTest.java From DataVec with Apache License 2.0 | 5 votes |
@Test public void testReadAllTypes() throws Exception { TestDb.buildAllTypesTable(conn); try (JDBCRecordReader reader = new JDBCRecordReader("SELECT * FROM AllTypes", dataSource)) { reader.initialize(null); List<Writable> item = reader.next(); assertEquals(item.size(), 15); assertEquals(BooleanWritable.class, item.get(0).getClass()); // boolean to boolean assertEquals(Text.class, item.get(1).getClass()); // date to text assertEquals(Text.class, item.get(2).getClass()); // time to text assertEquals(Text.class, item.get(3).getClass()); // timestamp to text assertEquals(Text.class, item.get(4).getClass()); // char to text assertEquals(Text.class, item.get(5).getClass()); // long varchar to text assertEquals(Text.class, item.get(6).getClass()); // varchar to text assertEquals(DoubleWritable.class, item.get(7).getClass()); // float to double (derby's float is an alias of double by default) assertEquals(FloatWritable.class, item.get(8).getClass()); // real to float assertEquals(DoubleWritable.class, item.get(9).getClass()); // decimal to double assertEquals(DoubleWritable.class, item.get(10).getClass()); // numeric to double assertEquals(DoubleWritable.class, item.get(11).getClass()); // double to double assertEquals(IntWritable.class, item.get(12).getClass()); // integer to integer assertEquals(IntWritable.class, item.get(13).getClass()); // small int to integer assertEquals(LongWritable.class, item.get(14).getClass()); // bigint to long } }
Example #5
Source File: RecordUtils.java From DataVec with Apache License 2.0 | 5 votes |
public static List<Writable> toRecord(float[] record) { List<Writable> ret = new ArrayList<>(record.length); for (int i = 0; i < record.length; i++) ret.add(new FloatWritable(record[i])); return ret; }
Example #6
Source File: JDBCRecordReaderTest.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testReadAllTypes() throws Exception { TestDb.buildAllTypesTable(conn); try (JDBCRecordReader reader = new JDBCRecordReader("SELECT * FROM AllTypes", dataSource)) { reader.initialize(null); List<Writable> item = reader.next(); assertEquals(item.size(), 15); assertEquals(BooleanWritable.class, item.get(0).getClass()); // boolean to boolean assertEquals(Text.class, item.get(1).getClass()); // date to text assertEquals(Text.class, item.get(2).getClass()); // time to text assertEquals(Text.class, item.get(3).getClass()); // timestamp to text assertEquals(Text.class, item.get(4).getClass()); // char to text assertEquals(Text.class, item.get(5).getClass()); // long varchar to text assertEquals(Text.class, item.get(6).getClass()); // varchar to text assertEquals(DoubleWritable.class, item.get(7).getClass()); // float to double (derby's float is an alias of double by default) assertEquals(FloatWritable.class, item.get(8).getClass()); // real to float assertEquals(DoubleWritable.class, item.get(9).getClass()); // decimal to double assertEquals(DoubleWritable.class, item.get(10).getClass()); // numeric to double assertEquals(DoubleWritable.class, item.get(11).getClass()); // double to double assertEquals(IntWritable.class, item.get(12).getClass()); // integer to integer assertEquals(IntWritable.class, item.get(13).getClass()); // small int to integer assertEquals(LongWritable.class, item.get(14).getClass()); // bigint to long } }
Example #7
Source File: ConvertToFloat.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public FloatWritable map(Writable writable) { if(writable.getType() == WritableType.Double){ return (FloatWritable)writable; } return new FloatWritable(writable.toFloat()); }
Example #8
Source File: RecordUtils.java From deeplearning4j with Apache License 2.0 | 5 votes |
public static List<Writable> toRecord(float[] record) { List<Writable> ret = new ArrayList<>(record.length); for (int i = 0; i < record.length; i++) ret.add(new FloatWritable(record[i])); return ret; }
Example #9
Source File: EvalTest.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testEvalSplitting2(){ List<List<Writable>> seqFeatures = new ArrayList<>(); List<Writable> step = Arrays.<Writable>asList(new FloatWritable(0), new FloatWritable(0), new FloatWritable(0)); for( int i=0; i<30; i++ ){ seqFeatures.add(step); } List<List<Writable>> seqLabels = Collections.singletonList(Collections.<Writable>singletonList(new FloatWritable(0))); SequenceRecordReader fsr = new CollectionSequenceRecordReader(Collections.singletonList(seqFeatures)); SequenceRecordReader lsr = new CollectionSequenceRecordReader(Collections.singletonList(seqLabels)); DataSetIterator testData = new SequenceRecordReaderDataSetIterator(fsr, lsr, 1, -1, true, SequenceRecordReaderDataSetIterator.AlignmentMode.ALIGN_END); MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123) .list() .layer(0, new LSTM.Builder().activation(Activation.TANH).nIn(3).nOut(3).build()) .layer(1, new RnnOutputLayer.Builder().activation(Activation.SIGMOID).lossFunction(LossFunctions.LossFunction.XENT) .nIn(3).nOut(1).build()) .backpropType(BackpropType.TruncatedBPTT).tBPTTForwardLength(10).tBPTTBackwardLength(10) .build(); MultiLayerNetwork net = new MultiLayerNetwork(conf); net.init(); net.evaluate(testData); }
Example #10
Source File: JdbcWritableConverter.java From DataVec with Apache License 2.0 | 4 votes |
public static Writable convert(final Object columnValue, final int columnType) { switch (columnType) { case Types.BOOLEAN: return new BooleanWritable((boolean) columnValue); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: case Types.CHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.VARCHAR: return new Text(columnValue.toString()); case Types.FLOAT: case Types.REAL: return new FloatWritable((float) columnValue); case Types.DECIMAL: case Types.NUMERIC: return new DoubleWritable(((BigDecimal) columnValue).doubleValue()); //!\ This may overflow case Types.DOUBLE: return new DoubleWritable((double) columnValue); case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: return new IntWritable((int) columnValue); case Types.BIT: return new BooleanWritable((boolean) columnValue); case Types.BIGINT: return new LongWritable((long) columnValue); default: throw new IllegalArgumentException("Column type unknown"); } }
Example #11
Source File: JdbcWritableConverter.java From deeplearning4j with Apache License 2.0 | 4 votes |
public static Writable convert(final Object columnValue, final int columnType) { if (columnValue == null) return new NullWritable(); switch (columnType) { case Types.BOOLEAN: return new BooleanWritable((boolean) columnValue); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: case Types.CHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.VARCHAR: return new Text(columnValue.toString()); case Types.FLOAT: return new FloatWritable((float) columnValue); case Types.REAL: return columnValue instanceof Float ? new FloatWritable((float) columnValue) : new DoubleWritable((double) columnValue); case Types.DECIMAL: case Types.NUMERIC: return new DoubleWritable(((BigDecimal) columnValue).doubleValue()); //!\ This may overflow case Types.DOUBLE: return new DoubleWritable((double) columnValue); case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: return new IntWritable((int) columnValue); case Types.BIT: return new BooleanWritable((boolean) columnValue); case Types.BIGINT: return new LongWritable((long) columnValue); default: throw new IllegalArgumentException("Column type unknown"); } }
Example #12
Source File: FloatMathFunctionTransform.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public Writable map(Writable w) { switch (mathFunction) { case ABS: return new FloatWritable(Math.abs(w.toFloat())); case ACOS: return new FloatWritable((float)Math.acos(w.toFloat())); case ASIN: return new FloatWritable((float)Math.asin(w.toFloat())); case ATAN: return new FloatWritable((float)Math.atan(w.toFloat())); case CEIL: return new FloatWritable((float)Math.ceil(w.toFloat())); case COS: return new FloatWritable((float)Math.cos(w.toFloat())); case COSH: return new FloatWritable((float)Math.cosh(w.toFloat())); case EXP: return new FloatWritable((float)Math.exp(w.toFloat())); case FLOOR: return new FloatWritable((float)Math.floor(w.toFloat())); case LOG: return new FloatWritable((float)Math.log(w.toFloat())); case LOG10: return new FloatWritable((float)Math.log10(w.toFloat())); case SIGNUM: return new FloatWritable(Math.signum(w.toFloat())); case SIN: return new FloatWritable((float)Math.sin(w.toFloat())); case SINH: return new FloatWritable((float)Math.sinh(w.toFloat())); case SQRT: return new FloatWritable((float)Math.sqrt(w.toFloat())); case TAN: return new FloatWritable((float)Math.tan(w.toFloat())); case TANH: return new FloatWritable((float)Math.tanh(w.toFloat())); default: throw new RuntimeException("Unknown function: " + mathFunction); } }
Example #13
Source File: FloatMathOpTransform.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public Writable map(Writable columnWritable) { return new FloatWritable(doOp(columnWritable.toFloat())); }