public class Codec
extends java.lang.Object
Create a codec:
Map<String, String> setosa = Map.of(
"petal_length", "1.5",
"species", "setosa"
);
Map<String, String> versicolor = Map.of(
"petal_length", "3.8",
"species", "versicolor"
);
Stream dataset = Arrays.stream(new Map[]{setosa, versicolor});
Attribute[] attributes = {
new Attribute("petal_length", false),
new Attribute("species", true)
};
Codec codec = new Codec(attributes, dataset);
Encode a data point:
codec.encode(setosa);
Decode a data point:
codec.decode(new double[]{0.0, 1.0, 0.0});
Get the JSON representation of the codec:
codec.json();
Constructor and Description |
---|
Codec(Attribute[] attributes,
java.util.stream.Stream<java.util.Map<java.lang.String,java.lang.String>> datapoints)
Creates a codec by consuming a stream of data points.
|
Codec(java.lang.String json)
Creates a codec by parsing its JSON representation.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.String> |
decode(double[] encodedValues)
Decodes a data point.
|
double[] |
encode(java.util.Map<java.lang.String,java.lang.String> datapoint)
Encodes a data point.
|
java.lang.String |
json()
The JSON representation of the codec.
|
public Codec(Attribute[] attributes, java.util.stream.Stream<java.util.Map<java.lang.String,java.lang.String>> datapoints)
attributes
- An array of attributes that defines their names and types (discrete or not).datapoints
- A stream that contains the data points.public Codec(java.lang.String json)
json
- The JSON representation of a codec.public double[] encode(java.util.Map<java.lang.String,java.lang.String> datapoint)
datapoint
- A data point as a map of strings.public java.util.Map<java.lang.String,java.lang.String> decode(double[] encodedValues)
encodedValues
- An encoded data point as an array of numbers between 0.0 and 1.0.public java.lang.String json()