Code Monkey home page Code Monkey logo

simple-mlnn's Introduction

simple-mlnn

A simple binary classification MLNN.

Usage

Example:

import numpy as np
from mlnn import MLNN
import sample_data
# init and format data
X = [
    [0, 0],
    [0, 1],
    [1, 0],
    [1, 1]
]
Y = [x[0] | x[1] for x in X]
X, Y = np.array(X), np.array(Y)
X = X.T
Y = Y.reshape(1, -1)
# array of number of neurons in each layer
layers = np.array([X.shape[0], Y.shape[0]])
# initialize the network
net = MLNN(layers, h=1)
# fit to the test data
net.fit(X, Y, epochs=500)
a = net.Y_hat(X)
e = net.loss(Y, a)
# print estimation and error
print([round(i, 2) for i in a[0]])
print(e)

Sample output:

[0.03, 0.99, 0.99, 1.0]
0.0131356870149288

An extended example is given in example.py.

Glossary

$X\in\mathbb{R}^{n_x \times m}$

$Y\in\mathbb{R}^{1 \times m}$

Design

I decided against support for variable layer activations (anything but sigmoid), multilabel classification, and other loss functions because my gradient descent computation depends on the derivatives of the sigmoid and logistic loss functions.

Techniques

  • Sigmoid activation: $A=\sigma(Z)=\frac{1}{1+e^{-Z}}, \frac{dA}{dZ}=A(1-A)$
  • Logistic loss: $L(a, y)=-(y\log a+(1-y)\log(1-a))$
  • Backpropogation of this network currently utilizes batch (not mini-batch) gradient descent. The first two pages of the following document contains relevant gradients: link

simple-mlnn's People

Contributors

josephyooo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.