Skip to content

Add history_ attribute to DNN models for training loss tracking - #712

Open
jiyanshuj wants to merge 2 commits into
yzhao062:masterfrom
jiyanshuj:feature/history-attribute-636
Open

Add history_ attribute to DNN models for training loss tracking#712
jiyanshuj wants to merge 2 commits into
yzhao062:masterfrom
jiyanshuj:feature/history-attribute-636

Conversation

@jiyanshuj

@jiyanshuj jiyanshuj commented Aug 1, 2026

Copy link
Copy Markdown

Fixes #636

  • Add self.history_ dict ({'loss': [...]}) to BaseDeepLearningDetector and all standalone DNN-based detectors (AutoEncoder, VAE, ALAD, AnoGAN, DeepSVDD, DevNet, LUNAR, MO_GAAL, SO_GAAL, TS-LSTM, TS-AnomalyTransformer, AE1SVM)
  • Update docstrings to document the new attribute
  • Add unit tests verifying history_['loss'] is populated per epoch
  • No changes to existing verbose printing behavior, except DevNet's console log now prints the mean epoch loss instead of the last-batch loss (per review feedback)

All Submissions Basics:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you checked all Issues to tie the PR to a specific one?

All Submissions Cores:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?
  • Does your submission pass tests, including CircleCI, Travis CI, and AppVeyor?
  • Does your submission have appropriate code coverage? The cutoff threshold is 95% by Coversall.

New Model Submissions:

  • Have you created a .py in ~/pyod/models/?
  • Have you created a _example.py in ~/examples/?
  • Have you created a test_.py in ~/pyod/test/?
  • Have you lint your code locally prior to submission?

Fixes yzhao062#636

- Add self.history_ dict ({'loss': [...]}) to BaseDeepLearningDetector
  and all standalone DNN-based detectors (AutoEncoder, VAE, ALAD,
  AnoGAN, DeepSVDD, DevNet, LUNAR, MO_GAAL, SO_GAAL, TS-LSTM,
  TS-AnomalyTransformer, AE1SVM)
- Update docstrings to document the new attribute
- Add unit tests verifying history_['loss'] is populated per epoch
- Retain existing verbose printing behavior (noting DevNet's console print
  now outputs the mean epoch loss rather than the last batch loss)
Copilot AI review requested due to automatic review settings August 1, 2026 14:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a history_ attribute to deep-learning-based detectors so callers can retrieve training loss information after fit() (addressing issue #636), and extends the test suite to assert the history is populated.

Changes:

  • Track and expose per-epoch training loss via history_ across BaseDeepLearningDetector-based models and several standalone DNN detectors.
  • Update model docstrings and CHANGES.txt to document the new history_ attribute.
  • Add/extend unit tests to validate history_ is present and populated after fitting.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pyod/models/base_dl.py Initializes/resets and appends to history_['loss'] during training in the shared deep-learning base class.
pyod/models/auto_encoder.py Documents inherited history_ for AutoEncoder.
pyod/models/vae.py Documents inherited history_ for VAE.
pyod/models/deep_svdd.py Adds history_ initialization and records per-epoch loss.
pyod/models/ae1svm.py Adds history_ and records per-epoch mean loss (also reuses that value for best-loss tracking/printing).
pyod/models/devnet.py Adds history_ and records per-epoch mean loss (also changes printed loss value).
pyod/models/lunar.py Adds history_ and records loss each epoch.
pyod/models/ts_lstm.py Adds history_ and records mean batch loss per epoch during training.
pyod/models/ts_anomaly_transformer.py Adds history_ and records per-epoch mean minimize-phase loss.
pyod/models/anogan.py Adds history_ mapping to GAN loss histories; reinitializes on fit().
pyod/models/alad.py Adds history_ mapping to GAN loss histories during model build/fit.
pyod/models/so_gaal.py Exposes existing train_history via history_ and documents it.
pyod/models/mo_gaal.py Exposes existing train_history via history_ and documents it.
pyod/test/test_auto_encoder.py Adds assertions that history_['loss'] exists and has epoch_num entries.
pyod/test/test_vae.py Adds assertions that history_['loss'] exists and has epoch_num entries.
pyod/test/test_deepsvdd.py Adds assertions that history_['loss'] exists and has epochs entries.
pyod/test/test_anogan.py Adds assertions for GAN loss keys in history_.
pyod/test/test_alad.py Adds assertions for GAN loss keys in history_.
pyod/test/test_so_gaal.py Adds assertions for GAN loss keys in history_.
pyod/test/test_mo_gaal.py Adds assertions for GAN loss keys in history_.
CHANGES.txt Adds release-note entry for the new history_ attribute.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyod/models/base_dl.py Outdated
Comment thread pyod/models/base_dl.py Outdated
Comment thread pyod/models/anogan.py Outdated
Comment thread pyod/models/devnet.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c0e54c06c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pyod/models/base_dl.py Outdated
Comment thread pyod/models/anogan.py Outdated
- Ensure self.history_ is set exclusively in fit() across all models
- Explicitly cast overall_loss to float in BaseDeepLearningDetector.train
- Address PR review comments
@jiyanshuj
jiyanshuj force-pushed the feature/history-attribute-636 branch from 2c0e54c to 69ac31d Compare August 1, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding history for deep learning model

2 participants