Skip to main content

Density Forest library for confidence estimation and novelty detection

Project description

Density Forest

This library was developed within an EPFL Master Project, Spring Semester 2018.

GitHub repository:

📖 Usage of the DensityForest class:

Fitting a Density Forest

Suppose you have your training data X_train and test data X_test, in [N, D] with N data points in D dimensions:

from density_forest.density_forest import DensityForest

clf_df = DensityForest(**params)         # create new class instance, put hyperparameters here                      # fit to a training set
conf = clf_df.decision_function(X_test)  # get confidence values for test set
outliers = clf_df.predict(X_test)        # predict whether a point is an outlier (-1 for outliers 1, for inliers)

Hyperparameters are documented in the docstring. To find the optimal hyperparameters, consider the section below.

Finding Hyperparameters

To find the optimal hyperparameters, use the ParameterSearch from helpers.cross_validator, which allows CV, and hyperparameter search.

from helpers.cross_validator import ParameterSearch

# define hyperparameters to test
tuned_params = [{'max_depth':[2, 3, 4], 'n_trees': [10, 20]}] # optionally add non-default arguments as single-element arrays
default_params = [{'verbose':0, ...}]  # other default parameters 
# do parameter search
ps = ParameterSearch(DensityForest, tuned_parameters, X_train, X_train_all, y_true_tr, f_scorer, n_iter=2, verbosity=0, n_jobs=1, default_params=default_params)

# get model with the best parameters, as above
clf_df = DensityForest(**ps.best_params, **default_params)  # create new class instance with best hyperparameters
...  # continue as above

Check the docstrings for more detailed documentation af the ParameterSearch class.

🗂 File Structure

👾 Code

All libraries for density forests, helper libraries for semantic segmentation and for baselines.


Package for implementation of Decision Trees, Random Forests, Density Trees and Density Forests

  • functions for generating labelled and unlabelled data
  • data structure for decision tree nodes
  • functions for generating decision trees
  • functions for traversing a decision tree and predicting labels
  • functions for creating density forests
  • data struture for density tree nodes
  • functions for generating a density tree
  • functions for descending a density tree and retrieving its cluster parameters
  • various helper functions
  • functions for creating random forests


General helpers library for semantic segmentation

  • custom data augmentation methods applied to both the image and the ground truth
  • PyTorch data loader for Zurich dataset
  • functions for importing, cropping, padding images and other related image tranformations
  • functions for finding optimal hyperparameters for Density Forest, OC-SVM and GMM (explained above)
  • Generic plotter functions for labelled and unlabelled 2D and 3D plots, used for t-SNE and PCA plots


Helper functions for confidence estimation baselines MSR, margin, entropy and MC-Dropout


Helper functions for Keras

  • get activations
  • callbacks to be evaluated after each epoch
  • UNET model for training of network on Zurich dataset

🗾 Visualizations


Visualizations of basic decision tree and density tree

  • Decision Forest.ipynb: Decision Trees and Random Forest on randomly generated labelled data
  • Density Forest.ipynb: Density Trees on randomly generated unlabelled data

🎓 Supervisors:

  • Prof. Devis Tuia, University of Wageningen
  • Diego Marcos González, University of Wageningen
  • Prof. François Golay, EPFL

Cyril Wendl, 2018

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for density_forest, version 0.5.1
Filename, size File type Python version Upload date Hashes
Filename, size density_forest-0.5.1-py3-none-any.whl (36.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size density_forest-0.5.1.tar.gz (29.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page