com.github.mrdimosthenis.synapses.Codec Maven / Gradle / Ivy
The newest version!
package com.github.mrdimosthenis.synapses;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Stream;
import synapses.custom.AttributeWithFlag;
import synapses.jvm.CodecJ;
/**
* The constructors and methods of codecs.
*
* Create a codec:
*
* {@code
* Map setosa = Map.of(
* "petal_length", "1.5",
* "species", "setosa"
* );
*
* Map 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:
*
* {@code
* codec.encode(setosa);
* }
*
*
*
* Decode a data point:
*
* {@code
* codec.decode(new double[]{0.0, 1.0, 0.0});
* }
*
*
*
* Get the JSON representation of the codec:
*
* {@code
* codec.json();
* }
*
*
*/
public class Codec {
CodecJ contents;
/**
* Creates a codec by consuming a stream of data points.
*
* @param attributes An array of attributes that defines their names and types (discrete or not).
* @param datapoints A stream that contains the data points.
*/
public Codec(Attribute[] attributes,
Stream