diff 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
line wrap: on
line diff
--- a/dataset.py	Tue May 06 20:01:34 2008 -0400
+++ b/dataset.py	Tue May 06 22:24:55 2008 -0400
@@ -9,7 +9,22 @@
 class AbstractFunction (Exception): """Derived class must override this function"""
 class NotImplementedYet (NotImplementedError): """Work in progress, this should eventually be implemented"""
 
-class DataSet(object):
+class AttributesHolder(object):
+    def __init__(self): pass
+
+    def attributeNames(self):
+        raise AbstractFunction()
+
+    def setAttributes(self,attribute_names,attribute_values,make_copies=False):
+        if make_copies:
+            for name,value in zip(attribute_names,attribute_values):
+                self.__setattr__(name,copy.deepcopy(value))
+        else:
+            for name,value in zip(attribute_names,attribute_values):
+                self.__setattr__(name,value)
+    
+    
+class DataSet(AttributesHolder):
     """A virtual base class for datasets.
 
     A DataSet can be seen as a generalization of a matrix, meant to be used in conjunction
@@ -149,10 +164,6 @@
 
     def attributeNames(self): return self._attribute_names
 
-    def setAttributes(self,attribute_names,attribute_values):
-        for name,value in zip(attribute_names,attribute_values):
-            self.__setattr__(name,value)
-    
     class MinibatchToSingleExampleIterator(object):
         """
         Converts the result of minibatch iterator with minibatch_size==1 into