Skip to content

Commit e2ff7ae

Browse files
committed
Recommender and mining implemented.
1 parent 06d5c98 commit e2ff7ae

File tree

18 files changed

+879
-381
lines changed

18 files changed

+879
-381
lines changed

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<module>prefrec-stratification</module>
1414
<module>prefrec-pref-mining</module>
1515
<module>prefrec-execution</module>
16+
<module>prefrec-recommender</module>
1617
</modules>
1718
<dependencies>
1819
<dependency>
@@ -63,7 +64,7 @@
6364
<dependency>
6465
<groupId>cprefminer</groupId>
6566
<artifactId>cprefminermulti</artifactId>
66-
<version>1.0.0</version>
67+
<version>1.0.2</version>
6768
</dependency>
6869
</dependencies>
6970

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package br.ufu.facom.lsi.prefrec.agregation;
2+
3+
import java.util.Iterator;
4+
import java.util.LinkedHashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
public class Agregator {
9+
10+
private Map<Long, List<Map<Long, Double[][]>>> clusterToUserMatrixScorer = new LinkedHashMap<>();
11+
private Map<Double[][], List<Map<Long, Double[][]>>> concensualMatrixMap = new LinkedHashMap<>();
12+
13+
public Agregator(Map<Long, List<Map<Long, Double[][]>>> clusterToUserMatrixScorer) {
14+
this.clusterToUserMatrixScorer = clusterToUserMatrixScorer;
15+
}
16+
17+
public void execute() {
18+
19+
try {
20+
// Read input
21+
//readInput();
22+
23+
int length = clusterToUserMatrixScorer.values().iterator().next()
24+
.get(0).values().iterator().next().length;
25+
26+
// Reading cluster
27+
for (Long id : clusterToUserMatrixScorer.keySet()) {
28+
Double[][] concensualMatrix = initMatrix(length);
29+
30+
// Reading Matrix
31+
Iterator<Map<Long, Double[][]>> it = clusterToUserMatrixScorer
32+
.get(id).iterator();
33+
while (it.hasNext()) {
34+
Map<Long, Double[][]> map = it.next();
35+
for (Double[][] temp : map.values()) {
36+
for (int k = 0; k < temp.length; k++) {
37+
for (int h = 0; h < temp[k].length; h++) {
38+
concensualMatrix[k][h] += temp[k][h];
39+
}
40+
}
41+
}
42+
}
43+
44+
for (int k = 0; k < concensualMatrix.length; k++) {
45+
for (int h = 0; h < concensualMatrix[k].length; h++) {
46+
concensualMatrix[k][h] = concensualMatrix[k][h]
47+
/ clusterToUserMatrixScorer.get(id).size();
48+
}
49+
}
50+
51+
concensualMatrixMap.put(concensualMatrix,
52+
clusterToUserMatrixScorer.get(id.intValue()));
53+
}
54+
55+
//writeConcensualMatrizMapOutput();
56+
57+
} catch (Exception e) {
58+
e.printStackTrace();
59+
}
60+
61+
}
62+
63+
// private void writeConcensualMatrizMapOutput() throws Exception {
64+
//
65+
// try (FileOutputStream fout = new FileOutputStream("../ConcensualMatrixMap.prefrecmining");
66+
// ObjectOutputStream oos = new ObjectOutputStream(fout)) {
67+
//
68+
// oos.writeObject(concensualMatrixMap);
69+
// oos.flush();
70+
// fout.flush();
71+
//
72+
// } catch (Exception e) {
73+
// throw e;
74+
// }
75+
// }
76+
77+
private Double[][] initMatrix(int length) {
78+
79+
Double[][] result = new Double[length][length];
80+
for (int i = 0; i < length; i++) {
81+
for (int j = 0; j < length; j++) {
82+
result[i][j] = 0.0;
83+
}
84+
}
85+
return result;
86+
}
87+
88+
/**
89+
* @return the clusterToUserMatrixScorer
90+
*/
91+
public Map<Long, List<Map<Long, Double[][]>>> getClusterToUserMatrixScorer() {
92+
return clusterToUserMatrixScorer;
93+
}
94+
95+
/**
96+
* @return the concensualMatrixMap
97+
*/
98+
public Map<Double[][], List<Map<Long, Double[][]>>> getConcensualMatrixMap() {
99+
return concensualMatrixMap;
100+
}
101+
102+
// /**
103+
// * Deserialize the output file
104+
// */
105+
// @SuppressWarnings("unchecked")
106+
// public static void readInput() throws Exception {
107+
//
108+
// File f = new File("../ClusterOutput.prefrecCluster");
109+
//
110+
// try (InputStream file = new FileInputStream(f);
111+
// InputStream buffer = new BufferedInputStream(file);
112+
// ObjectInput input = new ObjectInputStream(buffer);) {
113+
//
114+
// // deserialize the Map
115+
// clusterToUserMatrixScorer = (Map<Long, List<Map<Long, Double[][]>>>) input
116+
// .readObject();
117+
//
118+
// } catch (Exception e) {
119+
// throw e;
120+
// }
121+
// }
122+
}

prefrec-agregation/src/main/java/br/ufu/facom/lsi/prefrec/agregation/Main.java

Lines changed: 0 additions & 112 deletions
This file was deleted.

prefrec-execution/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<artifactId>prefrec-pref-mining</artifactId>
2929
<version>0.0.1-SNAPSHOT</version>
3030
</dependency>
31+
<dependency>
32+
<groupId>br.ufu.facom.lsi</groupId>
33+
<artifactId>prefrec-recommender</artifactId>
34+
<version>0.0.1-SNAPSHOT</version>
35+
</dependency>
3136
</dependencies>
3237

3338
</project>

prefrec-execution/src/main/java/br/ufu/facom/lsi/prefrec/Main.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

prefrec-execution/src/main/java/br/ufu/facom/lsi/prefrec/crossvalidation/CrossValidation.java

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
*
3+
*/
4+
package br.ufu.facom.lsi.prefrec.execution;
5+
6+
import br.ufu.facom.lsi.prefrec.execution.crossvalidation.CrossValidation;
7+
8+
/**
9+
* @author Klerisson
10+
*
11+
*/
12+
public class Main {
13+
14+
/**
15+
* @param args
16+
*/
17+
public static void main(String[] args) {
18+
19+
CrossValidation cv = new CrossValidation(5);
20+
cv.execute();
21+
22+
}
23+
24+
}

0 commit comments

Comments
 (0)