Hi,
I contacted Remi before, but he is using a much improved version of his
tools now and suggested I could share the patch here.
It speeds up the mm-tools by a factor of 50 in the iteration loop if you
use it for a high number of gammas (like in case of large patterns).
I hope it helps:)
This patch is minimalistic, so you should be able to check it's
correctness by reading. I have some more changes which allow the gcc
vectorizer to improve some of the initial loops, but this does not make
such a big difference.
Detlef
diff -rupN mm-orig/mm.cpp mm/mm.cpp
--- mm-orig/mm.cpp 2013-05-15 18:32:40.000000000 +0200
+++ mm/mm.cpp 2013-05-15 18:37:07.000000000 +0200
@@ -11,6 +11,7 @@
#include <iomanip>
#include <sstream>
#include <vector>
+#include <map>
#include <cmath>
#include <fstream>
@@ -180,13 +181,16 @@ void CGameCollection::MM(int Feature)
//
// Main loop over games
//
+ std::map<int,double> tMul;
for (int i = vgame.size(); --i >= 0;)
{
- double tMul[vGamma.size()];
- {
- for (int i = vGamma.size(); --i >= 0;)
- tMul[i] = 0.0;
- }
+ //double tMul[vGamma.size()];
+ //{
+ // for (int i = vGamma.size(); --i >= 0;)
+ // tMul[i] = 0.0;
+ //}
+ tMul.clear();
+
double Den = 0.0;
std::vector<CTeam> &v = vgame[i].vParticipants;
@@ -208,15 +212,25 @@ void CGameCollection::MM(int Feature)
if (FeatureIndex >= 0)
{
- tMul[FeatureIndex] += Product;
+ //tMul[FeatureIndex] += Product;
+ if (tMul.count(FeatureIndex))
+ tMul[FeatureIndex] += Product;
+ else
+ tMul[FeatureIndex]=Product;
+
Product *= vGamma[FeatureIndex];
}
Den += Product;
}
- for (int i = Max; --i >= Min;)
- vDen[i] += tMul[i] / Den;
+ //for (int i = Max; --i >= Min;)
+ // vDen[i] += tMul[i] / Den;
+ for (std::map<int,double>::iterator it=tMul.begin();it!=tMul.end();++it)
+ {
+ int key=it->first;
+ vDen[key]+=it->second / Den;
+ }
}
//
_______________________________________________
Computer-go mailing list
[email protected]
http://dvandva.org/cgi-bin/mailman/listinfo/computer-go