comparison dataset.py @ 319:6441e568745e

bug fixed when one matrix is an array, a 1-d matrix
author Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
date Wed, 11 Jun 2008 17:05:56 -0400
parents e2eab74b6a28
children b1da46b9b901
comparison
equal deleted inserted replaced
318:e2eab74b6a28 319:6441e568745e
1057 Every tensor is treated as a numpy matrix (using numpy.asmatrix) 1057 Every tensor is treated as a numpy matrix (using numpy.asmatrix)
1058 """ 1058 """
1059 ArrayFieldsDataSet.__init__(self,**kwargs) 1059 ArrayFieldsDataSet.__init__(self,**kwargs)
1060 assert len(data_arrays) == len(fieldnames) 1060 assert len(data_arrays) == len(fieldnames)
1061 assert len(fieldnames) > 0 1061 assert len(fieldnames) > 0
1062 num_examples = numpy.asmatrix(data_arrays[0]).shape[0] 1062 all_matrix_sizes = map(lambda x : numpy.asmatrix(x).shape[0] , data_arrays)
1063 for k in range(len(data_arrays)) : 1063 num_examples = max(all_matrix_sizes)
1064 assert numpy.asmatrix(data_arrays[k]).shape[0] == num_examples
1065 self._fieldnames = fieldnames 1064 self._fieldnames = fieldnames
1066 self._datas = [] 1065 self._datas = []
1067 for k in range(len(data_arrays)) : 1066 for k in range(len(data_arrays)) :
1068 self._datas.append( numpy.asmatrix(data_arrays[k]) ) 1067 self._datas.append( numpy.asmatrix(data_arrays[k]) )
1069 #raise NotImplemented 1068 if self._datas[-1].shape[0] == 1 and self._datas[-1].shape[1] == num_examples :
1069 self._datas[-1] = self._datas[-1].transpose()
1070 for k in range(len(self._datas)) :
1071 assert self._datas[k].shape[0] == num_examples
1070 1072
1071 1073
1072 def __len__(self) : 1074 def __len__(self) :
1073 """ 1075 """
1074 Length of the dataset is based on the first array = data_arrays[0], using its shape 1076 Length of the dataset is based on the first array = data_arrays[0], using its shape