Esempio n. 1
0
def _daal_dbscan(X, eps=0.5, min_samples=5, sample_weight=None):
    if not eps > 0.0:
        raise ValueError("eps must be positive.")

    X = check_array(X, dtype=[np.float64, np.float32])
    if sample_weight is not None:
        sample_weight = np.asarray(sample_weight)
        check_consistent_length(X, sample_weight)
        ww = make2d(sample_weight)
    else:
        ww = None

    XX = make2d(X)

    fpt = getFPType(XX)
    alg = daal4py.dbscan(method='defaultDense',
                         epsilon=float(eps),
                         minObservations=int(min_samples),
                         resultsToCompute="computeCoreIndices")

    daal_res = alg.compute(XX, ww)
    n_clusters = daal_res.nClusters[0, 0]
    assignments = daal_res.assignments.ravel()
    if daal_res.coreIndices is not None:
        core_ind = daal_res.coreIndices.ravel()
    else:
        core_ind = np.array([], dtype=np.intc)

    return (core_ind, assignments)
Esempio n. 2
0
 def __init__(self, X, y, beta, hess=False, fit_intercept=True):
     self.compute_hess = hess
     self.n = X.shape[0]
     self.fptype = getFPType(X)
     self.fit_intercept = fit_intercept
     self.X = make2d(X)
     self.y = make2d(y)
    def __init__(self, X, y, beta, hess=False, fit_intercept=True):
        self.compute_hess = hess
        self.n = X.shape[0]
        self.fptype = getFPType(X)
        self.fit_intercept = fit_intercept
        self.X = make2d(X)
        self.y = make2d(y)

        self.last_beta = beta.copy()

        self.func = None
        self.grad = None
        self.hess = None
    def compute(self, beta):
        # Don't compute if we have already cached func, grad, hess
        if self.func is not None and np.array_equal(beta, self.last_beta):
            return

        result = self.algo.compute(self.X, self.y, make2d(beta))
        np.copyto(self.last_beta, beta)
        self.func = result.valueIdx[0, 0] * self.n
        self.grad = result.gradientIdx.ravel() * self.n
        if self.compute_hess:
            self.hess = result.hessianIdx * self.n
Esempio n. 5
0
 def compute(self, beta):
     result = self.algo.compute(self.X, self.y, make2d(beta))
     self.func = result.valueIdx[0, 0] * self.n
     self.grad = result.gradientIdx.ravel() * self.n
     if self.compute_hess:
         self.hess = result.hessianIdx * self.n