Exemple #1
    def __init__(self, sigma = 0.2, _lambda = np.exp(-15), Nadd = 150, output = 0, maxIter = np.inf,
                epsilon = 0.001, delta_k = 1, tempInt = 0.95, epsilon_back = 0.001, flyComputeK = 0,
                deselect = 0, CV = None, lambdas = np.r_[[np.exp(-12)], np.exp(np.arange(-10,-3))], 
                sigmas = np.sqrt(1. / (2. * 2.**np.arange(-5, 3)))):

        self.sigma = sigma
        self._lambda = _lambda
        self.Nadd = Nadd
        self.output = output
        self.maxIter = maxIter
        self.epsilon = epsilon
        self.delta_k = delta_k
        self.tempInt = tempInt
        self.epsilon_back = epsilon_back
        self.flyComputeK = flyComputeK
        self.deselect = deselect
        self.CV = CV
        self.lambdas = lambdas
        self.sigmas = sigmas

        this_dir, this_filename = os.path.split(__file__)
        src_dir = os.path.join(this_dir, "ivmSoftware4.3/src")

Exemple #2
def load_matlab():
    Imports and starts matlab bridge if not started.

    global mlab
    global MatlabError

    from mlabwrap import mlab
    from mlabraw import error as MatlabError

    abspath = os.path.abspath(__file__)
    features = os.path.join(os.path.dirname(os.path.dirname(abspath)),
    toolbox = os.path.join(features, "matlab-chroma-toolbox")
import os
import sys
import numpy as np

from mlabwrap import mlab
import scikits.audiolab as AUDIOLAB

# makes sure we have the right matlab files
# save their absolute path
_code_dir = os.path.dirname(__file__)
_find_landmarks_path = os.path.join(os.path.abspath(_code_dir), "find_landmarks.m")
if not os.path.exists(_find_landmarks_path):
    print "can't find find_lanmarks.m, not same place as get_landmarks?"
    print "get_landmarks.py dir:", _code_dir
    raise ImportError

def wavread(path):
    Wrapper around scikits functions
    Returns: wavdata, sample rate, encoding type
    See pyaudiolab or scikits.audiolab for more information
    return AUDIOLAB.wavread(path)

def find_landmarks_from_wav(wavpath):
    utility function, open wav, calls find_landmarks
import scipy as sp
import scipy.io

import plca

from string import lower
import csv

                    format='%(levelname)s %(name)s %(asctime)s '
                    '%(filename)s:%(lineno)d  %(message)s')
logger = logging.getLogger('segmenter')

    from mlabwrap import mlab
    logger.warning('Unable to import mlab module.  Feature extraction '
                   'and evaluation will not work.')

def extract_features(wavfilename, fctr=400, fsd=1.0, type=1):
    """Computes beat-synchronous chroma features from the given wave file

    Calls Dan Ellis' chrombeatftrs Matlab function.
    if lower(wavfilename[-4:]) == '.csv':
        logger.info('CSV filename reading preprocessed features from %s',
        csvr = csv.reader(open(wavfilename, 'rb'), delimiter=',')
        feats = np.array([[float(x) for x in row] for row in csvr])

import os
import sys
import tempfile
import numpy as np
# MATLAB wrapper, we remove the dperecation warnings
import warnings
from mlabwrap import mlab
# kalman toolbox path
kal_toolbox_path = '/home/thierry/Columbia/Imputation/PythonSrc/KalmanAll'
mlab.warning('off','all') # hack, remove warnings
                          # some functions are redefined but who cares!

def learn_kalman(data,A,C,Q,R,initx,initV,niter,diagQ=1,diagR=1):
    Main function, take initial parameters and train a Kalman filter.
    We assume a model:
      x(t+1) = A*x(t) + w(t),  w ~ N(0, Q),  x(0) ~ N(init_x, init_V)
      y(t)   = C*x(t) + v(t),  v ~ N(0, R)
      data   - one sequence, one observation per col
      A      - DxD matrix, D dimension of hidden state
# --------------------------------------------------------------------------- #
# example.py
# Tarik Tosun, 2012-07-19
# Description:
#     Demonstrates what you can do with python-retargeter.
# --------------------------------------------------------------------------- #

import numpy as np
import scipy as sp
from mlabwrap import mlab
# when mlabwrap is imported, it starts an instance of matlab which runs in the
# background.  Nearly any matlab function may be called as: 'mlab.[function]'


# ----------------------------------------------------------- #
# Creating Kinematic Chain Models: 
# ----------------------------------------------------------- #

# pr2larm(length_total) returns a simulated PR2 left arm of specified total
# length. (pr2rarm returns a simulated PR2 right arm.)
# Degrees of freedom:
#     [shoulder_yaw, shoulder_tilt, shoulder_roll, elbow_flex]
L = 300
pr2 = mlab.pr2rarm(L)

# human24(lengths) returns a 2-link, 4-dof chain similar to a human arm.  the
# lengths vector specifies link lengths.
# Degrees of freedom:
#     [shoulder_roll, shoulder_yaw, shoulder_pitch, elbow_pitch]
Exemple #7
from mlabwrap import mlab as matlab

# give an interface to the mlab system through cobra.matlab
cobra.matlab = matlab
matlab.__doc__ = """
This is an mlabwrap connection to MATLAB which can be used to call
MATLAB functions. For example, if model is a python model, the following
can be used to optimize the model in MATLAB:
> matlab_model = cobra.mlab.cobra_model_object_to_cobra_matlab_struct(model)
> result = cobra.matlab.optimizeCbModel(matlab_model)

Any MATLAB function can be called this way"""

# add path with module's python scripts to the MATLAB path
mlab_path = os.path.join(cobra.__path__[0], 'mlab', 'matlab_scripts')

_possible_cobra_locations = ["~/MATLAB/cobra", "~/cobra",
    "~/Documents/MATLAB/cobra", "~/Documents/opencobra/matlab/cobra"]

def init_matlab_toolbox(matlab_cobra_path=None, discover_functions=True):
    """initialize the matlab cobra toolbox, and load its functions
    into mlab's namespace (very useful for ipython tab completion)

    matlab_cobra_path: the path to the directory containing the MATLAB
    cobra installation. Using the default None will attempt to find the
    toolbox in the MATLAB path
    discover_functions: Whether mlabwrap should autodiscover all cobra toolbox
    functions in matlab. This is convenient for tab completion, but may take
    some time."""
except ImportError:
    print 'Unable to import mlab module.  Attempting to install...'
    os.system('cd %s; python setup.py build' % MLABWRAPDIR)
    basedir = '%s/build/' % MLABWRAPDIR
    sys.path.extend([os.path.join(basedir, x) for x in os.listdir(basedir)
                     if x.startswith('lib')])
    from mlabwrap import mlab

    # Re-initialize the broken connection to the Matlab engine.
    import mlabraw
    mlab._session = mlabraw.open()

mlab.addpath(os.path.join(CURRDIR, 'coversongs'))

def extract_features(track, fctr=400, fsd=1.0, type=1):
    """Computes beat-synchronous chroma features.

    Uses Dan Ellis' chrombeatftrs Matlab function (via the mlabwrap
    module, which is included with this feature extractor).

    See http://labrosa.ee.columbia.edu/projects/coversongs
    for more details.

    track : gordon Track instance
    fctr : float
import os
import sys

import numpy as np
import scipy as sp
import scipy.io

import plca

logger = logging.getLogger("segmenter")

    from mlabwrap import mlab

    logger.warning("Unable to import mlab module.  Feature extraction " "and evaluation will not work.")

def extract_features(wavfilename, fctr=400, fsd=1.0, type=1):
    """Computes beat-synchronous chroma features from the given wave file

    Calls Dan Ellis' chrombeatftrs Matlab function.
    x, fs = mlab.wavread(wavfilename, nout=2)
    feats, beats = mlab.chrombeatftrs(x, fs, fctr, fsd, type, nout=2)
    return feats, beats.flatten()

def segment_song(
Also, can use codebook encoding.

T. Bertin-Mahieux (2010) Columbia University
[email protected]

import os
import sys
import glob
import numpy as np
import scipy.io as sio

rondir = 'ronwsiplca'
from ronwsiplca import segmenter as SEGMENTER
from mlabwrap import mlab

# beatles directories on my machines (TBM)
_enfeats_dir = os.path.expanduser('~/Columbia/InfiniteListener/beatles_enbeatfeats')
_audio_dir = os.path.expanduser('~/Columbia/InfiniteListener/beatles_audio')
_seglab_dir = os.path.expanduser('~/Columbia/InfiniteListener/beatles_seglab')

def get_all_files(basedir,pattern='*.wav') :
    From a root directory, go through all subdirectories
    and find all files that fit the pattern. Return them in a list.
    allfiles = []
    for root, dirs, files in os.walk(basedir):
Exemple #11
from mlabwrap import mlab
import pycuda.autoinit
import pycuda.driver as drv
import numpy
from pycuda.compiler import SourceModule

mlab.addpath('../FasihSarStuff/', nout=0)

# Params
clight = 299792458.0
block_width = 16
block_height = 16

# Matlab data loading
data = mlab.helper3DSAR()
#data = mlab.helperMTI()

data = mlab.rangeCompress(data)

mdouble = mlab.double;
do = lambda x: float(mdouble(x)[0,0])
nint    = numpy.int32
nfloat  = numpy.float32

rp = mdouble(data.upsampled_range_profiles)

im = numpy.zeros_like(data.im_final).astype(numpy.complex64)
[Nimg_height, Nimg_width] = im.shape
delta_pixel_x = numpy.diff(data.x_vec)[0,0]
delta_pixel_y = numpy.diff(data.y_vec)[0,0]
c__4_deltaF = clight / (4.0 * do(data.deltaF))