Logarithm::Autoencoder
Inherits Logarithm::AbstractModel < Reference < Object
Autoencoder neural network for unsupervised anomaly detection.
This class implements a simple autoencoder with an encoder-decoder architecture designed for anomaly detection in log data. The network compresses log vectors into a low-dimensional bottleneck representation and then reconstructs them.
Architecture:
- Encoder: vocab_size -> 32 -> 8 (bottleneck)
- Decoder: 8 -> 32 -> vocab_size
Training uses mean squared error loss to minimize reconstruction error. Anomalies are detected when reconstruction error exceeds a threshold.
The model uses simple gradient descent with a fixed learning rate. For production use, consider more sophisticated optimizers and architectures.
Constructors
Instance methods
Loads a trained model from a file.
Parameters:
- path: File path to load the model from
Deserializes the model from a string.
Parameters:
- data: String representation of the model
Performs inference on a single input vector.
Given an input vector, the model attempts to reconstruct it based on learned patterns. The reconstruction quality indicates how "normal" the input appears to the model.
Parameters:
- input: Input vector to reconstruct
Returns: Reconstructed vector (same dimensions as input)
The reconstruction error (input - output) is used for anomaly scoring.
Saves the trained model to a file.
Parameters:
- path: File path to save the model to
Serializes the model to a string for storage/encryption.
Returns: String representation of the trained model
Trains the model on vectorized log data.
This method implements the learning algorithm that allows the model to learn patterns in normal log data. The training process optimizes the model's parameters to minimize reconstruction error for normal data.
Parameters:
- data: Array of training vectors (from vectorizer)
- epochs: Number of training iterations over the dataset
Training may take significant time depending on data size and epochs.