GithubHelp home page GithubHelp logo

jiaangyao / bcgnet Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 10.0 143.91 MB

BCGNet: Deep Learning Toolbox for BCG Artifact Reduction

License: MIT License

Python 89.16% Jupyter Notebook 10.84%
eeg-fmri bcg ballistocardiogram deep-learning

bcgnet's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bcgnet's Issues

Hashes in data file names

  1. I suggest we have a new module where everything that gets used by multiple modules gets stored (it's basically a supporting module for all other modules).

  2. @Yida-Lin it's quite useful to include a hash of the opt in the file name, so that when you change the opt, you don't accidentally reload a file that was made with a different opt. So, the following would be part of what I described in 1). See end of code for usage -

import hashlib
import random
from collections import namedtuple
import numpy as np


def set_seed(ps):
    """
    Sets the seed based on a string (e.g. path)

    :type ps: str
    :param ps: any string to be hashed
    """

    hash_ = gen_hash(ps)
    random.seed(hash_)
    np.random.seed(hash_)  # not tested


def gen_hash(ps):
    """
    Gets the hash of a string (e.g. path)

    :type ps: str
    :param ps: any string to be hashed
    """

    str_hash = str(ps)
    hash_object = hashlib.md5(str_hash.encode('utf-8'))
    hash = int(hash_object.hexdigest(), 16) % 2 ** 32
    return hash


def namedtuple_to_hashable_dict(opt, exclusions=None, **kwargs):
    """Generate a dictionary of items to be hashed"""
    default_exclusions = ['overwrite', 'plot']
    if exclusions:
        exclusions = default_exclusions.append(exclusions)
    else:
        exclusions = default_exclusions

    hashable_dict = opt._asdict()
    hashable_dict.update(kwargs)  # in case you want to add something extra

    # remove overwrite strings and opt_met stuff
    for e in exclusions:
        hashable_dict = {k: v for k, v in hashable_dict.items() if e not in k}
    hashable_dict = {k: v for k, v in hashable_dict.items() if v is not None}

    # force the ordering
    hashable_dict = {k: v for k, v in sorted(hashable_dict.items())}

    return hashable_dict


def dictionary_to_hash(hashable_dict):
    ip_string = dictionary_to_string(hashable_dict)
    return gen_hash(ip_string)


def dictionary_to_string(hashable_dict):
    ip_string = ''
    for k, v in hashable_dict.items():
        ip_string = ip_string + k
        if not isinstance(v, list):
            v = [v]
        for i in v:
            ip_string = ip_string + str(i) + '_'
    return ip_string


if __name__ == "__main__":
    Person = namedtuple('Person', 'name age gender')
    opt = Person(name='John', age=45, gender='male')

    dh = namedtuple_to_hashable_dict(opt)
    h = dictionary_to_hash(dh, exclusions=None)
    # h can then be used in the string specification of saved files (so that if you change something in opt
    # you know that the saved file doesn't match). You can add exclusions (as there are somethings that you want to be
    # able to change in opt, without triggering new file generation).

    # this can also be used to set the seed when processing individual subjects so that we get reliable seeds for each subject:
    subject_hash = gen_hash('subject_name')
    set_seed(subject_hash)

Suggestions on demo.ipynb

I think this might be confusing to the user
image

and then here
image

Users might feel lost when we give them too many choices. This demo should be as simple and precise as a tutorial. If really needed, we can add an extra section and do something like this:

Config in Yaml (Optional 1, Recommended)

Config in Python (Optional 2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.