[Debtags-commits] [svn] r1889 - in tagcoll/2.0: . tagcoll/coll tagcoll/stream

Enrico Zini enrico at costa.debian.org
Mon Sep 4 06:39:06 UTC 2006


Author: enrico
Date: Mon Sep  4 06:39:06 2006
New Revision: 1889

Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/coll/base.h
   tagcoll/2.0/tagcoll/coll/base.tcc
   tagcoll/2.0/tagcoll/stream/filters.h
Log:
 r3288 at viaza:  enrico | 2006-09-04 08:38:20 +0200
 filters.h needs wibble/singleton
 Updated relevance ordering formula after the tests with the python implementation
 Skipped one expensive and redundant iteration when computing itemsHavingTags


Modified: tagcoll/2.0/tagcoll/coll/base.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/base.h	(original)
+++ tagcoll/2.0/tagcoll/coll/base.h	Mon Sep  4 06:39:06 2006
@@ -68,13 +68,7 @@
 	public:
 		RelevanceOrder(const COLL& first, const Self& second)
 			: first(first), second(second) {}
-		bool operator()(const typename coll_traits<Self>::tag_type& t1, const typename coll_traits<Self>::tag_type& t2)
-		{
-			// Replace 10000* with (double) to be formally precise but
-			// use floating point aritmetics
-			return 10000 * second.getCardinality(t1) / first.getCardinality(t1)
-			     < 10000 * second.getCardinality(t2) / first.getCardinality(t2);
-		}
+		bool operator()(const typename coll_traits<Self>::tag_type& t1, const typename coll_traits<Self>::tag_type& t2);
 	};
 
 	/**

Modified: tagcoll/2.0/tagcoll/coll/base.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/coll/base.tcc	(original)
+++ tagcoll/2.0/tagcoll/coll/base.tcc	Mon Sep  4 06:39:06 2006
@@ -26,12 +26,36 @@
 #include <tagcoll/coll/base.h>
 #include <tagcoll/utils/set.h>
 #include <algorithm>
+#include <math.h>
 
 namespace tagcoll {
 namespace coll {
 
 template<typename T>
 class coll_traits;
+
+template<typename Self> template<typename COLL>
+bool ReadonlyCollection<Self>::RelevanceOrder<COLL>::operator()(
+		const typename coll_traits<Self>::tag_type& t1,
+		const typename coll_traits<Self>::tag_type& t2)
+{
+	// New cardinality divided by the old cardinality
+	// Weighted by the square root of the relevance, to downplay the very
+	// common tags a bit
+	//
+	float csub1 = second.getCardinality(t1);
+	float cfull1 = first.getCardinality(t1);
+	float csub2 = second.getCardinality(t2);
+	float cfull2 = first.getCardinality(t2);
+	float tfull = first.itemCount();
+	float rel1 = csub1 / cfull1 * sqrt(cfull1 / tfull);
+	float rel2 = csub2 / cfull2 * sqrt(cfull2 / tfull);
+
+	return rel1 < rel2;
+//	return 10000 * second.getCardinality(t1) / first.getCardinality(t1)
+//		 < 10000 * second.getCardinality(t2) / first.getCardinality(t2);
+}
+
 	
 template<typename Self>
 bool ReadonlyCollection<Self>::hasTag(const typename coll_traits<Self>::tag_type& tag) const
@@ -60,7 +84,7 @@
 	typename TAGS::const_iterator i = tags.begin();
 	typename coll_traits<Self>::itemset_type res = self().getItemsHavingTag(*i);
 
-	for ( ; i != tags.end(); ++i)
+	for (++i ; i != tags.end(); ++i)
 		res &= self().getItemsHavingTag(*i);
 
 	return res;

Modified: tagcoll/2.0/tagcoll/stream/filters.h
==============================================================================
--- tagcoll/2.0/tagcoll/stream/filters.h	(original)
+++ tagcoll/2.0/tagcoll/stream/filters.h	Mon Sep  4 06:39:06 2006
@@ -24,6 +24,7 @@
  */
 
 #include <wibble/mixin.h>
+#include <wibble/singleton.h>
 
 namespace std {
 template<typename A, typename B>



More information about the Debtags-commits mailing list