comparison dataset.py @ 110:8fa1ef2411a0

Worked on OneShotTLearner and implementation of LinearRegression
author bengioy@bengiomac.local
date Tue, 06 May 2008 22:24:55 -0400
parents 8c0a1b11b007
children 8b520423d4ee
comparison
equal deleted inserted replaced
109:d97f6fe6bdf9 110:8fa1ef2411a0
7 import numpy 7 import numpy
8 8
9 class AbstractFunction (Exception): """Derived class must override this function""" 9 class AbstractFunction (Exception): """Derived class must override this function"""
10 class NotImplementedYet (NotImplementedError): """Work in progress, this should eventually be implemented""" 10 class NotImplementedYet (NotImplementedError): """Work in progress, this should eventually be implemented"""
11 11
12 class DataSet(object): 12 class AttributesHolder(object):
13 def __init__(self): pass
14
15 def attributeNames(self):
16 raise AbstractFunction()
17
18 def setAttributes(self,attribute_names,attribute_values,make_copies=False):
19 if make_copies:
20 for name,value in zip(attribute_names,attribute_values):
21 self.__setattr__(name,copy.deepcopy(value))
22 else:
23 for name,value in zip(attribute_names,attribute_values):
24 self.__setattr__(name,value)
25
26
27 class DataSet(AttributesHolder):
13 """A virtual base class for datasets. 28 """A virtual base class for datasets.
14 29
15 A DataSet can be seen as a generalization of a matrix, meant to be used in conjunction 30 A DataSet can be seen as a generalization of a matrix, meant to be used in conjunction
16 with learning algorithms (for training and testing them): rows/records are called examples, and 31 with learning algorithms (for training and testing them): rows/records are called examples, and
17 columns/attributes are called fields. The field value for a particular example can be an arbitrary 32 columns/attributes are called fields. The field value for a particular example can be an arbitrary
147 if fieldtypes: 162 if fieldtypes:
148 self._attribute_names.append("fieldtypes") 163 self._attribute_names.append("fieldtypes")
149 164
150 def attributeNames(self): return self._attribute_names 165 def attributeNames(self): return self._attribute_names
151 166
152 def setAttributes(self,attribute_names,attribute_values):
153 for name,value in zip(attribute_names,attribute_values):
154 self.__setattr__(name,value)
155
156 class MinibatchToSingleExampleIterator(object): 167 class MinibatchToSingleExampleIterator(object):
157 """ 168 """
158 Converts the result of minibatch iterator with minibatch_size==1 into 169 Converts the result of minibatch iterator with minibatch_size==1 into
159 single-example values in the result. Therefore the result of 170 single-example values in the result. Therefore the result of
160 iterating on the dataset itself gives a sequence of single examples 171 iterating on the dataset itself gives a sequence of single examples