Changeset 10490:a1479e654132 in orange
 Timestamp:
 03/09/12 19:15:25 (2 years ago)
 Branch:
 default
 rebase_source:
 8af0ee6af6a8195dcd8111f3191759577f65a6aa
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/projection/linear.py
r10480 r10490 1340 1340 """ 1341 1341 1342 def __new__(cls, dataset =None, **kwds):1342 def __new__(cls, dataset=None, **kwds): 1343 1343 optimizer = object.__new__(cls) 1344 1344 optimizer.__init__(**kwds) … … 1349 1349 return optimizer 1350 1350 1351 def __init__(self, standardize = True, 1352 max_components = 0, variance_covered = 1, 1353 use_generalized_eigenvectors = 0): 1351 def __init__(self, standardize=True, max_components=0, variance_covered=1, 1352 use_generalized_eigenvectors=0): 1354 1353 self.standardize = standardize 1355 1354 self.max_components = max_components 1356 self.variance_covered = variance_covered if variance_covered < 1. else 11355 self.variance_covered = min(1, variance_covered) 1357 1356 self.use_generalized_eigenvectors = use_generalized_eigenvectors 1358 1357 … … 1362 1361 C = numpy.ma.dot(Xg.T, Xd.T) 1363 1362 V, D, T = numpy.linalg.svd(C) 1364 U = numpy.ma.dot(V.T, Xd) / numpy.sqrt(D.reshape(1, 1))1363 U = numpy.ma.dot(V.T, Xd) / numpy.sqrt(D.reshape(1, 1)) 1365 1364 else: 1366 1365 C = numpy.ma.dot(Xg, Xd) … … 1389 1388 stdev = numpy.std(Xd, axis=0) 1390 1389 relevant_features = stdev != 0 1390 Xd = Xd[:, relevant_features] 1391 1391 if self.standardize: 1392 stdev[stdev == 0] = 1. 1393 Xd /= stdev 1394 Xd = Xd[:,relevant_features] 1392 Xd /= stdev[relevant_features] 1395 1393 1396 1394 #use generalized eigenvectors … … 1402 1400 1403 1401 #actual pca 1404 n, m = Xd.shape1402 n, m = Xd.shape 1405 1403 U, D = self._pca(dataset, Xd, Xg) 1406 1404 … … 1408 1406 n, m = U.shape 1409 1407 if m != M: 1410 U_ = numpy.zeros((n, M))1411 U_[:, relevant_features] = U1408 U_ = numpy.zeros((n, M)) 1409 U_[:, relevant_features] = U 1412 1410 U = U_ 1413 1411 … … 1416 1414 #select eigen vectors 1417 1415 if self.variance_covered != 1: 1418 nfeatures = numpy.nonzero(numpy.cumsum(D) / sum(D) >= self.variance_covered)[0][0] + 1 1416 nfeatures = numpy.searchsorted(numpy.cumsum(D) / variance_sum, 1417 self.variance_covered) + 1 1419 1418 U = U[:nfeatures, :] 1420 1419 D = D[:nfeatures] … … 1426 1425 n, m = U.shape 1427 1426 pc_domain = Orange.data.Domain([Orange.feature.Continuous("Comp.%d"% 1428 (i+1)) for i in range(n)], False)1429 1430 return PcaProjector(input_domain =dataset.domain,1427 (i + 1)) for i in range(n)], False) 1428 1429 return PcaProjector(input_domain=dataset.domain, 1431 1430 output_domain = pc_domain, 1432 1431 pc_domain = pc_domain, … … 1444 1443 # define the Laplacian matrix 1445 1444 c = dataset.to_numpy("c")[0] 1446 l = numpy.array(numpy.hstack( 1445 l = numpy.array(numpy.hstack([(c != v) for v in c]), dtype='f') 1447 1446 l = numpy.diagflat(numpy.sum(l, axis=0)) 1448 1447
Note: See TracChangeset
for help on using the changeset viewer.