Changeset 8545:e0b2560fc071 in orange
 Timestamp:
 07/31/11 00:33:11 (3 years ago)
 Branch:
 default
 Convert:
 7c2ff522009b764f5df671d8d61f322948765352
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/Orange/preprocess/scaling.py
r8539 r8545 539 539 @deprecated_keywords({"xAnchors": "xanchors", "yAnchors": "yanchors"}) 540 540 def set_anchors(self, xanchors, yanchors, attributes): 541 print('set anchors') 541 542 if attributes: 542 543 if xanchors != None and yanchors != None: … … 554 555 555 556 """ 557 print('create anchors') 556 558 xanchors = self.create_xanchors(num_of_attr) 557 559 yanchors = self.create_yanchors(num_of_attr) … … 693 695 "settingsDict": "settings_dict"}) 694 696 def create_projection_as_numeric_array(self, attr_indices, **settings_dict): 697 print('create projection as numeric array') 695 698 # load the elements from the settings dict 696 699 validData = settings_dict.get("validData") … … 795 798 createProjectionAsNumericArray = create_projection_as_numeric_array 796 799 800 @deprecated_keywords({"attrIndices": "attr_indices", 801 "settingsDict": "settings_dict"}) 802 def create_projection_as_numeric_array_3D(self, attr_indices, **settings_dict): 803 print('create projection as numeric array') 804 # load the elements from the settings dict 805 validData = settings_dict.get("validData") 806 classList = settings_dict.get("classList") 807 sum_i = settings_dict.get("sum_i") 808 XAnchors = settings_dict.get("XAnchors") 809 YAnchors = settings_dict.get("YAnchors") 810 ZAnchors = settings_dict.get("ZAnchors") 811 scaleFactor = settings_dict.get("scaleFactor", 1.0) 812 normalize = settings_dict.get("normalize") 813 jitterSize = settings_dict.get("jitterSize", 0.0) 814 useAnchorData = settings_dict.get("useAnchorData", 0) 815 removeMissingData = settings_dict.get("removeMissingData", 1) 816 useSubsetData = settings_dict.get("useSubsetData", 0) # use the data or subsetData? 817 #minmaxVals = settings_dict.get("minmaxVals", None) 818 819 # if we want to use anchor data we can get attr_indices from the anchor_data 820 if useAnchorData and self.anchor_data: 821 attr_indices = [self.attribute_name_index[val[3]] for val in self.anchor_data] 822 823 if validData == None: 824 if useSubsetData: validData = self.get_valid_subset_list(attr_indices) 825 else: validData = self.get_valid_list(attr_indices) 826 if sum(validData) == 0: 827 return None 828 829 if classList == None and self.data_domain.class_var: 830 if useSubsetData: classList = self.original_subset_data[self.data_class_index] 831 else: classList = self.original_data[self.data_class_index] 832 833 # if jitterSize is set below zero we use scaled_data that has already jittered data 834 if useSubsetData: 835 if jitterSize < 0.0: data = self.scaled_subset_data 836 else: data = self.no_jittering_scaled_subset_data 837 else: 838 if jitterSize < 0.0: data = self.scaled_data 839 else: data = self.no_jittering_scaled_data 840 841 selectedData = numpy.take(data, attr_indices, axis = 0) 842 if removeMissingData: 843 selectedData = numpy.compress(validData, selectedData, axis = 1) 844 if classList != None and len(classList) != numpy.shape(selectedData)[1]: 845 classList = numpy.compress(validData, classList) 846 847 if useAnchorData and self.anchor_data: 848 XAnchors = numpy.array([val[0] for val in self.anchor_data]) 849 YAnchors = numpy.array([val[1] for val in self.anchor_data]) 850 ZAnchors = numpy.array([val[2] for val in self.anchor_data]) 851 r = numpy.sqrt(XAnchors*XAnchors + YAnchors*YAnchors + ZAnchors*ZAnchors) # compute the distance of each anchor from the center of the circle 852 if normalize == 1 or (normalize == None and self.normalize_examples): 853 XAnchors *= r 854 YAnchors *= r 855 ZAnchors *= r 856 elif (XAnchors != None and YAnchors != None and ZAnchors != None): 857 XAnchors = numpy.array(XAnchors); 858 YAnchors = numpy.array(YAnchors) 859 ZAnchors = numpy.array(ZAnchors) 860 r = numpy.sqrt(XAnchors*XAnchors + YAnchors*YAnchors + ZAnchors*ZAnchors) # compute the distance of each anchor from the center of the circle 861 else: 862 # Golden Section Spiral algorithm approximates even distribution of points on a sphere 863 # (read more here http://www.softimageblog.com/archives/115) 864 n = len(attr_indices) 865 XAnchors = [] 866 YAnchors = [] 867 ZAnchors = [] 868 869 inc = math.pi * (3  math.sqrt(5)) 870 off = 2. / n 871 for k in range(n): 872 y = k * off  1 + (off / 2) 873 r = math.sqrt(1  y*y) 874 phi = k * inc 875 XAnchors.append(math.cos(phi)*r) 876 YAnchors.append(y) 877 ZAnchors.append(math.sin(phi)*r) 878 r = numpy.ones(len(XAnchors), numpy.float) 879 880 x_positions = numpy.dot(XAnchors, selectedData) 881 y_positions = numpy.dot(YAnchors, selectedData) 882 z_positions = numpy.dot(ZAnchors, selectedData) 883 884 if normalize == 1 or (normalize == None and self.normalize_examples): 885 if sum_i == None: 886 sum_i = self._getSum_i(selectedData, useAnchorData, r) 887 x_positions /= sum_i 888 y_positions /= sum_i 889 z_positions /= sum_i 890 self.trueScaleFactor = scaleFactor 891 else: 892 if not removeMissingData: 893 try: 894 x_validData = numpy.compress(validData, x_positions) 895 y_validData = numpy.compress(validData, y_positions) 896 z_validData = numpy.compress(validData, z_positions) 897 except: 898 print validData 899 print x_positions 900 print numpy.shape(validData) 901 print numpy.shape(x_positions) 902 else: 903 x_validData = x_positions 904 y_validData = y_positions 905 906 dist = math.sqrt(max(x_validData*x_validData + y_validData*y_validData + z_validData*z_validData)) or 1 907 self.trueScaleFactor = scaleFactor / dist 908 909 self.unscaled_x_positions = numpy.array(x_positions) 910 self.unscaled_y_positions = numpy.array(y_positions) 911 self.unscaled_z_positions = numpy.array(z_positions) 912 913 if self.trueScaleFactor != 1.0: 914 x_positions *= self.trueScaleFactor 915 y_positions *= self.trueScaleFactor 916 z_positions *= self.trueScaleFactor 917 918 if jitterSize > 0.0: 919 x_positions += numpy.random.uniform(jitterSize, jitterSize, len(x_positions)) 920 y_positions += numpy.random.uniform(jitterSize, jitterSize, len(y_positions)) 921 z_positions += numpy.random.uniform(jitterSize, jitterSize, len(z_positions)) 922 923 self.last_attr_indices = attr_indices 924 if classList != None: 925 return numpy.transpose(numpy.array((x_positions, y_positions, z_positions, classList))) 926 else: 927 return numpy.transpose(numpy.array((x_positions, y_positions, z_positions))) 928 929 createProjectionAsNumericArray3D = create_projection_as_numeric_array_3D 930 797 931 @deprecated_keywords({"useAnchorData": "use_anchor_data", 798 932 "anchorRadius": "anchor_radius"}) … … 823 957 "create_projection_as_example_table": "create_projection_as_example_table", 824 958 "create_projection_as_numeric_array": "create_projection_as_numeric_array", 959 "create_projection_as_numeric_array_3D": "create_projection_as_numeric_array_3D", 825 960 "_getSum_i": "_getsum_i", 826 961 "normalizeExamples": "normalize_examples",
Note: See TracChangeset
for help on using the changeset viewer.