Using Autoencoder Agents
What Autoencoder Agents Do
Autoencoder agents learn to reconstruct normal sensor data patterns. When incoming data deviates significantly from learned patterns, the agent flags anomalies.
Use cases:
- Detect sensor malfunctions
- Identify unusual system states
- Monitor equipment health
- Validate data quality
Configuration
Basic Configuration
autoencoder_agent1:
# Preprocessing
preprocessing_pipeline:
- bounds_normalizer
- window_processor
window_size: 5
# Training
min_training_samples: 100
learning_rate: 0.0001
batch_size: 16
epochs: 10
# Model
encoder_dims: [64, 32, 16]
# Data specification
model_input:
channels:
- state_0
- state_1
- state_2
bounds:
- [-1.0, 1.0]
- [-1.0, 1.0]
- [-8.0, 8.0]
model_output:
channels:
- state_0
- state_1
- state_2
# Topics
kafka_topics:
input: "gymnasium-output"
output: "autoencoder1-anomalies"
training_output: "autoencoder1-training-results"
Key Parameters
window_size: Number of timesteps per training sample
- Smaller (5-10): Faster training, less context
- Larger (50-100): More context, slower training
min_training_samples: Samples before first training
- Development: 100-1000
- Production: 10000+
encoder_dims: Neural network layer sizes
- Smaller: Faster, less capacity
- Larger: More capacity, slower
- Pattern: Decreasing sizes [64, 32, 16]
model_input: Expected input channels
- The channel names will be from the channels found in the kafka topic you are subscribed to
- These will be what the model is using for input
model_output: Expected output channels
- The channel names will be from the channels found in the kafka topic you are subscribed to
- These will be what the model is predicting (output)
bounds: Expected data ranges per channel
- Must match actual sensor ranges
- Used for normalization
- Out-of-bounds data rejected
kafka_topics: Input kafka topic name and output kafka names
- Input should be the kafka topic you would like your data to come from
- Output should be the inference topic you would like to send results to
- Training output will be the training information and statistics topic name
Training Process
Data Accumulation Phase
Agent collects data but does not train:
Database contains X samples (need 100)
Duration: Depends on data rate
- 10 samples/sec: 10 seconds to 100 samples
- 1 sample/sec: 100 seconds
Training Phase
When threshold reached:
Found 150 new samples since last training
Starting model training...
Training complete: loss=0.023, val_loss=0.025
Model v001 saved successfully
Training frequency: After sufficient new data accumulates
- First training: At min_training_samples
- Subsequent: After similar amount of new data
Model Versioning
Models stored in /app/models:
/app/models/
model_v001.h5
model_v002.h5
model_v003.h5
latest_model.json (points to v003)
Access models:
docker exec autoencoder-agent1 ls /app/models
docker cp autoencoder-agent1:/app/models ./exported_models
Inference and Anomaly Detection
How Detection Works
- Receive sensor data
- Create sliding window from recent history
- Normalize using training bounds
- Reconstruct through autoencoder
- Calculate reconstruction error
- Compare to threshold
- Flag anomaly if error exceeds threshold
Anomaly Thresholds
Automatic threshold (95th percentile of training errors):
anomaly_threshold_type: "percentile"
threshold_percentile: 95.0
Fixed threshold:
anomaly_threshold_type: "fixed"
threshold: 0.02
Reading Anomaly Messages
Published to output topic:
{
"timestamp": 1234567890.123,
"channels": {
"agent_id": "autoencoder-agent1",
"error_score": 0.045,
"is_anomaly": true,
"anomaly_threshold": 0.030,
"state_0_input": 1.23,
"state_0_reconstructed": 1.18
}
}
Key fields:
is_anomaly: Boolean flagerror_score: Actual reconstruction erroranomaly_threshold: Current threshold*_inputvs*_reconstructed: Per-channel comparison
Monitoring
Training Progress
View training results in logs:
docker compose logs autoencoder-agent1 | grep "Training complete"
Check InfluxDB:
- Query
autoencoder1-training-resultsmeasurement - Plot loss over time
- Monitor training frequency
Model Performance
Metrics to watch:
loss: Training error (should decrease)val_loss: Validation error (should track loss)mean_reconstruction_error: Average error on evaluation set
Common Issues
No Training Occurring
Symptom: "Database contains X samples (need Y)" repeats
Causes:
- Not enough data ingested
- Input topic misconfigured
- Data ingest thread failed
High Anomaly Rate
Symptom: Most samples flagged as anomalies
Causes:
- Threshold too low
- Insufficient training data
- Data distribution shifted
Training Errors
Symptom: "Preprocessing pipeline failed"
Causes:
- Bounds misconfigured
- Channel mismatch
- Invalid data in database
Customization
Adjust Model Capacity
Larger model (more capacity):
encoder_dims: [128, 64, 32, 16]
Smaller model (faster):
encoder_dims: [32, 16]
Change Window Size
Longer windows (more context):
window_size: 50
Note: Requires more training data and memory.