Skip to content

Commit

Permalink
Merge pull request #106 from neurolib-dev/imp/explorationUtils_plotting
Browse files Browse the repository at this point in the history
Improvement/explorationUtils for plotting
  • Loading branch information
caglorithm authored Jan 20, 2021
2 parents 86e2f5e + 58eb563 commit 1120f20
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
<p align="center">
<a href="https://travis-ci.org/neurolib-dev/neurolib">
<img alt="Header image of neurolib - A Python simulation framework foreasy whole-brain neural mass modeling." src="https://github.com/neurolib-dev/neurolib/raw/master/resources/readme_header.png" ></a>
<img alt="Header image of neurolib - A Python simulation framework foreasy whole-brain neural mass modeling." src="https://github.com/neurolib-dev/neurolib/raw/master/resources/readme_header.png" >
</p>
<p align="center">
<a href="https://github.com/neurolib-dev/neurolib/actions">
<img alt="Build" src="https://img.shields.io/github/workflow/status/neurolib-dev/neurolib/ci"></a>

<a href="https://zenodo.org/badge/latestdoi/236208651">
<img alt="DOI" src="https://zenodo.org/badge/236208651.svg"></a>


<a href="https://github.com/neurolib-dev/neurolib/releases">
<img alt="Release" src="https://img.shields.io/github/v/release/neurolib-dev/neurolib"></a>

<br>

<a href="https://codecov.io/gh/neurolib-dev/neurolib">
<img alt="codecov" src="https://codecov.io/gh/neurolib-dev/neurolib/branch/master/graph/badge.svg"></a>

<a href="https://pepy.tech/project/neurolib">
<img alt="Downloads" src="https://pepy.tech/badge/neurolib"></a>

<a href="https://github.com/psf/black">
<img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>

<a href="https://mybinder.org/v2/gh/neurolib-dev/neurolib.git/master?filepath=examples">
<img alt="Launch in binder" src="https://mybinder.org/badge_logo.svg"></a>

</p>


Expand Down
15 changes: 11 additions & 4 deletions neurolib/optimize/evolution/evolutionaryUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def plotScoresDistribution(scores, gIdx, save_plots=None, color="C0"):
plt.show()


def plotSeabornScatter1(evolution, dfPop=None, save_plots=None, color="C0"):
def plotSeabornScatter1(evolution, dfPop=None, save_plots=None, color="C0", line_kws={}, scatter_kws={}):
import matplotlib.pyplot as plt
import seaborn as sns

Expand All @@ -105,12 +105,18 @@ def plotSeabornScatter1(evolution, dfPop=None, save_plots=None, color="C0"):
dfPop = evolution.dfPop()

fig = plt.figure()

_line_kws = {"color": color}
_line_kws.update(line_kws)
_scatter_kws = {"alpha": 0.5, "color": color}
_scatter_kws.update(scatter_kws)

sm = sns.pairplot(
dfPop,
vars=vars,
diag_kind="kde",
kind="reg",
plot_kws={"line_kws": {"color": color}, "scatter_kws": {"alpha": 0.5, "color": color},},
plot_kws={"line_kws": _line_kws, "scatter_kws": _scatter_kws,},
diag_kws={"color": color},
)

Expand Down Expand Up @@ -191,10 +197,10 @@ def plotProgress(evolution, reverse=True):

gens, all_scores = evolution.getScoresDuringEvolution(reverse=reverse)

fig, axs = plt.subplots(2, 1, figsize=(3.5, 3), dpi=150, sharex=True, gridspec_kw={"height_ratios": [2, 1]},)
fig, axs = plt.subplots(2, 1, figsize=(3.5, 3), sharex=True, gridspec_kw={"height_ratios": [2, 1]},)
im = axs[0].imshow(all_scores.T, aspect="auto", origin="lower")
axs[0].set_ylabel("Individuals")
cbar_ax = fig.add_axes([0.93, 0.42, 0.02, 0.3])
cbar_ax = fig.add_axes([1.0, 0.55, 0.02, 0.3])
fig.colorbar(im, cax=cbar_ax, label="Score")

axs[1].plot(gens, np.nanmean(all_scores, axis=1), label="Average")
Expand All @@ -203,6 +209,7 @@ def plotProgress(evolution, reverse=True):
)
axs[1].set_xlabel("Generation")
axs[1].set_ylabel("Score")
plt.tight_layout()
plt.show()


Expand Down
23 changes: 23 additions & 0 deletions neurolib/utils/devutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
import scipy

import sys

import neurolib.utils.functions as func


Expand Down Expand Up @@ -333,3 +335,24 @@ def rolling_window(array, window=(0,), asteps=None, wsteps=None, axes=None, toen
new_shape = new_shape[new_shape != 0]

return np.lib.stride_tricks.as_strided(array, shape=new_shape, strides=new_strides)


def get_size(obj, seen=None):
"""Recursively finds size of objects"""
size = sys.getsizeof(obj)
if seen is None:
seen = set()
obj_id = id(obj)
if obj_id in seen:
return 0
# Important mark as seen *before* entering recursion to gracefully handle
# self-referential objects
seen.add(obj_id)
if isinstance(obj, dict):
size += sum([get_size(v, seen) for v in obj.values()])
size += sum([get_size(k, seen) for k in obj.keys()])
elif hasattr(obj, "__dict__"):
size += get_size(obj.__dict__, seen)
elif hasattr(obj, "__iter__") and not isinstance(obj, (str, bytes, bytearray)):
size += sum([get_size(i, seen) for i in obj])
return size

0 comments on commit 1120f20

Please sign in to comment.