def segment_signal(signal, numScales, deltaTau=None, kMin=None, linkType=None): if deltaTau is None: deltaTau = DELTA_TAU if kMin is None: kMin = pow((1 - exp(-2 * deltaTau)), -0.5) signal = asarray(signal).flatten() signalLength, maxDiff, numLeadingZeros, numTrailingZeros = _signal_properties( signal) # Calculate scale sigma's scaleSigmaArray = exp(arange(0, numScales) * deltaTau) # Setup initial node set nodeIds = nonzero(diff(signal, axis=0))[0] + 1 if nodeIds[-1] != signalLength: nodeIds = append(nodeIds, signalLength) # Loop! baseSignal = asarray(signal, dtype=np_double) prevScaleSignal, prevSegmentEnds = baseSignal, nodeIds nodeMapping, segmentEnds = {}, {0: nodeIds} for scaleIndex in range(1, numScales): scaleSignal = convolve(baseSignal, scaleSigmaArray[scaleIndex]) d, dcp, r = _search_volume(scaleSigmaArray, scaleIndex, kMin) parents, scaleSegmentEnds = link(nodeIds, d, dcp, r, prevScaleSignal, scaleSignal, signalLength, \ maxDiff, prevSegmentEnds, numLeadingZeros, numTrailingZeros, linkType=linkType) nodeMapping[scaleIndex] = zip(nodeIds, parents) segmentEnds[scaleIndex] = scaleSegmentEnds prevScaleSignal, prevSegmentEnds, nodeIds = scaleSignal, scaleSegmentEnds, unique( parents) return nodeMapping, segmentEnds
def segment_signal(signal, numScales, deltaTau=None, kMin=None, linkType=None): if deltaTau is None: deltaTau = DELTA_TAU if kMin is None: kMin = pow((1 - exp(-2 * deltaTau)), -0.5) signal = asarray(signal).flatten() signalLength, maxDiff, numLeadingZeros, numTrailingZeros = _signal_properties(signal) # Calculate scale sigma's scaleSigmaArray = exp(arange(0, numScales) * deltaTau) # Setup initial node set nodeIds = nonzero(diff(signal, axis=0))[0] + 1 if nodeIds[-1] != signalLength: nodeIds = append(nodeIds, signalLength) # Loop! baseSignal = asarray(signal, dtype=np_double) prevScaleSignal, prevSegmentEnds = baseSignal, nodeIds nodeMapping, segmentEnds = {}, { 0: nodeIds } for scaleIndex in range(1, numScales): scaleSignal = convolve(baseSignal, scaleSigmaArray[scaleIndex]) d, dcp, r = _search_volume(scaleSigmaArray, scaleIndex, kMin) parents, scaleSegmentEnds = link(nodeIds, d, dcp, r, prevScaleSignal, scaleSignal, signalLength, \ maxDiff, prevSegmentEnds, numLeadingZeros, numTrailingZeros, linkType=linkType) nodeMapping[scaleIndex] = zip(nodeIds, parents) segmentEnds[scaleIndex] = scaleSegmentEnds prevScaleSignal, prevSegmentEnds, nodeIds = scaleSignal, scaleSegmentEnds, unique(parents) return nodeMapping, segmentEnds
def segment_signal(signal, numScales, deltaTau=None, kMin=None, linkType=None, doNodeMapping=False, minNodeInterval=None): assert type(signal) == list or (type(signal) == ndarray and signal.ndim == 1) if deltaTau is None: deltaTau = DELTA_TAU if kMin is None: kMin = pow((1 - exp(-2 * deltaTau)), -0.5) if type(signal) == list: signal = asarray(signal).flatten() signalLength, maxDiff, numLeadingZeros, numTrailingZeros = _signal_properties(signal) # Calculate scale sigma's scaleSigmaArray = exp(arange(0, numScales) * deltaTau) # Setup initial node set nodeIds = _initial_node_set(signal, signalLength, minNodeInterval) # Setup initial loop vars segmentEnds = { 0: nodeIds } if doNodeMapping: nodeMapping = {} # Loop! baseSignal = asarray(signal, dtype=np_double) prevScaleSignal, prevSegmentEnds = baseSignal, nodeIds for scaleIndex in range(1, numScales): scaleSignal = convolve(baseSignal, scaleSigmaArray[scaleIndex]) d, dcp, r = _search_volume(scaleSigmaArray, scaleIndex, kMin) parents, scaleSegmentEnds = link(nodeIds, d, dcp, r, prevScaleSignal, scaleSignal, signalLength, \ maxDiff, prevSegmentEnds, numLeadingZeros, numTrailingZeros, linkType=linkType) if doNodeMapping: nodeMapping[scaleIndex] = zip(nodeIds, parents) segmentEnds[scaleIndex] = scaleSegmentEnds prevScaleSignal, prevSegmentEnds, nodeIds = scaleSignal, scaleSegmentEnds, unique(parents) return (segmentEnds, nodeMapping) if doNodeMapping else segmentEnds