Ejemplo n.º 1
0
import unittest, importlib
from smp_base.impl import smpi

# func = {}

imports_req = {
    'numpy': 'np',
}

imports_opt = {
    'matplotlib.pyplot': 'plt',
}

logging = smpi('logging')
get_module_logger = smpi('smp_base.common', 'get_module_logger')

# from cloud.serialization.cloudpickle import dumps
# from collections import OrderedDict
# from cycler import cycler
# from emd import emd
# from functools import partial, wraps, reduce
# from igmm_cond import IGMM_COND
# from jpype import JPackage, getDefaultJVMPath, isJVMStarted, startJVM, attachThreadToJVM, isThreadAttachedToJVM
# from kohonen.kohonen import argsample
# from kohonen.kohonen import Gas, GrowingGas, GrowingGasParameters, Filter
# from kohonen.kohonen import Map, Parameters, ExponentialTimeseries, ConstantTimeseries
# from matplotlib.font_manager import FontManager, FontProperties
# from matplotlib import colorbar as mplcolorbar
# from matplotlib import gridspec
# from matplotlib import rc, rcParams, rc_params
# from matplotlib.pyplot import figure
Ejemplo n.º 2
0
 def test_smpi(self):
     self.assertEqual(smpi('numpy'), importlib.import_module('numpy'),
                      "Should be numpy")
Ejemplo n.º 3
0
"""smp_base.common

common and frequently required small patterns and util functions

.. TODO:: consolidate with :mod:`smp_graphs.common`
"""

from smp_base.impl import smpi

logging = smpi('logging')
reduce = smpi('functools', 'reduce')


def get_module_logger(modulename='experiment', loglevel=logging.INFO):
    """get a logging.logger instance with reasonable defaults

    Create a new logger and configure its name, loglevel, formatter
    and output stream handling.
    1. initialize a logger with name from arg 'modulename'
    2. set loglevel from arg 'loglevel'
    3. configure matching streamhandler
    4. set formatting swag
    5. return the logger
    """
    loglevels = {
        'debug': logging.DEBUG,
        'info': logging.INFO,
        'warn': logging.WARNING
    }
    if type(loglevel) is str:
        try:
Ejemplo n.º 4
0
In addition there are some soft requirements, or conventions,
respectively like a bootstrap method that prepares an untrained
subordinate model for inference, a visualize method that provides some
visualization of the model's current state for debugging and analysis
and a save/load method pair for storing and loading model's which is
useful for large models with long training times.

Things:
 - use abstract method defs, either abc or NotImplementedError
 - merge stray models such as UniformRandomBlock2, iir, CodingBlock2, ...
 - fix visualization
"""
from smp_base.impl import smpi

# req
pickle = smpi('pickle')
np = smpi('numpy')

# smp foo
set_attr_from_dict = smpi('smp_base.common', 'set_attr_from_dict')
set_interactive = smpi('smp_base.plot_utils', 'set_interactive')

################################################################################
# smpModel decorator init
class smpModelInit():
    """smpModelInit wrapper"""
    def __call__(self, f):
        def wrap(xself, *args, **kwargs):
            # print "args", args
            # print "kwargs", kwargs
            assert 'conf' in kwargs, "smpModel needs conf dict"
Ejemplo n.º 5
0
.. todo:: Make it a class of @staticmethods
"""
from smp_base.impl import smpi

import numpy as np
from scipy.io import wavfile as wavfile
# import mdp

import logging
from smp_base.common import get_module_logger, compose

loglevel_debug = logging.DEBUG
logger = get_module_logger(modulename='datasets', loglevel=logging.INFO)

Oger = smpi('Oger')


def get_mackey_glass(sample_len=1000, n_samples=1):
    # check Oger imported by name exists in globals and its value a module
    if 'Oger' in globals() and Oger is not None:
        logger.debug('get_mackey_glass Oger = {0}'.format(Oger))
        return Oger.datasets.mackey_glass(sample_len=sample_len,
                                          n_samples=n_samples)

    logger.warn('datasets.get_mackey_glass: Oger not found, returning zeros')
    # return np.zeros((n_samples, 1, sample_len))
    return [[np.zeros((sample_len, 1))] for _ in list(range(n_samples))]


def wavdataset(sample_len, n_samples, filename, n_offset=None, numchan=1):
Ejemplo n.º 6
0
- compute_segments (librosa, essentia)
- compute_chroma_librosa
- compute_tempogram_librosa
- compute_onsets_librosa
- compute_beats_librosa
- compute_beats_mix

- beats_to_bpm
"""
import argparse, os
import json
import numpy as np

from smp_base.impl import smpi
# import logging
logging = smpi('logging')

DEBUG = True


# numpy encoder json ndarray/list
class NumpyEncoder(json.JSONEncoder):
    """ Special json encoder for numpy types """
    def default(self, obj):
        if isinstance(obj, np.integer):
            return int(obj)
        elif isinstance(obj, np.floating):
            return float(obj)
        elif isinstance(obj, np.ndarray):
            return obj.tolist()
        return json.JSONEncoder.default(self, obj)
Ejemplo n.º 7
0
"""smp_audio.common_api

define the api and map calls to one or more implementation libraries,
merge results if required and return final prediction

### data_load

fix streaming vs. buffered load issue

### data_stream

### etc
"""
from smp_base.impl import smpi
# import logging
logging = smpi('logging')
common_aubio = smpi('common_aubio')
common_librosa = smpi('common_librosa')
common_essentia = smpi('common_essentia')

DEBUG = True


def data_load(**kwargs):
    if common_aubio is not None:
        print('aubio loaded {0}'.format(common_aubio))
        return common_aubio.data_load_aubio(**kwargs)
    if common_librosa is not None:
        print('librosa loaded {0}'.format(common_librosa))
        return common_librosa.data_load_librosa(**kwargs)
    if common_essentia is not None:
Ejemplo n.º 8
0
Generate special noise distributions: 1/f noise, levyflights

.. note::

   oneoverfnoise is a python port of gennoise.c by paul bourke

   levyflight is homegrown (?)
"""
# import argparse

#####
from smp_base.impl import smpcls, smpi

# required
argparse = smpi('argparse')
logging = smpi('logging')
np = smpi('numpy')

# optional
normalize = smpi('sklearn.preprocessing', 'normalize')
get_module_logger = smpi('smp_base.common', 'get_module_logger')
plot_gennoise = smpi('smp_base.plot_models', 'plot_gennoise')

logger = get_module_logger(modulename='gennoise', loglevel=logging.INFO)

N = 8192
TWOPOWER = 13
TWOPI = 6.283185307179586476925287

Ejemplo n.º 9
0
Archivo: lr.py Proyecto: x75/smp_base
"""smp_base.lr

.. moduleauthor:: Oswald Berthold

learning rules (lr)
"""

from smp_base.impl import smpi

logging = smpi('logging')
get_module_logger = smpi('smp_base.common', 'get_module_logger')
logger = get_module_logger(modulename='lr', loglevel=logging.DEBUG)

np = smpi('numpy')
rlspy = smpi('rlspy')

isdefined = smpi('smp_base.common', 'isdefined')


class rlspyDummy(object):
    def __init__(self, x0, P0):
        """Returns new RLS estimator."""
        self.x = x0
        self.P = P0
        self.y = np.zeros((1, x0.shape[1]))
        self.dx = np.zeros_like(self.y)
        # identity matrix same size as P for convenience
        self.I = np.identity(len(x0))

    def single_update(self, A, b, v):
        logger.warn('rlspyDummy.single_update: implement me')