@@ 46,6 46,11 @@ functor ConstrainedDTWFn (ARG : CONSTRAI
type dtw = {
costFunction : cost_function,
+ stepFactors : {
+ horizontal : cost -> cost,
+ vertical : cost -> cost,
+ diagonal : cost -> cost
+ },
searchWidth : int
}
@@ 252,14 257,25 @@ functor ConstrainedDTWFn (ARG : CONSTRAI
case ARG.Cost.compare (c1, c2) of
LESS => c1
| _ => c2
- val bestCost =
+ val costVertical =
ARG.Cost.add
- (costHere,
- (if i > 0
- then min (costAtLeft,
- min (Vector.sub (costs, i),
- Vector.sub (costs, i-1)))
- else Vector.sub (costs, i)))
+ ((#vertical (#stepFactors dtw)) costHere,
+ Vector.sub (costs, i))
+ val costHorizontal =
+ if i > 0
+ then ARG.Cost.add
+ ((#horizontal (#stepFactors dtw)) costHere,
+ costAtLeft)
+ else ARG.Cost.infinite
+ val costDiagonal =
+ if i > 0
+ then ARG.Cost.add
+ ((#diagonal (#stepFactors dtw)) costHere,
+ Vector.sub (costs, i-1))
+ else ARG.Cost.infinite
+ val bestCost =
+ min (costHorizontal,
+ min (costVertical, costDiagonal))
in
SOME ((i + 1, bestCost), bestCost)
end
@@ 641,13 657,8 @@ functor FileBackedDTWCostVectorFn (ARG :
val sub = BackedVector.sub
end
-
-functor RealConstrainedDTWFn (Feature : sig
- type feature
- type feature_vector
- val length : feature_vector -> int
- val sub : feature_vector * int -> feature
- end)
+
+functor RealConstrainedDTWFn (Feature : CONSTRAINED_DTW_FEATURE)
= ConstrainedDTWFn (struct
structure Feature = Feature
structure Cost = struct
@@ 660,12 671,7 @@ functor RealConstrainedDTWFn (Feature :
structure CostVector = InMemoryDTWCostVectorFn (Cost)
end)
-functor Real32ConstrainedDTWFn (Feature : sig
- type feature
- type feature_vector
- val length : feature_vector -> int
- val sub : feature_vector * int -> feature
- end)
+functor Real32ConstrainedDTWFn (Feature : CONSTRAINED_DTW_FEATURE)
= ConstrainedDTWFn (struct
structure Feature = Feature
structure Cost = struct