Skip to main content

Neural network modeled after the olfactory system of the hawkmoth.

Project description


Build Status Documentation Status MIT license Python 3.6

This package contains a Python version of MothNet

Neural network modeled after the olfactory system of the hawkmoth, Manduca sexta (shown above).

This repository contains a Python version of the code used in:

Docs (via Sphinx)


Built for use with Mac/Linux systems - not tested in Windows.

  • Requires Python 3.6+

Via pip

pip install mothnet

From source

First, clone this repo and cd into it. Then run:

# Install dependencies:  
pip install -r pymoth/docs/requirements.txt
# Run sample experiment:
python pymoth/

Dependencies (also see requirements.txt)

Example experiment (also see

import os
import pymoth

def experiment():

    # instantiate the MothNet object
    mothra = 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:
    for run in range(mothra.NUM_RUNS):

        # generate dataset
        feature_array = mothra.load_mnist()
        train_X, test_X, train_y, test_y = mothra.train_test_split(feature_array)

        # load parameters
        mothra.load_moth() # define moth model parameters
        mothra.load_exp() # define parameters of a time-evolution experiment

        # run simulation (SDE time-step evolution)
        sim_results = mothra.simulate(feature_array)
        # future:, y_train)

        # collect response statistics:
        # process the sim results to group EN responses by class and time
        EN_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,

        # reveal scores
        # score MothNet
        # score KNN
        mothra.score_knn(train_X, train_y, test_X, test_y)
        # score SVM
        mothra.score_svm(train_X, train_y, test_X, test_y)

        # plot each model in a subplot of a single figure
        if mothra.SHOW_ROC_PLOTS:
            mothra.show_multi_roc(['MothNet', 'SVM', 'KNN'], mothra._class_labels,

Sample results




Questions, comments, criticisms? Feel free to drop us an e-mail!

Bug reports, suggestions, or requests are also welcome! Feel free to create an issue.

Project details

Download files

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

Source Distribution

mothnet-0.0.5.tar.gz (44.4 kB view hashes)

Uploaded source

Built Distribution

mothnet-0.0.5-py3-none-any.whl (49.8 kB view hashes)

Uploaded py3

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