Giter VIP home page Giter VIP logo

aletheia's Introduction

Aletheia

A Python package for unwrapping ReLU Neural Networks

Installation

The following environments are required:

  • Python 3.6, 3.7, 3.8, 3.9 (Try Google Colab)
  • matplotlib>=3.1.3
  • numpy>=1.17
  • pandas>=1.1.2
  • seaborn>=0.9.0
  • scikit-learn>=0.23.0
  • statsmodels>=0.12.2
pip install aletheia-dnn

Usage

Load data

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
from sklearn.datasets import make_circles
from sklearn.model_selection import train_test_split

random_state = 0

x, y = make_circles(n_samples=2000, noise=0.1, random_state=random_state)
train_x, test_x, train_y, test_y = train_test_split(x, y, test_size=0.2, random_state=random_state)

plt.figure(figsize=(10,8))
scatter = plt.scatter(x[:, 0], x[:, 1], c=y)
plt.legend(*scatter.legend_elements(), loc="upper right")
plt.show()

Train a ReLU Net

from sklearn.neural_network import MLPClassifier
mlp = MLPClassifier(hidden_layer_sizes=[40] * 4, max_iter=2000, early_stopping=True, 
                    n_iter_no_change=100, validation_fraction=0.2,
                    solver='adam', activation="relu", random_state=random_state, 
                    learning_rate_init=0.001)
mlp.fit(train_x, train_y)

UnwrapperClassifier

from aletheia import *
clf = UnwrapperClassifier(mlp.coefs_, mlp.intercepts_)
clf.fit(train_x, train_y)
clf.summary()

CoCircleSummary

Partitioned regions

clf.visualize2D_regions(figsize=(8, 8), meshsize=300, show_label=False)

CoCircleRegions

Simplification

from sklearn.metrics import make_scorer, roc_auc_score
from sklearn.model_selection import GridSearchCV, PredefinedSplit
from sklearn.linear_model import LogisticRegressionCV, LogisticRegression

datanum = train_x.shape[0]
indices = np.arange(datanum)
idx1, idx2 = train_test_split(indices, test_size=0.2, random_state=random_state)
val_fold = np.ones((len(indices)))
val_fold[idx1] = -1

grid = GridSearchCV(MergerClassifier(unwrapper=None, 
                                     weights=mlp.coefs_, 
                                     biases=mlp.intercepts_,
                                     min_samples=30,
                                     n_neighbors=np.round(clf.nllms * 0.01).astype(int),
                                     refit_model=LogisticRegression()),
                                     param_grid={"n_clusters": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20]},
                                     scoring={"auc": make_scorer(roc_auc_score, needs_proba=True)},
                                     cv=PredefinedSplit(val_fold), refit="auc", n_jobs=10, error_score=np.nan)
grid.fit(train_x, train_y)
clf_merge = grid.best_estimator_
clf_merge.summary()

Local Inference

tmpid = 0
clf_merge.visualize2D_one_line(tmpid, figsize=(8, 8))
clf_merge.local_inference_wald(tmpid).round(4)

Citations

Agus Sudjianto, William Knauth, Rahul Singh, Zebin Yang and Aijun Zhang. 2020. Unwrapping The Black Box of Deep ReLU Networks: Interpretability, Diagnostics, and Simplification. arXiv:2011.04041

@article{sudjianto2020unwrapping,
  title={Unwrapping The Black Box of Deep ReLU Networks: Interpretability, Diagnostics, and Simplification},
  author={Sudjianto, Agus and Knauth, William and Singh, Rahul and Yang, Zebin and Zhang, Aijun},
  journal={arXiv:2011.04041},
  year={2020}
}

aletheia's People

Contributors

ajzhanghk avatar zebinyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

aletheia's Issues

TypeError with "fit" function within the "UnwrapperClassifier" function

Hi,

When I am trying to use the fit function with the UnwrapperClassfier, I constantly keep getting a type error that says the following:
aletheia_error
I am not sure if this is an issue faced earlier, but if further details can be provided for the input data types for the functions that would be helpful as well.
Looking forward to hearing from you, thank you very much!

Installation problems - Windows

Hi,

I have a similar issue to #2. I've installed the library with pip install aletheia-relunet-unwrapper (as indicated in README instructions) without any problem, but when I try to use UnWrapperRegressor , it throws the error: name 'UnWrapperRegressor' is not defined.

Following the issue #2, I did

import aletheia
dir(aletheia)

But I obtained:

['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

My config is:

  • Windows 10
  • Python 3.8.5
  • aletheia-relunet-unwrapper 1.1.2

What could be the problem? Thank you very much!

Altetheia's copyright clarification

Hi,

While I was reading the paper, I saw: "Aletheia©". I am assuming Aletheia is copyrighted.

I don't know what this means...and I couldn't find clarifications on readme/documentations...

Can I use your package to run some examples and show them at work (of couse I would make the citations/references properly) ?
Would it be a copyright infringement writing a whitepaper which includes some examples/analysis made with Aletheia (other than those from your paper) ?

Thank you !!!,
rafael

Build from source support

Pip install not working
ERROR: Could not find a version that satisfies the requirement aletheia-dnn ERROR: No matching distribution found for aletheia-dnn

  • python version: 3.7.3

Is it possible to get a Python 3.10 version uploaded to PyPi?

I'm currently attempting to use Aletheia in Google Colab which defaults to Python 3.10, and the aletheia-dnn library isn't resolved by pip.

I was wondering if it would be possible to arrange for a 3.10 compatible version to be made available?

As a workaround I'm attempting to downgrade the version of Python, but this is a bit of a faff and I'd prefer to avoid this if possible.

Thanks.

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.