acton.proto package¶
Submodules¶
acton.proto.acton_pb2 module¶
acton.proto.io module¶
Functions for reading/writing to protobufs.
-
acton.proto.io.
GeneratedProtocolMessageType
(name, *args, **kwargs)¶
-
acton.proto.io.
get_ndarray
(data: list, shape: tuple, dtype: str) → <MagicMock id='140030183474344'>[source]¶ Converts a list of values into an array.
Parameters: - data – Raw array data.
- shape – Shape of the resulting array.
- dtype – Data type of the resulting array.
Returns: Array with the given data, shape, and dtype.
Return type: numpy.ndarray
-
acton.proto.io.
read_metadata
(file: typing.Union[str, typing.BinaryIO]) → bytes[source]¶ Reads metadata from a protobufs file.
Parameters: file – Path to binary file, or file itself. Returns: Metadata. Return type: bytes
-
acton.proto.io.
read_proto
()[source]¶ Reads a protobuf from a .proto file.
Parameters: - path – Path to the .proto file.
- Proto – Protocol message class (from the generated protobuf module).
Returns: The parsed protobuf.
Return type:
-
acton.proto.io.
read_protos
()[source]¶ Reads many protobufs from a file.
Parameters: - file – Path to binary file, or file itself.
- Proto – Protocol message class (from the generated protobuf module).
Yields: GeneratedProtocolMessageType – A parsed protobuf.
acton.proto.wrappers module¶
Classes that wrap protobufs.
-
class
acton.proto.wrappers.
LabelPool
(proto: typing.Union[str, mock.mock.LabelPool])[source]¶ Bases:
object
Wrapper for the LabelPool protobuf.
-
proto
¶ acton_pb.LabelPool – Protobuf representing the label pool.
-
db_kwargs
¶ dict – Key-value pairs of keyword arguments for the database constructor.
-
label_encoder
¶ sklearn.preprocessing.LabelEncoder – Encodes labels as integers. May be None.
-
DB
¶ Gets a database context manager for the specified database.
Returns: Database context manager. Return type: type
-
classmethod
deserialise
(proto: bytes, json: bool = False) → acton.proto.wrappers.LabelPool[source]¶ Deserialises a protobuf into a LabelPool.
Parameters: - proto – Serialised protobuf.
- json – Whether the serialised protobuf is in JSON format.
Returns: Return type:
-
ids
¶ Gets a list of IDs.
Returns: List of known IDs. Return type: List[int]
-
labels
¶ Gets labels array specified in input.
Notes
The returned array is cached by this object so future calls will not need to recompile the array.
Returns: T x N x F NumPy array of labels. Return type: numpy.ndarray
-
-
class
acton.proto.wrappers.
Predictions
(proto: typing.Union[str, mock.mock.Predictions])[source]¶ Bases:
object
Wrapper for the Predictions protobuf.
-
proto
¶ acton_pb.Predictions – Protobuf representing predictions.
-
db_kwargs
¶ dict – Dictionary of database keyword arguments.
-
label_encoder
¶ sklearn.preprocessing.LabelEncoder – Encodes labels as integers. May be None.
-
DB
¶ Gets a database context manager for the specified database.
Returns: Database context manager. Return type: type
-
classmethod
deserialise
(proto: bytes, json: bool = False) → acton.proto.wrappers.Predictions[source]¶ Deserialises a protobuf into Predictions.
Parameters: - proto – Serialised protobuf.
- json – Whether the serialised protobuf is in JSON format.
Returns: Return type:
-
labelled_ids
¶ Gets a list of IDs the predictor knew the label for.
Returns: List of IDs the predictor knew the label for. Return type: List[int]
-
classmethod
make
(predicted_ids: typing.Iterable[int], labelled_ids: typing.Iterable[int], predictions: <MagicMock id='140030183792768'>, db: acton.database.Database, predictor: str = '') → acton.proto.wrappers.Predictions[source]¶ Converts NumPy predictions to a Predictions object.
Parameters: - predicted_ids – Iterable of instance IDs corresponding to predictions.
- labelled_ids – Iterable of instance IDs used to train the predictor.
- predictions – T x N x D array of corresponding predictions.
- predictor – Name of predictor used to generate predictions.
- db – Database.
Returns: Return type:
-
predicted_ids
¶ Gets a list of IDs corresponding to predictions.
Returns: List of IDs corresponding to predictions. Return type: List[int]
-
predictions
¶ Gets predictions array specified in input.
Notes
The returned array is cached by this object so future calls will not need to recompile the array.
Returns: T x N x D NumPy array of predictions. Return type: numpy.ndarray
-
-
class
acton.proto.wrappers.
Recommendations
(proto: typing.Union[str, mock.mock.Recommendations])[source]¶ Bases:
object
Wrapper for the Recommendations protobuf.
-
proto
¶ acton_pb.Recommendations – Protobuf representing recommendations.
-
db_kwargs
¶ dict – Key-value pairs of keyword arguments for the database constructor.
-
label_encoder
¶ sklearn.preprocessing.LabelEncoder – Encodes labels as integers. May be None.
-
DB
¶ Gets a database context manager for the specified database.
Returns: Database context manager. Return type: type
-
classmethod
deserialise
(proto: bytes, json: bool = False) → acton.proto.wrappers.Recommendations[source]¶ Deserialises a protobuf into Recommendations.
Parameters: - proto – Serialised protobuf.
- json – Whether the serialised protobuf is in JSON format.
Returns: Return type:
-
labelled_ids
¶ Gets a list of labelled IDs.
Returns: List of labelled IDs. Return type: List[int]
-
classmethod
make
(recommended_ids: typing.Iterable[int], labelled_ids: typing.Iterable[int], recommender: str, db: acton.database.Database) → acton.proto.wrappers.Recommendations[source]¶ Constructs a Recommendations.
Parameters: - recommended_ids – Iterable of recommended instance IDs.
- labelled_ids – Iterable of labelled instance IDs used to make recommendations.
- recommender – Name of the recommender used to make recommendations.
- db – Database.
Returns: Return type:
-
recommendations
¶ Gets a list of recommended IDs.
Returns: List of recommended IDs. Return type: List[int]
-
-
acton.proto.wrappers.
deserialise_encoder
(encoder: mock.mock.LabelEncoder) → <MagicMock name='mock.LabelEncoder' id='140030183483040'>[source]¶ Deserialises a LabelEncoder protobuf.
Parameters: encoder – LabelEncoder protobuf. Returns: LabelEncoder (or None if no encodings were specified). Return type: sklearn.preprocessing.LabelEncoder