Janto Dreijer avatar Janto Dreijer committed 7765ee2

Comments (0)

Files changed (13)

 __all__.append("FeaturesBayesianClassifier")
 class FeaturesBayesianClassifier(Classifier):
 	def __init__(self, train_on_testdata=False, feature_extractor=FeatureExtractor(), mutations_to_train_on=10, pdf_type=probalistic_discrete_estimate, symbol_definitions=None): #XXX magic number
+		self.logger = logging.getLogger("FeaturesBayesianClassifier(%s, %s)" % (typename(feature_extractor), pdf_type.__name__))
 		if symbol_definitions is None:
 			symbol_definitions = SymbolDefinitions()
 		self.bayesian = Bayesian(pdf_type=pdf_type)
 		self.feature_extractor = feature_extractor
 		# load initial training data
+		self.logger.info("generating training data")
 		for component, filename in tools.component_files().items():
 			# train def
 			self.bayesian.add_training_data(component, feature_extractor.features_from_xml(filename))
 			for component, filenames in tools.test_files().items():
 				for filename in filenames:
 					self.bayesian.add_training_data(component, feature_extractor.features_from_xml(filename))
+		self.logger.info("training classifier")
 		self.bayesian.train()
 
 	def classify(self, primitives):
 
 	def to_eps(self, filename):
 		import vplot
-		eps = vplot.eps_class(fname=filename, bbx=512,bby=512)
+		eps = vplot.eps_class(fname=filename, bbx=1024,bby=1024)
 		eps.color('black')
 		for component in self.components():
 			component.to_eps(eps, self)
 	circuit.add_component(resistor, {1:con})
 	print circuit.spice()
 	circuit.redraw(frame=None)
-	#~ circuit.to_eps(filename="test.eps")
+	circuit.to_eps(filename="test.eps")
 	T = points_transformation(theta=pi/4, midpoint=Point(0,1))
 	points = [Point(n,1) for n in range(30)]
 	print [abs(Point(x,y)) for x,y in T(points)]
 import os, os.path
 
 from linetools import *
+from itertools import count
 
 reports_directory = "reports"
 
-from itertools import count
-
 def fixme_log(directory="."):
 	bugs = 0
 	line_count = 0
 from event_recorders import *
 from linetools import Point, primitives_to_xml, Symbol
 from tools import *
+import os.path
 
 import cPickle
 
 					self.pen_recorder.primitives = []
 				else:
 					# add primitive
-					if Sketching.current_primitives:
-						self.pen_recorder.primitives.extend(Sketching.current_primitives)
+					current_primitives = self.pen_recorder.suggested_primitives()
+					if current_primitives:
+						self.pen_recorder.primitives.extend(current_primitives)
 				for primitive in Sketching.current_primitives:
 					self.Canvas.remove(primitive)
 				Sketching.current_primitives = []
 		self._pnl.AddFoldPanelWindow(item, chooser)
 		## capture button
 		def save_data(directory, item_name, author):
-			root, dirs, files = tools.dir_content("%s/%s" % (directory, item_name))
-			if files:
-				filenumber = int(max([f for f in files if f.endswith(".xml")]).split(".")[0])+1
-			else:
-				filenumber = 1
-			filename="%s/%s/%s.xml" % (directory, item_name, str(filenumber).zfill(3))
+			for filenumber in count():
+				filename = "%s/%s/%s.%s.%s.xml" % (directory, item_name, System.host, author, str(filenumber).zfill(3))
+				if not os.path.exists(filename):
+					break
 			primitives_to_xml(self.pen_recorder.primitives, filename=filename, author=author)
 			self.pen_recorder.clear_primitives()
 			self.logger.info("%s captured %s to %s" % (author, item_name, filename))
 		filename = "circuit.pickle"
 		self.Canvas.SaveAsImage("circuit.png") # for bonus points
 		if self.pen_recorder:
+			self.pen_recorder.circuit.to_eps("test.eps")
 			f = file(filename, "w")
 			cPickle.dump(self.pen_recorder.circuit, f)
 			f.close()

reports/classifier_accuracy/FeaturesBayesianClassifier(FeatureExtractor,diagonal_gaussian_estimate)_accuracy.csv

-,and,bjt,box,buffer,capacitor,dc-source,diode,inductor,junction,nand,nor,or,resistor
-and,47,0,3,10,21,1,2,0,2,6,7,1,0,0.47
-bjt,0,95,2,0,0,0,3,0,0,0,0,0,0,0.95
-box,1,1,72,4,2,6,14,0,0,0,0,0,0,0.72
-buffer,8,0,3,43,23,5,17,0,0,0,1,0,0,0.43
-capacitor,7,0,0,4,83,0,0,0,6,0,0,0,0,0.83
-dc-source,1,0,9,8,11,69,1,0,0,1,0,0,0,0.69
-diode,4,5,13,18,0,8,52,0,0,0,0,0,0,0.52
-inductor,0,0,0,0,0,0,0,91,0,0,0,0,9,0.91
-junction,0,0,0,0,13,0,0,0,87,0,0,0,0,0.87
-nand,14,0,2,2,5,4,0,0,0,49,9,15,0,0.49
-nor,4,0,2,0,0,0,0,0,0,1,67,26,0,0.67
-or,9,0,0,2,2,0,0,0,0,12,3,72,0,0.72
-resistor,0,0,0,0,0,0,0,25,0,0,0,0,75,0.75
+,and,bjt,box,buffer,capacitor,dc-source,diode,inductor,junction,nand,nor,not,or,resistor
+and,8,0,3,7,17,1,9,0,0,17,0,36,2,0,0.08
+bjt,0,100,0,0,0,0,0,0,0,0,0,0,0,0,1.00
+box,1,0,76,14,0,3,6,0,0,0,0,0,0,0,0.76
+buffer,0,0,4,70,10,4,7,0,0,1,0,4,0,0,0.70
+capacitor,3,0,0,15,73,0,0,0,6,1,0,2,0,0,0.73
+dc-source,0,0,0,4,5,79,1,0,0,11,0,0,0,0,0.79
+diode,3,0,21,12,1,3,60,0,0,0,0,0,0,0,0.60
+inductor,0,0,0,0,0,0,0,100,0,0,0,0,0,0,1.00
+junction,0,0,0,0,28,0,0,0,72,0,0,0,0,0,0.72
+nand,6,0,3,5,2,1,3,0,0,67,0,7,6,0,0.67
+nor,7,0,3,0,1,1,0,0,0,6,65,0,17,0,0.65
+not,4,0,2,29,0,15,4,0,0,3,0,42,1,0,0.42
+or,6,0,0,5,4,0,0,0,1,18,23,3,40,0,0.40
+resistor,0,0,0,0,0,0,0,2,0,0,0,0,0,98,0.98
 
-0.69 total accuracy (902 out of 1300 tests)
-0.69 average_class_accuracy
-0.67 geometricmean_class_accuracy
-0.43 min_class_accuracy
-0.61 combined_accuracy number
+0.68 total accuracy (950 out of 1400 tests)
+0.68 average_class_accuracy
+0.60 geometricmean_class_accuracy
+0.08 min_class_accuracy
+0.41 combined_accuracy number

reports/classifier_accuracy/FeaturesBayesianClassifier(FeatureExtractor,probalistic_discrete_estimate)_accuracy.csv

-,and,bjt,box,buffer,capacitor,dc-source,diode,inductor,junction,nand,nor,or,resistor
-and,95,0,0,1,1,0,0,0,0,0,0,0,3,0.95
-bjt,0,100,0,0,0,0,0,0,0,0,0,0,0,1.00
-box,0,0,92,0,0,0,8,0,0,0,0,0,0,0.92
-buffer,0,0,0,100,0,0,0,0,0,0,0,0,0,1.00
-capacitor,0,0,0,0,99,0,0,0,1,0,0,0,0,0.99
-dc-source,0,0,0,0,0,100,0,0,0,0,0,0,0,1.00
-diode,0,0,32,0,0,0,67,0,1,0,0,0,0,0.67
-inductor,0,0,0,0,0,0,0,89,0,0,0,0,11,0.89
-junction,0,0,0,0,0,0,0,0,100,0,0,0,0,1.00
-nand,2,0,4,0,3,3,7,0,0,74,4,0,3,0.74
-nor,0,0,8,0,0,1,7,0,10,1,72,1,0,0.72
-or,10,0,0,4,0,0,0,0,4,0,1,76,5,0.76
-resistor,0,0,0,0,0,0,0,17,0,0,0,0,83,0.83
+,and,bjt,box,buffer,capacitor,dc-source,diode,inductor,junction,nand,nor,not,or,resistor
+and,93,0,4,3,0,0,0,0,0,0,0,0,0,0,0.93
+bjt,0,99,0,0,0,0,0,0,1,0,0,0,0,0,0.99
+box,0,0,97,0,0,0,3,0,0,0,0,0,0,0,0.97
+buffer,0,0,0,99,0,0,0,0,1,0,0,0,0,0,0.99
+capacitor,0,0,0,0,100,0,0,0,0,0,0,0,0,0,1.00
+dc-source,0,0,0,0,0,100,0,0,0,0,0,0,0,0,1.00
+diode,0,0,33,0,0,0,67,0,0,0,0,0,0,0,0.67
+inductor,0,0,0,0,0,0,0,100,0,0,0,0,0,0,1.00
+junction,0,0,0,0,0,0,0,0,100,0,0,0,0,0,1.00
+nand,0,0,3,0,2,7,4,0,0,75,0,9,0,0,0.75
+nor,0,0,1,1,0,9,3,0,4,11,69,1,1,0,0.69
+not,0,0,0,0,0,53,0,0,0,0,0,47,0,0,0.47
+or,9,0,0,0,0,1,1,0,0,0,0,5,84,0,0.84
+resistor,0,0,0,0,0,0,0,3,0,0,0,0,0,97,0.97
 
-0.88 total accuracy (1147 out of 1300 tests)
+0.88 total accuracy (1227 out of 1400 tests)
 0.88 average_class_accuracy
-0.87 geometricmean_class_accuracy
-0.67 min_class_accuracy
-0.82 combined_accuracy number
+0.86 geometricmean_class_accuracy
+0.47 min_class_accuracy
+0.75 combined_accuracy number

reports/classifier_accuracy/FeaturesBayesianClassifier(SimpleFeatureExtractor,diagonal_gaussian_estimate)_accuracy.csv

-,and,bjt,box,buffer,capacitor,dc-source,diode,inductor,junction,nand,nor,or,resistor
-and,95,0,0,3,1,1,0,0,0,0,0,0,0,0.95
-bjt,0,100,0,0,0,0,0,0,0,0,0,0,0,1.00
-box,0,0,42,0,0,0,58,0,0,0,0,0,0,0.42
-buffer,0,0,0,100,0,0,0,0,0,0,0,0,0,1.00
-capacitor,0,0,0,0,100,0,0,0,0,0,0,0,0,1.00
-dc-source,0,0,0,0,0,100,0,0,0,0,0,0,0,1.00
-diode,0,0,51,0,0,0,49,0,0,0,0,0,0,0.49
-inductor,0,0,0,0,0,0,0,86,0,0,0,0,14,0.86
-junction,0,0,0,0,0,0,0,0,100,0,0,0,0,1.00
-nand,0,0,0,0,0,6,0,0,0,52,42,0,0,0.52
-nor,0,0,0,0,0,1,0,0,0,20,78,1,0,0.78
-or,10,0,0,0,0,0,0,0,0,0,84,6,0,0.06
-resistor,0,0,0,0,0,0,0,34,0,0,0,0,66,0.66
+,and,bjt,box,buffer,capacitor,dc-source,diode,inductor,junction,nand,nor,not,or,resistor
+and,1,0,1,5,0,0,4,0,0,0,0,89,0,0,0.01
+bjt,0,100,0,0,0,0,0,0,0,0,0,0,0,0,1.00
+box,0,0,51,0,0,0,49,0,0,0,0,0,0,0,0.51
+buffer,0,0,0,100,0,0,0,0,0,0,0,0,0,0,1.00
+capacitor,0,0,0,0,100,0,0,0,0,0,0,0,0,0,1.00
+dc-source,0,0,0,0,0,100,0,0,0,0,0,0,0,0,1.00
+diode,0,0,50,0,0,0,50,0,0,0,0,0,0,0,0.50
+inductor,0,0,0,0,0,0,0,100,0,0,0,0,0,0,1.00
+junction,0,0,0,0,0,0,0,0,100,0,0,0,0,0,1.00
+nand,0,0,0,0,0,7,2,0,0,45,43,3,0,0,0.45
+nor,0,0,0,0,0,0,0,0,0,57,43,0,0,0,0.43
+not,0,0,0,0,0,51,0,0,0,0,0,49,0,0,0.49
+or,0,0,0,0,0,0,0,0,0,4,0,17,79,0,0.79
+resistor,0,0,0,0,0,0,0,2,0,0,0,0,0,98,0.98
 
-0.75 total accuracy (974 out of 1300 tests)
-0.75 average_class_accuracy
-0.63 geometricmean_class_accuracy
-0.06 min_class_accuracy
-0.43 combined_accuracy number
+0.73 total accuracy (1016 out of 1400 tests)
+0.73 average_class_accuracy
+0.54 geometricmean_class_accuracy
+0.01 min_class_accuracy
+0.41 combined_accuracy number

reports/classifier_accuracy/FeaturesBayesianClassifier(SimpleFeatureExtractor,probalistic_discrete_estimate)_accuracy.csv

-,and,bjt,box,buffer,capacitor,dc-source,diode,inductor,junction,nand,nor,or,resistor
-and,100,0,0,0,0,0,0,0,0,0,0,0,0,1.00
-bjt,0,100,0,0,0,0,0,0,0,0,0,0,0,1.00
-box,0,0,55,0,0,0,45,0,0,0,0,0,0,0.55
-buffer,0,0,0,100,0,0,0,0,0,0,0,0,0,1.00
-capacitor,0,0,0,0,100,0,0,0,0,0,0,0,0,1.00
-dc-source,0,0,0,0,0,100,0,0,0,0,0,0,0,1.00
-diode,0,0,59,0,0,0,41,0,0,0,0,0,0,0.41
-inductor,0,0,0,0,0,0,0,91,0,0,0,0,9,0.91
-junction,0,0,0,0,0,0,0,0,100,0,0,0,0,1.00
-nand,4,0,0,0,0,2,0,0,0,94,0,0,0,0.94
-nor,0,0,0,0,0,0,0,0,0,0,98,2,0,0.98
-or,0,0,0,0,0,0,0,0,2,0,0,98,0,0.98
-resistor,0,0,0,0,0,0,0,20,1,0,0,0,79,0.79
+,and,bjt,box,buffer,capacitor,dc-source,diode,inductor,junction,nand,nor,not,or,resistor
+and,93,0,2,2,0,0,3,0,0,0,0,0,0,0,0.93
+bjt,0,100,0,0,0,0,0,0,0,0,0,0,0,0,1.00
+box,0,0,46,0,0,0,54,0,0,0,0,0,0,0,0.46
+buffer,0,0,0,100,0,0,0,0,0,0,0,0,0,0,1.00
+capacitor,0,0,0,0,100,0,0,0,0,0,0,0,0,0,1.00
+dc-source,0,0,0,0,0,100,0,0,0,0,0,0,0,0,1.00
+diode,0,0,44,0,0,0,56,0,0,0,0,0,0,0,0.56
+inductor,0,0,0,0,0,0,0,100,0,0,0,0,0,0,1.00
+junction,0,0,0,0,0,0,0,0,100,0,0,0,0,0,1.00
+nand,2,0,4,0,0,4,2,0,0,86,0,2,0,0,0.86
+nor,0,0,0,2,0,2,1,0,0,13,80,1,1,0,0.80
+not,0,0,0,0,0,56,0,0,0,0,0,44,0,0,0.44
+or,10,0,1,1,0,0,1,0,0,0,0,7,80,0,0.80
+resistor,0,0,0,0,0,0,0,1,0,0,0,0,0,99,0.99
 
-0.89 total accuracy (1156 out of 1300 tests)
-0.89 average_class_accuracy
-0.86 geometricmean_class_accuracy
-0.41 min_class_accuracy
-0.73 combined_accuracy number
+0.85 total accuracy (1184 out of 1400 tests)
+0.85 average_class_accuracy
+0.82 geometricmean_class_accuracy
+0.44 min_class_accuracy
+0.71 combined_accuracy number

reports/classifier_accuracy/symbol_confusion_matrix.tex

- & and & bjt & box & buffer & capacitor & dc-source & diode & inductor & junction & nand & nor & not & or & resistor \\ 
-\hline
-and & 89 & 0 & 3 & 5 & 0 & 0 & 3 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
-bjt & 0 & 100 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
-box & 0 & 0 & 95 & 0 & 0 & 0 & 5 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
-buffer & 0 & 0 & 0 & 100 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
-capacitor & 0 & 0 & 0 & 0 & 100 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
-dc-source & 0 & 0 & 0 & 0 & 0 & 100 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
-diode & 0 & 0 & 44 & 0 & 0 & 0 & 56 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
-inductor & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 100 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
-junction & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 100 & 0 & 0 & 0 & 0 & 0 \\ 
-nand & 0 & 0 & 1 & 0 & 0 & 3 & 4 & 0 & 0 & 91 & 0 & 1 & 0 & 0 \\ 
-nor & 0 & 0 & 1 & 2 & 0 & 0 & 1 & 0 & 0 & 8 & 87 & 1 & 0 & 0 \\ 
-not & 0 & 0 & 0 & 0 & 0 & 52 & 0 & 0 & 0 & 0 & 0 & 48 & 0 & 0 \\ 
-or & 11 & 0 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 8 & 79 & 0 \\ 
-resistor & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 5 & 0 & 0 & 0 & 0 & 0 & 95 \\ 

reports/primitive_accuracy/primitive_accuracy.janto.txt

-Circle accuracy = 0.91 (29 out of 32)
-Corner accuracy = 1.00 (67 out of 67)
+Circle accuracy = 0.92 (55 out of 60)
+Corner accuracy = 0.86 (66 out of 77)
 Crescent accuracy = 0.98 (40 out of 41)
-Jagged accuracy = 0.89 (47 out of 53)
-Line accuracy = 1.00 (58 out of 58)
-Spiral accuracy = 0.96 (46 out of 48)
-accumulated accuracy = 0.95 (1.00 of goal[0.85])
+Jagged accuracy = 0.91 (49 out of 54)
+Line accuracy = 0.98 (57 out of 58)
+Spiral accuracy = 0.98 (48 out of 49)
+accumulated accuracy = 0.94 (1.00 of goal[0.85])

reports/primitive_accuracy/primitive_confusion_matrix.tex

- & Circle & Corner & Crescent & Jagged & Line & Spiral \\ 
-\hline
-Circle & 90 & 0 & 9 & 0 & 0 & 0 \\ 
-Corner & 0 & 100 & 0 & 0 & 0 & 0 \\ 
-Crescent & 0 & 0 & 97 & 0 & 2 & 0 \\ 
-Jagged & 0 & 0 & 0 & 88 & 0 & 11 \\ 
-Line & 0 & 0 & 0 & 0 & 100 & 0 \\ 
-Spiral & 0 & 0 & 0 & 2 & 2 & 95 \\ 
 		return text_report.strip()
 
 def symbol_tests_report():
+	logger = logging.getLogger("symbol_tests_report")
 	example_signatures = []
 	all_symbols = []
 	for symbol_type, filenames in Symbol.examples().items():
 	authors = sorted(tools.unique([sig[1] for sig in example_signatures]))
 	# determine test size
 	output = file("reports/classifier_accuracy/symbol_examples_size.tex", "w")
+	logger.info("writing %s" % output)
 	output.write("&%s&$\\bm{total}$\\\\\n" % "&".join(Symbol.types))
 	output.write("\\hline\n")
 	for author in authors:
 		correct = [c for c in correct if c==symbol_type]
 		return len(correct)/len(symbols)
 	output = file("reports/classifier_accuracy/symbol_examples_accuracy.tex", "w")
+	logger.info("writing %s" % output)
 	output.write("&%s&$\\bm{average}$\\\\\n" % "&".join(Symbol.types))
 	output.write("\\hline\n")
 	the_accuracy = {}
 	mem.cache = cache
 	return mem
 
+__all__.append("typename")
+def typename(instance):
+	"""
+		>>> class A(object): pass
+		>>> typename(A())
+		'A'
+	"""
+	return type(instance).__name__
+
 # files
 # -------------------------------------------------------------
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.