-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENH] Improved output messages/status information of ASSET functions #570
[ENH] Improved output messages/status information of ASSET functions #570
Conversation
…hant into feature/asset_logging
Hey @kohlerca , Doctests fail, since the print statements have been removed, so the output of e.g. elephant/elephant/asset/asset.py Lines 85 to 88 in 5b464ec
is no longer printed out. Fix: adapt example code accordingly (?). Run doctest with: |
Yes, I think the examples will also look cleaner with the removal of those text messages. For the doctests, just the final SSEs are the relevant output. |
@Moritz-Alexander-Kern I think this should also be considered with #567 |
Hey @kohlerca , I have used the following code example to test out the logging feature: # 1. Simulate two noise synfire chains, shuffle the neurons to destroy the
# pattern visually, and store shuffled activations in neo.SpikeTrains.
import logging
import neo
import numpy as np
import quantities as pq
from pprint import pprint
from elephant.asset.asset import logger as asset_logger
from elephant import asset
asset_logger.setLevel(logging.DEBUG)
verbosity=True
np.random.seed(10)
spiketrain = np.linspace(0, 50, num=10)
np.random.shuffle(spiketrain)
spiketrains = np.c_[spiketrain, spiketrain + 100]
spiketrains += np.random.random_sample(spiketrains.shape) * 5
spiketrains = [neo.SpikeTrain(st, units='ms', t_stop=1 * pq.s)
for st in spiketrains]
# 2. Create `ASSET` class object that holds spike trains.
# `ASSET` requires at least one argument - a list of spike trains. If
# `spiketrains_y` is not provided, the same spike trains are used to build an
# intersection matrix with.
asset_obj = asset.ASSET(spiketrains, bin_size=3*pq.ms, verbose=verbosity)
# 3. Build the intersection matrix `imat`:
imat = asset_obj.intersection_matrix()
# 4. Estimate the probability matrix `pmat`, using the analytical method:
pmat = asset_obj.probability_matrix_analytical(imat, kernel_width=50*pq.ms)
# 5. Compute the joint probability matrix `jmat`, using a suitable filter:
jmat = asset_obj.joint_probability_matrix(pmat, filter_shape=(5, 1), n_largest=3)
# 6. Create the masked version of the intersection matrix, `mmat`, from `pmat`
# and `jmat`:
mmat = asset_obj.mask_matrices([pmat, jmat], thresholds=.9)
# 7. Cluster significant elements of imat into diagonal structures:
cmat = asset_obj.cluster_matrix_entries(mmat, max_distance=11, min_neighbors=3, stretch=5)
# 9. Extract sequences of synchronous events:
sses = asset_obj.extract_synchronous_events(cmat)
# The ASSET found the following sequences of synchronous events:
pprint(sses) The code snippet demonstrates the usage of logging messages with either the Playing around with both the log level and the verbose parameter simultaneously, it seems to me, the current implementation introduces unnecessary complexity and even potential confusion (?). Maybe we can remove the Ideas welcome, lets develop this approach. 🙂 |
For the output control, in my opinion, everything should be controlled by the For
|
…ning, add tests for deprecation warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build wheels
verbose : bool, optional | ||
Display progress bars and log messages. | ||
Default: False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter is still there, so it should be listed as a deprecated non-functional parameter, also indicating how functionality is now handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
verbose : deprecated
This parameter is no longer functional. To control the verbosity of log messages, please use the module's logger that is based on the standard logging module. Logging is turned on by default (to level INFO). To restrict logging messages, use a higher logging level to WARNING or ERROR, e.g.,
import logging
from elephant.asset.asset import logger as asset_logger
asset_logger.set_level(logging.WARNING)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good suggestion. I believe there is a directive for Sphinx so that the deprecation is visible.
.. deprecated:: 0.14.0
This parameter is no longer .....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added deprecation, see: bdeb5e6
elephant/asset/asset.py
Outdated
logger.debug("Finding transactions") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be info?
logger.debug("Finding transactions") | |
logger.info("Finding transactions") | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember adding this to be able to check if the extraction was working, as it can take a long time and one may suspect everything hung. But looking in more detail now, perhaps the best is to put logger.info
calls in the main extract_synchronous_events
method, as this may be called twice if spiketrains_j
was passed, and the logging would be weird with two identical messages. This way, we could have explicit logging information messages for each list of spike trains being processed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed logging level to INFO and move logging call to extract_synchronous_events
function, see: 3f5211a
…extract_synchronous_events function
This PR replaces ordinary
print
statements throughout ASSET withlogging
calls.Moreover, steps that use loops also have improved output by using
tqdm
progress bars.Any INFO logging is controlled by the usual
verbose
parameter in the functions. Moreover, the user can use the standard log level setting to enable specific messages, as DEBUG messages were also included.