以鹰蛾嗅觉系统为模型的神经网络。
mothnet的Python项目详细描述
毒蛾
此包包含python版本的MothNet
神经网络模仿鹰蛾的嗅觉系统,manduca sexta(如上图所示)。
This repository contains a Python version of the code used in:
- "Putting a bug in ML: The moth olfactory network learns to read MNIST", Neural Networks 2019
Docs (via Sphinx)
安装
用于Mac/Linux系统-未在Windows中测试。
- 需要python 3.6+
通过pip
pip install mothnet
来源
首先,克隆这个repo并cd
到其中。然后运行:
# Install dependencies: pip install -r pymoth/docs/requirements.txt# Run sample experiment: python pymoth/examples.py
依赖项(另请参见^{} )
- scipy
- matplotlib
- scikit-learn(用于KNN和SVM模型)
- pillow
- keras(用于加载mnist)
- tensorflow(也用于加载mnist)
示例实验(另见^{} )
importosimportpymothdefexperiment():# instantiate the MothNet objectmothra=pymoth.MothNet({'screen_size':(1920,1080),# screen size (width, height)'num_runs':1,# how many runs you wish to do with this moth'goal':15,# defines the moth's learning rates'tr_per_class':1,# (try 3) the number of training samples per class'num_sniffs':1,# (try 2) number of exposures each training sample'num_neighbors':1,# optimization param for nearest neighbors'box_constraint':1e1,# optimization parameter for svm'n_thumbnails':1,# show N experiment inputs from each class'show_acc_plots':True,# True to plot, False to ignore'show_time_plots':True,# True to plot, False to ignore'show_roc_plots':True,# True to plot, False to ignore'results_folder':'results',# string'results_filename':'results',# will get the run number appended to it'data_folder':'MNIST_all',# string'data_filename':'MNIST_all',# string})# loop through the number of simulations specified:forruninrange(mothra.NUM_RUNS):# generate datasetfeature_array=mothra.load_mnist()train_X,test_X,train_y,test_y=mothra.train_test_split(feature_array)# load parametersmothra.load_moth()# define moth model parametersmothra.load_exp()# define parameters of a time-evolution experiment# run simulation (SDE time-step evolution)sim_results=mothra.simulate(feature_array)# future: mothra.fit(X_train, y_train)# collect response statistics:# process the sim results to group EN responses by class and timeEN_resp_trained=mothra.collect_stats(sim_results,mothra.experiment_params,mothra._class_labels,mothra.SHOW_TIME_PLOTS,mothra.SHOW_ACC_PLOTS,images_filename=mothra.RESULTS_FILENAME,images_folder=mothra.RESULTS_FOLDER,screen_size=mothra.SCREEN_SIZE)# reveal scores# score MothNetmothra.score_moth_on_MNIST(EN_resp_trained)# score KNNmothra.score_knn(train_X,train_y,test_X,test_y)# score SVMmothra.score_svm(train_X,train_y,test_X,test_y)# plot each model in a subplot of a single figureifmothra.SHOW_ROC_PLOTS:mothra.show_multi_roc(['MothNet','SVM','KNN'],mothra._class_labels,images_filename=mothra.RESULTS_FOLDER+os.sep+mothra.RESULTS_FILENAME+'_ROC_multi')
样本结果
数据集
模块
- classify.py对来自蛾类网络模型的输出进行分类。
- generate.py下载(如果不存在)并准备下采样的mnist数据集。
- params.py实验和模型参数。
- sde.py运行随机微分方程模拟。
- show_figs.py图形生成模块。
- MNIST_make_all.py下载mnist数据并将其保存到.npy文件。
问题,评论,批评?请随便给我们一个e-mail!
也欢迎错误报告、建议或请求!请随意create an issue。