def plot_pr_curve(data,startPoints,filename,legend_string): mlab.addpath('/home/cchansen/snp_analysis/common') xlabel = 'Recall' ylabel = 'Precision' xlim = n.array([0,1]) ylim = n.array([0,1]) mlab.create_pdf_plot(data,startPoints,'',filename,xlabel,14,ylabel,14,xlim,ylim,legend_string)
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") mlab.addpath(src_dir)
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)), "features") toolbox = os.path.join(features, "matlab-chroma-toolbox") mlab.addpath(toolbox)
def generateBSAinput(scale=10): from mlabwrap import mlab #mlab.addpath('../') mlab.addpath('/home/mammoth/dejan/simtools/AuditoryToolbox') mlab.addpath('/home/mammoth/dejan/simtools/RCToolbox') mlab.addpath('/home/mammoth/dejan/simtools/RCToolbox/spike_coding') mlab.addpath('/home/mammoth/dejan/simtools/RCToolbox/utility') mlab.addpath('/home/mammoth/dejan/simtools/speech') currDir = os.getcwd() mlab.cd('/home/mammoth/dejan/simtools/speech') mlab.startup() #mlab.cd(currDir) mlab.cd('/home/mammoth/dejan/simtools/RCToolbox') InputDist = mlab.preprocessed_speech('scale', scale) h5filename = 'spkdata_%d.h5' % scale N = mlab.get(InputDist, 'size').flatten() N_rev = mlab.get(InputDist, 'rev_size').flatten() NN = N + N_rev print "Saving inputs..." for i in range(NN): stimulus = PreprocessedSpeechStimulus() S = mlab.generate_input(InputDist, i + 1) nc = mlab.length(S.channel).flatten() for c in range(nc): channel = Channel(S.channel[c].data.flatten()) stimulus.channel.append(channel) stimulus.Tsim = S.info.Tstim.flatten()[0] stimulus.file = S.info.file stimulus.speaker = S.info.speaker.flatten()[0] stimulus.utterance = S.info.utterance.flatten()[0] stimulus.digit = S.info.digit.flatten()[0] stimulus.reversed = S.info.reversed.flatten()[0] == 1 if stimulus.reversed: grpname = stimulus.file + "_rev" else: grpname = stimulus.file print "%d: %s" % (i, grpname) stimulus.save(filename=h5filename, grpname=grpname)
import scipy as sp import scipy.io import plca from string import lower import csv logging.basicConfig(level=logging.INFO, format='%(levelname)s %(name)s %(asctime)s ' '%(filename)s:%(lineno)d %(message)s') logger = logging.getLogger('segmenter') try: from mlabwrap import mlab mlab.addpath('coversongs') except: 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', wavfilename) 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 warnings.filterwarnings('ignore',category=DeprecationWarning) from mlabwrap import mlab warnings.filterwarnings('default',category=DeprecationWarning) # 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! mlab.addpath(kal_toolbox_path) mlab.addpath(os.path.join(kal_toolbox_path,'Kalman')) mlab.addpath(os.path.join(kal_toolbox_path,'KPMstats')) mlab.addpath(os.path.join(kal_toolbox_path,'KPMtools')) mlab.warning('on','all') 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) INPUT data - one sequence, one observation per col A - DxD matrix, D dimension of hidden state
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))
# --------------------------------------------------------------------------- # # 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]' mlab.addpath(mlab.genpath('../minimal')) # ----------------------------------------------------------- # # 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]
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') matlab.addpath(mlab_path) _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."""
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))
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 try: mlab.sin(1) except: # 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. Parameters ---------- track : gordon Track instance fctr : float
import optparse import os import sys import numpy as np import scipy as sp import scipy.io import plca logging.basicConfig(level=logging.INFO) logger = logging.getLogger('segmenter') try: from mlabwrap import mlab mlab.addpath('coversongs') except: 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()
import os import sys import numpy as np import scipy as sp import scipy.io import plca logging.basicConfig(level=logging.INFO) logger = logging.getLogger("segmenter") try: from mlabwrap import mlab mlab.addpath("coversongs") except: 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 mlab.addpath(os.path.abspath(rondir)) mlab.addpath(os.path.abspath('.')) # 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):
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 mlab.addpath(_code_dir) 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 """ wav = wavread(wavpath)
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 mlab.addpath(os.path.abspath(rondir)) mlab.addpath(os.path.abspath('.')) # 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 = []
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 mlab.addpath(_code_dir) 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 os import sys import tempfile import numpy as np # MATLAB wrapper, we remove the dperecation warnings import warnings warnings.filterwarnings('ignore', category=DeprecationWarning) from mlabwrap import mlab warnings.filterwarnings('default', category=DeprecationWarning) # 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! mlab.addpath(kal_toolbox_path) mlab.addpath(os.path.join(kal_toolbox_path, 'Kalman')) mlab.addpath(os.path.join(kal_toolbox_path, 'KPMstats')) mlab.addpath(os.path.join(kal_toolbox_path, 'KPMtools')) mlab.warning('on', 'all') 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) INPUT data - one sequence, one observation per col A - DxD matrix, D dimension of hidden state