Commit 0b42f57e0f0127e463ac1b913c8bec15dd014a58
1 parent
f8dca06c
Exists in
master
and in
1 other branch
Minor fixes.
Showing
5 changed files
with
46 additions
and
25 deletions
Show diff stats
src/app_recommender.py
... | ... | @@ -37,7 +37,7 @@ if __name__ == '__main__': |
37 | 37 | cfg = Config() |
38 | 38 | rec = Recommender(cfg) |
39 | 39 | user = LocalSystem() |
40 | - user.maximal_pkg_profile() | |
40 | + user.no_auto_pkg_profile() | |
41 | 41 | |
42 | 42 | begin_time = datetime.datetime.now() |
43 | 43 | logging.debug("Recommendation computation started at %s" % begin_time) | ... | ... |
src/data.py
... | ... | @@ -27,6 +27,7 @@ import logging |
27 | 27 | import hashlib |
28 | 28 | |
29 | 29 | from error import Error |
30 | +from singleton import Singleton | |
30 | 31 | |
31 | 32 | class Item: |
32 | 33 | """ |
... | ... | @@ -52,19 +53,6 @@ def normalize_tags(string): |
52 | 53 | """ |
53 | 54 | return string.replace(':','_').replace('-','\'') |
54 | 55 | |
55 | -class Singleton(object): | |
56 | - """ | |
57 | - Base class for inheritance of only-one-instance classes. | |
58 | - Singleton design pattern. | |
59 | - """ | |
60 | - def __new__(cls, *args, **kwargs): | |
61 | - """ | |
62 | - Creates a new instance of the class only if none already exists. | |
63 | - """ | |
64 | - if '_inst' not in vars(cls): | |
65 | - cls._inst = object.__new__(cls) | |
66 | - return cls._inst | |
67 | - | |
68 | 56 | class TagsXapianIndex(xapian.WritableDatabase,Singleton): |
69 | 57 | """ |
70 | 58 | Data source for tags info defined as a singleton xapian database. | ... | ... |
src/evaluation.py
... | ... | @@ -24,8 +24,9 @@ import logging |
24 | 24 | |
25 | 25 | from user import * |
26 | 26 | from recommender import * |
27 | +from singleton import Singleton | |
27 | 28 | |
28 | -class Metric: | |
29 | +class Metric(Singleton): | |
29 | 30 | """ |
30 | 31 | Base class for metrics. Strategy design pattern. |
31 | 32 | """ |
... | ... | @@ -40,7 +41,7 @@ class Precision(Metric): |
40 | 41 | """ |
41 | 42 | Set metric description. |
42 | 43 | """ |
43 | - self.desc = " Precision " | |
44 | + self.desc = " Precision " | |
44 | 45 | |
45 | 46 | def run(self,evaluation): |
46 | 47 | """ |
... | ... | @@ -57,7 +58,7 @@ class Recall(Metric): |
57 | 58 | """ |
58 | 59 | Set metric description. |
59 | 60 | """ |
60 | - self.desc = " Recall " | |
61 | + self.desc = " Recall " | |
61 | 62 | |
62 | 63 | def run(self,evaluation): |
63 | 64 | """ |
... | ... | @@ -74,7 +75,7 @@ class F1(Metric): |
74 | 75 | """ |
75 | 76 | Set metric description. |
76 | 77 | """ |
77 | - self.desc = " F1 " | |
78 | + self.desc = " F1 " | |
78 | 79 | |
79 | 80 | def run(self,evaluation): |
80 | 81 | """ |
... | ... | @@ -92,7 +93,7 @@ class MAE(Metric): |
92 | 93 | """ |
93 | 94 | Set metric description. |
94 | 95 | """ |
95 | - self.desc = " MAE " | |
96 | + self.desc = " MAE " | |
96 | 97 | |
97 | 98 | def get_errors(self,evaluation): |
98 | 99 | """ |
... | ... | @@ -125,7 +126,7 @@ class MSE(MAE): |
125 | 126 | """ |
126 | 127 | Set metric description. |
127 | 128 | """ |
128 | - self.desc = " MSE " | |
129 | + self.desc = " MSE " | |
129 | 130 | |
130 | 131 | def run(self,evaluation): |
131 | 132 | """ |
... | ... | @@ -144,7 +145,7 @@ class Coverage(Metric): |
144 | 145 | """ |
145 | 146 | Set initial parameters. |
146 | 147 | """ |
147 | - self.desc = " Coverage " | |
148 | + self.desc = " Coverage " | |
148 | 149 | self.repository_size = repository_size |
149 | 150 | self.covered = set() |
150 | 151 | |
... | ... | @@ -214,14 +215,14 @@ class CrossValidation: |
214 | 215 | for r in range(self.rounds): |
215 | 216 | metrics_result = "" |
216 | 217 | for metric in self.metrics_list: |
217 | - metrics_result += (" %.2f |" % | |
218 | - (self.cross_results[metric.desc][r])) | |
218 | + metrics_result += (" %2.1f%% |" % | |
219 | + (self.cross_results[metric.desc][r]*100)) | |
219 | 220 | str += "| %d |%s\n" % (r,metrics_result) |
220 | 221 | metrics_mean = "" |
221 | 222 | for metric in self.metrics_list: |
222 | 223 | mean = float(sum(self.cross_results[metric.desc]) / |
223 | 224 | len(self.cross_results[metric.desc])) |
224 | - metrics_mean += " %.2f |" % (mean) | |
225 | + metrics_mean += " %2.1f%% |" % (mean*100) | |
225 | 226 | str += "| Mean |%s\n" % (metrics_mean) |
226 | 227 | return str |
227 | 228 | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +#!/usr/bin/python | |
2 | + | |
3 | +# singleton - python class that implements singleton design pattern. | |
4 | +# | |
5 | +# Copyright (C) 2010 Tassia Camoes <tassia@gmail.com> | |
6 | +# | |
7 | +# This program is free software: you can redistribute it and/or modify | |
8 | +# it under the terms of the GNU General Public License as published by | |
9 | +# the Free Software Foundation, either version 3 of the License, or | |
10 | +# (at your option) any later version. | |
11 | +# | |
12 | +# This program is distributed in the hope that it will be useful, | |
13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | +# GNU General Public License for more details. | |
16 | +# | |
17 | +# You should have received a copy of the GNU General Public License | |
18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | +class Singleton(object): | |
20 | + """ | |
21 | + Base class for inheritance of only-one-instance classes. | |
22 | + Singleton design pattern. | |
23 | + """ | |
24 | + def __new__(cls, *args, **kwargs): | |
25 | + """ | |
26 | + Creates a new instance of the class only if none already exists. | |
27 | + """ | |
28 | + if '_inst' not in vars(cls): | |
29 | + cls._inst = object.__new__(cls) | |
30 | + return cls._inst | |
31 | + | ... | ... |
src/strategy.py
... | ... | @@ -21,9 +21,10 @@ |
21 | 21 | import os, re |
22 | 22 | import xapian |
23 | 23 | from data import * |
24 | +from singleton import Singleton | |
24 | 25 | import recommender |
25 | 26 | |
26 | -class ReputationHeuristic: | |
27 | +class ReputationHeuristic(Singleton): | |
27 | 28 | """ |
28 | 29 | Abstraction for diferent reputation heuristics. |
29 | 30 | """ | ... | ... |