-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel_compare.py
More file actions
executable file
·42 lines (35 loc) · 1.37 KB
/
model_compare.py
File metadata and controls
executable file
·42 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import absolute_import
import numpy as np
import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()
from rpy2.robjects.packages import importr
import rpy2.robjects as robj
from python_speech_features import mfcc
from python_speech_features import delta
from python_speech_features import logfbank
import scipy.io.wavfile as wav
class CompareModel:
def compare(self,template,testmodel):
R = robj.r
DTW = importr('dtw')
# Generate our data
print "____________________compare_model____________________"
print template.shape
print testmodel.shape
rt,ct = template.shape
rq,cq = testmodel.shape
#converting numpy matrices to R matrices
templateR=R.matrix(template,nrow=rt,ncol=ct)
queryR=R.matrix(testmodel,nrow=rq,ncol=cq)
# Calculate the alignment vector and corresponding distance
alignment = R.dtw(templateR,queryR,keep=True, step_pattern=R.rabinerJuangStepPattern(4,"c"),open_begin=True,open_end=True)
dist = alignment.rx('distance')[0][0]
steps = (template.shape[0]-1) * (template.shape[1]-1) *(testmodel.shape[0]-1)
print "***model_compare***"
print dist
print steps
print template.shape
# print template.shape
print testmodel.shape
print "*******************"
return dist,steps