numpy-ml README

The project's README from github.com/ddbourgin/numpy-ml. As one markdown file: README.md.

numpy-ml

Ever wish you had an inefficient but somewhat legible collection of machine learning algorithms implemented exclusively in NumPy? No?

Installation

For rapid experimentation

To use this code as a starting point for ML prototyping / experimentation, just clone the repository, create a new virtualenv, and start hacking:

$ git clone https://github.com/ddbourgin/numpy-ml.git
$ cd numpy-ml && virtualenv npml && source npml/bin/activate
$ pip3 install -r requirements-dev.txt

As a package

If you don't plan to modify the source, you can also install numpy-ml as a Python package: pip3 install -u numpy_ml.

The reinforcement learning agents train on environments defined in the OpenAI gym. To install these alongside numpy-ml, you can use pip3 install -u 'numpy_ml[rl]'.

Documentation

For more details on the available models, see the project documentation.

Available models

Click to expand!
  1. Gaussian mixture model

    • EM training
  2. Hidden Markov model

    • Viterbi decoding
    • Likelihood computation
    • MLE parameter estimation via Baum-Welch/forward-backward algorithm
  3. Latent Dirichlet allocation (topic model)

    • Standard model with MLE parameter estimation via variational EM
    • Smoothed model with MAP parameter estimation via MCMC
  4. Neural networks

    • Layers / Layer-wise ops
      • Add
      • Flatten
      • Multiply
      • Softmax
      • Fully-connected/Dense
      • Sparse evolutionary connections
      • LSTM
      • Elman-style RNN
      • Max + average pooling
      • Dot-product attention
      • Embedding layer
      • Restricted Boltzmann machine (w. CD-n training)
      • 2D deconvolution (w. padding and stride)
      • 2D convolution (w. padding, dilation, and stride)
      • 1D convolution (w. padding, dilation, stride, and causality)
    • Modules
      • Bidirectional LSTM
      • ResNet-style residual blocks (identity and convolution)
      • WaveNet-style residual blocks with dilated causal convolutions
      • Transformer-style multi-headed scaled dot product attention
    • Regularizers
      • Dropout
    • Normalization
      • Batch normalization (spatial and temporal)
      • Layer normalization (spatial and temporal)
    • Optimizers
      • SGD w/ momentum
      • AdaGrad
      • RMSProp
      • Adam
    • Learning Rate Schedulers
      • Constant
      • Exponential
      • Noam/Transformer
      • Dlib scheduler
    • Weight Initializers
      • Glorot/Xavier uniform and normal
      • He/Kaiming uniform and normal
      • Standard and truncated normal
    • Losses
      • Cross entropy
      • Squared error
      • Bernoulli VAE loss
      • Wasserstein loss with gradient penalty
      • Noise contrastive estimation loss
    • Activations
      • ReLU
      • Tanh
      • Affine
      • Sigmoid
      • Leaky ReLU
      • ELU
      • SELU
      • GELU
      • Exponential
      • Hard Sigmoid
      • Softplus
    • Models
      • Bernoulli variational autoencoder
      • Wasserstein GAN with gradient penalty
      • word2vec encoder with skip-gram and CBOW architectures
    • Utilities
      • col2im (MATLAB port)
      • im2col (MATLAB port)
      • conv1D
      • conv2D
      • deconv2D
      • minibatch
  5. Tree-based models

    • Decision trees (CART)
    • [Bagging] Random forests
    • [Boosting] Gradient-boosted decision trees
  6. Linear models

    • Ridge regression
    • Logistic regression
    • Ordinary least squares
    • Weighted linear regression
    • Generalized linear model (log, logit, and identity link)
    • Gaussian naive Bayes classifier
    • Bayesian linear regression w/ conjugate priors
      • Unknown mean, known variance (Gaussian prior)
      • Unknown mean, unknown variance (Normal-Gamma / Normal-Inverse-Wishart prior)
  7. n-Gram sequence models

    • Maximum likelihood scores
    • Additive/Lidstone smoothing
    • Simple Good-Turing smoothing
  8. Multi-armed bandit models

    • UCB1
    • LinUCB
    • Epsilon-greedy
    • Thompson sampling w/ conjugate priors
      • Beta-Bernoulli sampler
    • LinUCB
  9. Reinforcement learning models

    • Cross-entropy method agent
    • First visit on-policy Monte Carlo agent
    • Weighted incremental importance sampling Monte Carlo agent
    • Expected SARSA agent
    • TD-0 Q-learning agent
    • Dyna-Q / Dyna-Q+ with prioritized sweeping
  10. Nonparameteric models

    • Nadaraya-Watson kernel regression
    • k-Nearest neighbors classification and regression
    • Gaussian process regression
  11. Matrix factorization

    • Regularized alternating least-squares
    • Non-negative matrix factorization
  12. Preprocessing

    • Discrete Fourier transform (1D signals)
    • Discrete cosine transform (type-II) (1D signals)
    • Bilinear interpolation (2D signals)
    • Nearest neighbor interpolation (1D and 2D signals)
    • Autocorrelation (1D signals)
    • Signal windowing
    • Text tokenization
    • Feature hashing
    • Feature standardization
    • One-hot encoding / decoding
    • Huffman coding / decoding
    • Byte pair encoding / decoding
    • Term frequency-inverse document frequency (TF-IDF) encoding
    • MFCC encoding
  13. Utilities

    • Similarity kernels
    • Distance metrics
    • Priority queue
    • Ball tree
    • Discrete sampler
    • Graph processing and generators

Contributing

Am I missing your favorite model? Is there something that could be cleaner / less confusing? Did I mess something up? Submit a PR! The only requirement is that your models are written with just the Python standard library and NumPy. The SciPy library is also permitted under special circumstances ;)

See full contributing guidelines here.

numpy-ml (ddbourgin/numpy-ml)

Searching Database…

16.3K ·GitHub
这是什么?一套机器学习算法合集——高斯混合模型、隐马尔可夫模型、神经网络、树集成、强化学习智能体等等——全部用纯 NumPy 从零实现。
里面都有哪些模型?高斯混合模型和隐马尔可夫模型、LDA 主题模型、一套完整的神经网络模块(CNN、LSTM、注意力机制、ResNet/WaveNet 模块、VAE、WGAN-GP、word2vec)、树集成、线性和贝叶斯模型、n-gram、多臂老虎机、强化学习智能体、KNN、高斯过程、矩阵分解——还包括 DFT、MFCC、BPE、TF-IDF 等预处理工具。
怎么上手?克隆仓库,建一个 virtualenv,直接在源码上动手——如果你只是想拿来用,用 pip3 install -u numpyml 把它作为包安装即可。
除了 Python 和 NumPy 之外还需要装别的东西吗?不需要——每个模型只用 Python 标准库和 NumPy(只有特殊情况会用到 SciPy)。强化学习智能体还会在 OpenAI gym 环境上训练,通过 numpyml[rl] 这个 extra 安装。
它的速度够用来训练真实模型吗?它刻意做到'效率不高但相当易读'——为可读性和实验而生,并不是为了达到生产级训练框架那样的吞吐量。
这是给谁用的——学机器学习的人,还是做产品的人?它面向机器学习的原型开发和实验:适合那些想阅读、修改并从实现中学习的学生和从业者,而不是把它们当成黑盒来用的人。
它涵盖 Transformer 注意力这类现代深度学习组件吗?涵盖——神经网络模块包括点积注意力、Transformer 风格的多头缩放点积注意力、带膨胀因果卷积的 WaveNet 风格残差块、ResNet 风格的残差块,以及双向 LSTM。
它自带哪些强化学习智能体?交叉熵方法、首次访问和重要性采样蒙特卡洛、期望 SARSA、TD-0 Q 学习,以及带优先级扫掠的 Dyna-Q / Dyna-Q+——全部在 OpenAI gym 环境上训练。
包含哪些预处理和实用工具?DFT、DCT、MFCC 和哈夫曼编码、文本分词、字节对编码、TF-IDF、特征哈希和独热编码,还有 im2col/col2im、距离度量、球树和优先队列等工具。
Creator
ddbourgin
Size
10.3 MB
Stars
16.3K
Updated
CommitJan 08
Age
7y
Commits · 90 Days