Changeset 8769:180322d40dab in orange


Ignore:
Timestamp:
08/24/11 22:39:33 (3 years ago)
Author:
matejd <matejd@…>
Branch:
default
Convert:
31293cb50935734cf29ef13c7e108c02e54bba20
Message:

Enabled PCA and SPCA for sphereviz and linproj3d

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/projection/linear.py

    r8765 r8769  
    326326        if not attr_indices: return 
    327327 
    328         if self.implementation == FAST_IMPLEMENTATION and not hasattr(self, '_use_3d'): # TODO 
     328        if self.implementation == FAST_IMPLEMENTATION and not hasattr(self, '_use_3D'): # TODO 
    329329            return self.optimize_fast_separation(steps, single_step, distances) 
    330330 
     
    984984                class_array = numpy.compress(indices, class_array) 
    985985 
     986        ncomps = 3 if hasattr(self, '_use_3D') else 2 
    986987        vectors = None 
    987988        if method == DR_PCA: 
    988             vals, vectors = create_pca_projection(data_matrix, ncomps = 2, 
     989            vals, vectors = create_pca_projection(data_matrix, ncomps = ncomps, 
    989990                                                  use_generalized_eigenvectors = self.use_generalized_eigenvectors) 
    990991        elif method == DR_SPCA and self.graph.dataHasClass: 
    991992            vals, vectors = create_pca_projection(data_matrix, class_array, 
    992                                                   ncomps = 2, 
     993                                                  ncomps = ncomps, 
    993994                                                  use_generalized_eigenvectors = self.use_generalized_eigenvectors) 
    994995        elif method == DR_PLS and self.graph.dataHasClass: 
    995996            data_matrix = data_matrix.transpose() 
    996997            class_matrix = numpy.transpose(numpy.matrix(class_array)) 
    997             vectors = create_pls_projection(data_matrix, class_matrix, 2) 
     998            vectors = create_pls_projection(data_matrix, class_matrix, ncomps) 
    998999            vectors = vectors.T 
    9991000 
     
    10061007        xanchors = vectors[0] 
    10071008        yanchors = vectors[1] 
    1008  
    1009         m = math.sqrt(max(xanchors**2 + yanchors**2)) 
     1009         
     1010        if ncomps == 3: 
     1011            zanchors = vectors[2] 
     1012            m = math.sqrt(max(xanchors**2 + yanchors**2 + zanchors**2)) 
     1013            zanchors /= m 
     1014        else: 
     1015            m = math.sqrt(max(xanchors**2 + yanchors**2)) 
    10101016 
    10111017        xanchors /= m 
     
    10151021 
    10161022        if set_anchors: 
    1017             self.graph.setAnchors(list(xanchors), list(yanchors), attributes) 
     1023            if ncomps == 3: 
     1024                self.graph.setAnchors(list(xanchors), list(yanchors), list(zanchors), attributes) 
     1025            else: 
     1026                self.graph.setAnchors(list(xanchors), list(yanchors), attributes) 
    10181027            self.graph.updateData() 
    10191028            self.graph.repaint() 
    1020         return xanchors, yanchors, (attributes, attr_indices) 
     1029 
     1030        if ncomps == 3: 
     1031            return xanchors, yanchors, zanchors, (attributes, attr_indices) 
     1032        else: 
     1033            return xanchors, yanchors, (attributes, attr_indices) 
    10211034 
    10221035    findProjection = find_projection 
Note: See TracChangeset for help on using the changeset viewer.