Exemplo n.º 1
0
	# TODO(patryk): plot events.

	# Preprocessing phase.

	if compress_to_weekly_data:
		data = utils.compress_data_weekly(data)		

	if trimming_range > 0:
		data = eventutils.trim_data_to_events(data, events, trimming_range)

	input_vecs = []
	if treat_data_differentially:
		input_vecs = utils.make_prices_diffs_vecs(data)
	else:
		input_vecs = utils.make_prices_vecs(data)

	# Run clustering algorithm.

	if algorithm_type == ClusterAlg.KMEANS:
		labels, wcss, n = Pycluster.kcluster(input_vecs, number_of_clusters, 
				dist = dist_measure, npass = number_of_iters, 
				method = dist_method)
	elif algorithm_type == ClusterAlg.HIERARCHICAL:
		tree = Pycluster.treecluster(input_vecs, method = dist_method,
				dist = dist_method)
		labels = tree.cut(number_of_clusters)
	elif algorithm_type == ClusterAlg.SELFORGMAPS:
		labels, celldata = Pycluster.somcluster(input_vecs, nxgrid = xgrid, 
				nygrid = ygrid, niter = number_of_iters)
Exemplo n.º 2
0
	def testGetPricesVecs(self):
		"""Obtaining list of prices vectors."""

		vecs = utils.make_prices_vecs(self.data1)
		self.assertEqual(vecs, [[9.5, 9, 10.5, 20.5], [9.5, 16.5, 17.5, 18.5]])