def _predict_values_sparse(self, x, n): if is_classification_problem(self.svm_type): kvalue = N.empty((len(self.support_vectors),)) for i, sv in enumerate(self.support_vectors): kvalue[i] = svm_node_dot(x, sv, self.kernel) p = 0 dec_values = N.empty((n,)) for i in range(self.nr_class): for j in range(i + 1, self.nr_class): sum = 0 si, sj = self.start[i], self.start[j] ci, cj = self.nSV[i], self.nSV[j] coef1 = self.sv_coef[j - 1] coef2 = self.sv_coef[i] sum = 0. for k in range(ci): sum += coef1[si + k] * kvalue[si + k] for k in range(cj): sum += coef2[sj + k] * kvalue[sj + k] dec_values[p] = sum - self.rho[p] p += 1 return dec_values else: z = -self.rho for sv_coef, sv in izip(self.sv_coef, self.support_vectors): z += sv_coef * svm_node_dot(x, sv, self.kernel) return z
def _predict_values_sparse(self, x, n): if is_classification_problem(self.svm_type): kvalue = N.empty((len(self.support_vectors),)) for i, sv in enumerate(self.support_vectors): kvalue[i] = svm_node_dot(x, sv, self.kernel) p = 0 dec_values = N.empty((n,)) for i in range(self.nr_class): for j in range(i + 1, self.nr_class): sum = 0 si, sj = self.start[i], self.start[j] ci, cj = self.nSV[i], self.nSV[j] coef1 = self.sv_coef[j - 1] coef2 = self.sv_coef[i] sum = 0. for k in range(ci): sum += coef1[si + k] * kvalue[si + k] for k in range(cj): sum += coef2[sj + k] * kvalue[sj + k] dec_values[p] = sum - self.rho[p] p += 1 return dec_values else: z = -self.rho for sv_coef, sv in izip(self.sv_coef, self.support_vectors): z += sv_coef * svm_node_dot(x, sv, self.kernel) return z
def _predict_values_compact(self, x, n): if is_classification_problem(self.svm_type): for i, (sv, kernel) in \ enumerate(izip(self.support_vectors, self.kernels)): kvalue = N.empty((len(self.support_vectors),)) kvalue[i] = svm_node_dot(x, sv, kernel) kvalue -= self.rho return kvalue else: sv = self.support_vectors[0] kernel = self.kernels[0] kvalue = svm_node_dot(x, sv, kernel) - self.rho return kvalue
def _predict_values_compact(self, x, n): if is_classification_problem(self.svm_type): for i, (sv, kernel) in \ enumerate(izip(self.support_vectors, self.kernels)): kvalue = N.empty((len(self.support_vectors),)) kvalue[i] = svm_node_dot(x, sv, kernel) kvalue -= self.rho return kvalue else: sv = self.support_vectors[0] kernel = self.kernels[0] kvalue = svm_node_dot(x, sv, kernel) - self.rho return kvalue
def _create_gramvec(self, x): gramvec = N.zeros((len(self.dataset)+1,), dtype=libsvm.svm_node_dtype) for sv_id in self.sv_ids: sv = self.dataset[sv_id] gramvec[sv_id]['value'] = svm_node_dot(x, sv, self.kernel) return gramvec
def _create_gramvec(self, x): gramvec = N.zeros((len(self.dataset)+1,), dtype=libsvm.svm_node_dtype) for sv_id in self.sv_ids: sv = self.dataset[sv_id] gramvec[sv_id]['value'] = svm_node_dot(x, sv, self.kernel) return gramvec