예제 #1
0
def bspline_clean_fast(data, smoothness, zscore):
    """Clean a data series using B-spline smoothing."""
    
    #define the degree
    degree = 3
    
    #create knot vector
    knots = sp.get_uniform_knots_from_points(
		    data, degree, knotrange=(0, len(data) - 1))
	
    #determine datasize
    n_data = len(data)
    n_knot = len(knots)
    
    #create a pointer to the dataset
    ds = np.array(data)
    ds_type = c_double*n_data
    ds_ptr = ds_type(*ds)
    
    #create a pointer to the knot
    kn = np.array(knots)
    kn_type = c_double*n_knot
    kn_ptr = kn_type(*kn)
    
    smoother = BsplineFastSmoother(ds_ptr, n_data, kn_ptr, n_knot, degree, c_double(smoothness), c_double(zscore))
    smoothed = smoother.bsm_cleanData()
    
    #convert the pointer to nparray
    ArrayType = ctypes.c_double*n_data
    array_ptr = ctypes.cast(smoothed, ctypes.POINTER(ArrayType))
    cleaned = data.copy()
    cleaned[:] = np.frombuffer(array_ptr.contents, dtype=np.double)
    
    return cleaned
    def __init__(self, data, smoothness, zscore):
        #create knot vector
        knots = sp.get_uniform_knots_from_points(data,
                                                 degree,
                                                 knotrange=(0, len(data) - 1))

        #determine datasize
        n_data = len(data)
        n_knot = len(knots)

        #create a pointer to the dataset
        ds = np.array(data)
        ds_type = c_double * n_data
        ds_array = ds_type(*ds)

        #create a pointer to the knots
        kn = np.array(knots)
        kn_type = c_double * n_knot
        kn_array = kn_type(*kn)

        #number of threads

        self._lib = cdll.LoadLibrary('lib_mkl/libspclean.so')
        self.obj = self._lib.Smoother_new(ds_array, n_data, kn_array, n_knot,
                                          degree, c_double(smoothness),
                                          c_double(zscore))
예제 #3
0
 def set_knots(self, knots=None, num_knots=None):
     """Set or reset knots. If both 'knots' and 'num_knots' are None,
     there will be one knot for each data point, with the necessary
     multiplicity at the ends for the curve to start and end at the first
     and last data point, respectively."""
     if knots is not None and num_knots is not None:
         raise RuntimeError("Either knots or num_knots may " \
                            "be specified, but not both.")
     if knots is not None:
         self._knots = knots
     elif num_knots is not None:
         self._knots = sp.get_uniform_knots(num_knots, self._degree,
             knotrange=(0, len(self._dataset)))
     else:
         self._knots = sp.get_uniform_knots_from_points(
             self._dataset, self._degree,
             knotrange=(0, len(self._dataset) - 1))
    def __init__(self, data, smoothness, zscore):
    	#create knot vector
    	knots = sp.get_uniform_knots_from_points(data, degree, knotrange=(0, len(data) - 1))

    	#determine datasize
    	n_data = len(data)
    	n_knot = len(knots)

    	#create a pointer to the dataset
    	ds = np.array(data)
    	ds_type = c_double*n_data
    	ds_array = ds_type(*ds)

    	#create a pointer to the knots
    	kn = np.array(knots)
    	kn_type = c_double*n_knot
    	kn_array = kn_type(*kn)
    
    	#number of threads
    	
    	self._lib = cdll.LoadLibrary('lib_mkl/libspclean.so')
        self.obj = self._lib.Smoother_new(ds_array, n_data, kn_array, n_knot, degree, c_double(smoothness), c_double(zscore))