List of usage examples for org.apache.hadoop.io DoubleWritable DoubleWritable
public DoubleWritable(double value)
From source file:hd_knn.KNN_MediaVecinos.java
@Override public HD_KNN.DistanceClassOutput getReducerOutput(HD_KNN.DistanceClassOutput[] nearest) { //MEDIA//from w w w . j a va2s . c o m HashMap<Text, ArrayList<Double>> nearest_map = new HashMap<>(); for (HD_KNN.DistanceClassOutput dco : nearest) { if (nearest_map.get(dco.instanceClass) == null) { nearest_map.put(dco.instanceClass, new ArrayList<Double>()); } nearest_map.get(dco.instanceClass).add(dco.distance.get()); } Text res_class = new Text("-1"); double min_d = Double.MAX_VALUE; for (Text ic : nearest_map.keySet()) { double s = 0; for (double d : nearest_map.get(ic)) { s += d; } s /= nearest_map.get(ic).size(); if (s < min_d) { res_class = ic; min_d = s; } } return new HD_KNN.DistanceClassOutput(res_class, new DoubleWritable(min_d)); }
From source file:hd_knn.KNN_Normal.java
@Override public HD_KNN.DistanceClassOutput getReducerOutput(HD_KNN.DistanceClassOutput[] nearest) { HashMap<String, Integer> nearest_map = new HashMap<>(); HashMap<String, Double> distances = new HashMap<>(); for (HD_KNN.DistanceClassOutput dco : nearest) { nearest_map.put(dco.instanceClass.toString(), 0); distances.put(dco.instanceClass.toString(), Double.MAX_VALUE); }//w ww . j av a 2 s. c om for (HD_KNN.DistanceClassOutput dco : nearest) { double dist = distances.get(dco.instanceClass.toString()); if (dco.distance.get() < dist) { distances.put(dco.instanceClass.toString(), dco.distance.get()); } nearest_map.put(dco.instanceClass.toString(), nearest_map.get(dco.instanceClass.toString()) + 1); } Text res_class = new Text("-1"); int max = -1; for (String ic : nearest_map.keySet()) { int n = nearest_map.get(ic); if (n > max) { res_class = new Text(ic); max = n; } } return new HD_KNN.DistanceClassOutput(res_class, new DoubleWritable(distances.get(res_class.toString()))); }
From source file:hd_knn.KNN_VotoInverso.java
@Override public HD_KNN.DistanceClassOutput getReducerOutput(HD_KNN.DistanceClassOutput[] nearest) { //MEDIA/*from ww w . j a va 2 s .c o m*/ HashMap<Text, ArrayList<Double>> nearest_map = new HashMap<>(); for (HD_KNN.DistanceClassOutput dco : nearest) { if (nearest_map.get(dco.instanceClass) == null) { nearest_map.put(dco.instanceClass, new ArrayList<Double>()); } if (dco.distance.get() == 0) { nearest_map.get(dco.instanceClass).add(Double.MAX_VALUE); } else { nearest_map.get(dco.instanceClass).add(1 / dco.distance.get()); } } Text res_class = new Text("-1"); double max = -1; for (Text ic : nearest_map.keySet()) { double s = 0; for (double d : nearest_map.get(ic)) { s += d; } if (s > max) { res_class = ic; max = s; } } return new HD_KNN.DistanceClassOutput(res_class, new DoubleWritable(max)); }
From source file:hivemall.ftvec.FeatureUDFTest.java
License:Apache License
@Test public void testTextDoubleWritable() throws Exception { ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector weightOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; udf.initialize(new ObjectInspector[] { featureOI, weightOI }); Text ret = udf.evaluate(new GenericUDF.DeferredObject[] { new DeferredJavaObject(new Text("f1")), new DeferredJavaObject(new DoubleWritable(2.5d)) }); Assert.assertEquals("f1:2.5", ret.toString()); }
From source file:hydrograph.engine.cascading.scheme.hive.parquet.ParquetWritableUtils.java
License:Apache License
private static Writable createPrimitive(final Object obj, final PrimitiveObjectInspector inspector) throws SerDeException { if (obj == null) { return null; }/*from w w w.j av a 2 s . co m*/ switch (inspector.getPrimitiveCategory()) { case VOID: return null; case BOOLEAN: return new BooleanWritable( ((BooleanObjectInspector) inspector).get(new BooleanWritable((boolean) obj))); case BYTE: return new ByteWritable(((ByteObjectInspector) inspector).get(new ByteWritable((byte) obj))); case DOUBLE: return new DoubleWritable(((DoubleObjectInspector) inspector).get(new DoubleWritable((double) obj))); case FLOAT: return new FloatWritable(((FloatObjectInspector) inspector).get(new FloatWritable((float) obj))); case INT: return new IntWritable(((IntObjectInspector) inspector).get(new IntWritable((int) obj))); case LONG: return new LongWritable(((LongObjectInspector) inspector).get(new LongWritable((long) obj))); case SHORT: return new ShortWritable(((ShortObjectInspector) inspector).get(new ShortWritable((short) obj))); case STRING: String v; if (obj instanceof Long) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date((long) obj); v = df.format(date); } else if (obj instanceof BigDecimal) { BigDecimal bigDecimalObj = (BigDecimal) obj; v = bigDecimalObj.toString(); } else { v = ((StringObjectInspector) inspector).getPrimitiveJavaObject(obj); } try { return new BytesWritable(v.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new SerDeException("Failed to encode string in UTF-8", e); } case DECIMAL: HiveDecimal hd; if (obj instanceof Double) { hd = HiveDecimal.create(new BigDecimal((Double) obj)); } else if (obj instanceof BigDecimal) { hd = HiveDecimal.create((BigDecimal) obj); } else { // if "obj" is other than Double or BigDecimal and a vaild // number, .toString, will get its correct number representation // and a BigDecimal object will be created hd = HiveDecimal.create(new BigDecimal(obj.toString())); } return new HiveDecimalWritable(hd); case TIMESTAMP: return new TimestampWritable(((TimestampObjectInspector) inspector) .getPrimitiveJavaObject(new TimestampWritable(new Timestamp((long) obj)))); case DATE: return new DateWritable(((DateObjectInspector) inspector) .getPrimitiveJavaObject(new DateWritable(new Date((long) obj)))); case CHAR: String strippedValue = ((HiveCharObjectInspector) inspector).getPrimitiveJavaObject(obj) .getStrippedValue(); return new BytesWritable(Binary.fromString(strippedValue).getBytes()); case VARCHAR: String value = ((HiveVarcharObjectInspector) inspector).getPrimitiveJavaObject(obj).getValue(); return new BytesWritable(Binary.fromString(value).getBytes()); default: throw new SerDeException("Unknown primitive : " + inspector.getPrimitiveCategory()); } }
From source file:inflater.computation.SimpleComputation.java
License:MIT License
private void applyChanges(Vertex<LongWritable, VertexValuesWritable, EdgeValuesWritable> vertex, Coordinate disp) {//from w w w . jav a 2 s. c om double t = this.<DoubleWritable>getAggregatedValue(TEMPERATURE_AGG).get(); Coordinate oldPos = vertex.getValue().getCoordinate().get(); Coordinate newPos; if (ComputationUtil.module(disp) != 0) { newPos = ComputationUtil.addCoor(oldPos, ComputationUtil .multiplyCoor(Math.min(ComputationUtil.module(disp), t) / ComputationUtil.module(disp), disp)); newPos.x = Math.min(canvasSize, Math.max(0, newPos.x)); newPos.y = Math.min(canvasSize, Math.max(0, newPos.y)); vertex.getValue().getCoordinate().set(newPos); aggregate(MAX_CHANGE_AGG, new DoubleWritable(ComputationUtil.distance(oldPos, newPos))); } }
From source file:inflater.computation.SimpleMasterCompute.java
License:MIT License
@Override public void compute() { double kValue = getConf().getDouble(KVALUE, -1); LOG.info("SuperStep: " + getSuperstep() + ". Temperature = " + getAggregatedValue(TEMPERATURE_AGG) + ". MAX change = " + getAggregatedValue(MAX_CHANGE_AGG) + ". k value = " + kValue); LOG.info(getTotalNumVertices() + " vertices."); if (getSuperstep() > 1) { double maxChange = this.<DoubleWritable>getAggregatedValue(MAX_CHANGE_AGG).get(); double temperature = this.<DoubleWritable>getAggregatedValue(TEMPERATURE_AGG).get(); double coolRate = getConf().getDouble(MIN_COOL_RATE, 0.9); double minRefine = getConf().getDouble(MIN_REFINE, 0.1); if (maxChange < temperature) { setAggregatedValue(TEMPERATURE_AGG, new DoubleWritable(maxChange)); } else {/*from w w w . ja va2s .c o m*/ setAggregatedValue(TEMPERATURE_AGG, new DoubleWritable(temperature * coolRate)); } if (this.<DoubleWritable>getAggregatedValue(TEMPERATURE_AGG).get() <= kValue * minRefine) { // stop when temperature is low enough haltComputation(); } } }
From source file:inflater.datatypes.writable.EdgeValuesWritable.java
License:MIT License
public EdgeValuesWritable(double weight) { this(new DoubleWritable(weight)); }
From source file:inflater.datatypes.writable.VertexValuesWritable.java
License:MIT License
public VertexValuesWritable(Coordinate coordinate, double weight) { this(new CoordinateWritable(coordinate), new DoubleWritable(weight)); }
From source file:it.uniroma1.bdc.piccioli.tesi.SimpleShortestPathsComputationTextValue.java
License:Apache License
@Override public void compute(Vertex<Text, DoubleWritable, DoubleWritable> vertex, Iterable<DoubleWritable> messages) throws IOException { if (getSuperstep() == 0) { vertex.setValue(new DoubleWritable(Double.MAX_VALUE)); }// www . ja v a2 s . c om double minDist = isSource(vertex) ? 0d : Double.MAX_VALUE; for (DoubleWritable message : messages) { minDist = Math.min(minDist, message.get()); } if (LOG.isDebugEnabled()) { System.out.println("Vertex " + vertex.getId() + " got minDist = " + minDist + " vertex value = " + vertex.getValue()); } if (minDist < new Double(vertex.getValue().toString())) { vertex.setValue(new DoubleWritable(minDist)); for (Edge<Text, DoubleWritable> edge : vertex.getEdges()) { double distance = minDist + edge.getValue().get(); if (LOG.isDebugEnabled()) { System.out.println( "Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance); } sendMessage(edge.getTargetVertexId(), new DoubleWritable(distance)); } } vertex.voteToHalt(); }