From ae3d7e2fb9995c5c949a3a04d545d107bcfb5596 Mon Sep 17 00:00:00 2001 From: Tim O'Donnell <timodonnell@gmail.com> Date: Tue, 19 Dec 2017 16:25:47 -0500 Subject: [PATCH] Better docstrings --- mhcflurry/class1_affinity_predictor.py | 3 +++ mhcflurry/class1_neural_network.py | 27 ++++++++++++++++++++++++-- mhcflurry/common.py | 8 ++++++++ mhcflurry/downloads.py | 11 ++++++----- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/mhcflurry/class1_affinity_predictor.py b/mhcflurry/class1_affinity_predictor.py index f1251282..7ba6a43b 100644 --- a/mhcflurry/class1_affinity_predictor.py +++ b/mhcflurry/class1_affinity_predictor.py @@ -153,6 +153,9 @@ class Class1AffinityPredictor(object): @property def num_networks(self): + """ + Total number of neural networks (models) + """ return self.manifest_df.shape[0] diff --git a/mhcflurry/class1_neural_network.py b/mhcflurry/class1_neural_network.py index 07ee5a30..eafbbf96 100644 --- a/mhcflurry/class1_neural_network.py +++ b/mhcflurry/class1_neural_network.py @@ -48,15 +48,27 @@ class Class1NeuralNetwork(object): } ], ) + """ + Hyperparameters (and their default values) that affect the neural network + architecture. + """ compile_hyperparameter_defaults = HyperparameterDefaults( loss="mse", optimizer="rmsprop", ) + """ + Loss and optimizer hyperparameters. Any values supported by keras may be + used. + """ input_encoding_hyperparameter_defaults = HyperparameterDefaults( left_edge=4, right_edge=4) + """ + Number of amino acid residues that are given fixed positions on the each + side in the variable length encoding. + """ fit_hyperparameter_defaults = HyperparameterDefaults( max_epochs=500, @@ -70,6 +82,9 @@ class Class1NeuralNetwork(object): random_negative_affinity_max=50000.0, random_negative_match_distribution=True, random_negative_distribution_smoothing=0.0) + """ + Hyperparameters for neural network training. + """ early_stopping_hyperparameter_defaults = HyperparameterDefaults( patience=10, @@ -78,12 +93,18 @@ class Class1NeuralNetwork(object): verbose=1, # currently unused mode='auto' # currently unused ) + """ + Hyperparameters for early stopping. + """ hyperparameter_defaults = network_hyperparameter_defaults.extend( compile_hyperparameter_defaults).extend( input_encoding_hyperparameter_defaults).extend( fit_hyperparameter_defaults).extend( early_stopping_hyperparameter_defaults) + """ + Combined set of all supported hyperparameters and their default values. + """ def __init__(self, **hyperparameters): self.hyperparameters = self.hyperparameter_defaults.with_defaults( @@ -97,9 +118,11 @@ class Class1NeuralNetwork(object): self.fit_seconds = None self.fit_num_points = None - # Process-wide keras model cache. - # architecture JSON string -> (Keras model, existing network weights) KERAS_MODELS_CACHE = {} + """ + Process-wide keras model cache, a map from: architecture JSON string to + (Keras model, existing network weights) + """ @classmethod def borrow_cached_network(klass, network_json, network_weights): diff --git a/mhcflurry/common.py b/mhcflurry/common.py index f87d235d..060dc4f6 100644 --- a/mhcflurry/common.py +++ b/mhcflurry/common.py @@ -71,6 +71,14 @@ def freeze_object(o): def configure_logging(verbose=False): + """ + Configure logging module using defaults. + + Parameters + ---------- + verbose : boolean + If true, output will be at level DEBUG, otherwise, INFO. + """ level = logging.DEBUG if verbose else logging.INFO logging.basicConfig( format="%(asctime)s.%(msecs)d %(levelname)s %(module)s - %(funcName)s:" diff --git a/mhcflurry/downloads.py b/mhcflurry/downloads.py index 81ef467e..21800feb 100644 --- a/mhcflurry/downloads.py +++ b/mhcflurry/downloads.py @@ -69,12 +69,13 @@ def get_current_release_downloads(): Return a dict of all available downloads in the current release. The dict keys are the names of the downloads. The values are a dict - with entries: - downloaded : bool - Whether the download is currently available locally + with two entries: - metadata : dict - Info about the download from downloads.yml such as URL + downloaded : bool + Whether the download is currently available locally + + metadata : dict + Info about the download from downloads.yml such as URL """ downloads = ( get_downloads_metadata() -- GitLab