Skip to main content

Keras Layer to apply Quantile transform and its inverse

Project description

FastQuantileLayer

FastQuantileLayer is a Layer for Keras implementing the QuantileTransform similarly to scikit-learn QuantileTransformer. A similar implementation, more precise but not bound to Keras, can be found here: https://github.com/yandexdataschool/QuantileTransformerTF/blob/master/README.md

The purpose of this package is:

  • remove all dependencies on scikit-learn
  • obtain an evaluation of the direct and inverse transform as fast as possible (trading some precision for performance)
  • obtain a TensorFlow graph runnable in a Sequential model in Keras

The package is composed of two classes:

  • FixedBinInterpolator: intended to interpolate a point-defined function y = f(x) with equidistant x samples (x-grid)
  • FastQuantileLayer: intended to compute the transform to preprocess the input data into a uniform- or normal-distributed variable.

Example outside Keras

  ## Creates the training dataset 
  dataset = np.random.uniform ( 0., 1., 1000 ) 

  ## Train the QuantileTransformer 
  transformer = FastQuantileLayer (output_distribution='normal')
  transformer . fit ( dataset ) 

  ## Gets a new dataset with the same distribution as the training dataset
  test_dataset = tf.constant(np.random.uniform ( 0., 1., 100000 ))

  ## Transform the variable into a Gaussian-distributed variable t 
  t = transformer . transform ( test_dataset ) 

  [...] 

  ## Appiles the inverted transform to the Gaussian distributed variable t  
  bkwd = transformer . transform ( t, inverse=True ) 

  ## bkwd differs from test_dataset only for computational errors 
  ## (order 1e-5) that can be reduced tuning the arguments of QuantileTransformer

Example within Keras

  ## Creates the training dataset 
  dataset = np.random.uniform ( 0., 1., 1000 ) 

  model = tf.keras.models.Sequential()
  model.add ( FastQuantileLayer ( output_distribution = 'normal' ).fit ( dataset ) )
  model.add ( Dense ( 10, activation = 'tanh' ) )
  model.add ( Dense ( 1, activation = 'sigmoid' ) ) 


Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

FastQuantileLayer-0.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file FastQuantileLayer-0.2-py3-none-any.whl.

File metadata

  • Download URL: FastQuantileLayer-0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

File hashes

Hashes for FastQuantileLayer-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 df20435f173f27ae16936a2e582e664bb4d3e29940e509b5cb7c7d73cda4f15a
MD5 cfb2c36b712fc2e9be036ca2af1c804a
BLAKE2b-256 8c9230f60f7f3a7a605ddebf1656392410495ff18935a4a27cbf5ef9a7029bd6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page