def warp2(f, g): #esmooth,usmooth = 0,0.0 esmooth, usmooth = 2, 8.0 rsmooth = 101 strainMax1 = 0.125 strainMax2 = 0.125 nr = int(rsmooth) dr = 2.0 * strainMax1 / (nr - 1) fr = -strainMax1 sr = Sampling(nr, dr, fr) shiftMax = 10 shiftMin = -shiftMax dw = DynamicWarping(shiftMin, shiftMax) dw.setErrorExtrapolation(DynamicWarping.ErrorExtrapolation.REFLECT) dw.setStrainMax(strainMax1, strainMax2) dw.setShiftSmoothing(usmooth) e = dw.computeErrors(f, g) for ismooth in range(esmooth): dw.smoothErrors(e, e) d = dw.accumulateForward1(e) u = dw.backtrackReverse1(d, e) #u = dw.smoothShifts(sr,u) u = dw.smoothShifts(u) h = dw.applyShifts(u, g) print "warp2: u min =", min(u), " max =", max(u) return u, h
def goFakeErrors(): dw = DynamicWarping(shiftMin, shiftMax) u = zerofloat(n1) for cs in [1.0, 0.5]: e = dw.fakeErrors(cs, nl, n1) plotShifts(e) for ds in [1.0, 0.1, 0.01]: u[0] = 0.0 esum = dw.findShiftsSmooth(ds, e, u) print "cs =", cs, " ds=", ds, " esum =", esum plotShifts(e, u)
def warp1(f, g): usmooth = 8.0 rsmooth = 101 strainMax1 = 0.125 #strainMax1 = 1.0 dstrainMax1 = 0.1 shiftMin = 0 shiftMax = 160 #shiftMax = 250 nr = rsmooth dr = 2.0 * strainMax1 / (nr - 1) fr = -strainMax1 sr = Sampling(nr, dr, fr) dw = DynamicWarping(shiftMin, shiftMax) dw.setErrorExtrapolation(DynamicWarping.ErrorExtrapolation.REFLECT) dw.setStrainMax(strainMax1) dw.setShiftSmoothing(usmooth, usmooth) e1 = dw.computeErrors1(f, g) d1 = dw.accumulateForward(e1) u1 = dw.backtrackReverse(d1, e1) nl = len(e1[0]) def plotShifts(): nl = len(e1[0]) sp = SimplePlot() sp.setSize(1400, 500) sl = Sampling(nl, s1f.delta, shiftMin * s1f.delta) pv = sp.addPixels(s1f, sl, pow(transpose(e1), 1.0)) pv.setInterpolation(PixelsView.Interpolation.NEAREST) pv.setColorModel(ColorMap.JET) pv.setPercentiles(2, 98) pv = sp.addPoints(s1f, mul(s1f.delta, u1)) plotShifts() #u1 = dw.smoothShifts(sr,u1) #u1 = dw.smoothShifts(u1) n1, n2 = len(f[0]), len(f) e1 = dw.computeErrorsRaw(f[n2 / 2], g[n2 / 2]) dw.findShiftsSmooth(dstrainMax1, u1[0], e1, u1) plotShifts() #u1 = dw.findShifts1(f,g) n1, n2 = len(f[0]), len(f) h = zerofloat(n1, n2) u = zerofloat(n1, n2) for i2 in range(n2): copy(u1, u[i2]) dw.applyShifts(u1, g[i2], h[i2]) print "warp1: u min =", min(u), " max =", max(u) return u, h