Toggle navigation
Toggle navigation
This project
Loading...
Sign in
grogv3
/
grog-cubi
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Francois Leveque
2017-04-06 10:38:26 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1b1e1414b90756d38af8c5c906dbea2c99a62627
1b1e1414
1 parent
f9605501
Analyse des recommandations et calcul de couverture.
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
9 deletions
grog-recommendation/grog-recommendation-postprocess/src/main/java/org/legrog/recommendation/postprocess/PostprocessingApplication.java
grog-recommendation/grog-recommendation-postprocess/src/main/java/org/legrog/recommendation/postprocess/PostprocessingApplication.java
View file @
1b1e141
...
...
@@ -29,12 +29,18 @@ public class PostprocessingApplication {
String
collectionSampleFilename
;
@Value
(
"${ratingSample.filename}"
)
String
ratingSampleFilename
;
@Value
(
"${recommandations.filename}"
)
String
recommandationsFilename
;
String
sampleFilename
;
Properties
properties
;
Set
<
Long
>
sampleItemIds
;
Set
<
Long
>
recommendedItemIds
;
Set
<
Long
>
sampleUserIds
;
Map
<
Long
,
Set
<
Long
>>
sampleItemUserIds
;
int
recommendableItemCount
;
int
recommendedItemCount
;
int
recommendableItemUserCount
;
int
recommendedItemUserCount
;
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
PostprocessingApplication
.
class
,
args
);
...
...
@@ -49,6 +55,53 @@ public class PostprocessingApplication {
loadParametersProperties
();
loadSampleFilename
();
analyzeSample
();
analyzeRecommendations
();
computeCoverage
();
}
void
computeCoverage
()
{
float
c1
;
float
c2
;
int
c3
;
logger
.
trace
(
"Nombre d'objets recommandés {}"
,
recommendedItemCount
);
logger
.
trace
(
"Nombre d'objets recommandables {}"
,
recommendableItemCount
);
c1
=
(
float
)
recommendedItemCount
/
recommendableItemCount
;
logger
.
trace
(
"c1 {}"
,
String
.
format
(
"%.3f"
,
c1
));
logger
.
trace
(
"Nombre de couples item-user recommandés {}"
,
recommendedItemUserCount
);
logger
.
trace
(
"Nombre de couples item-user recommandables {}"
,
recommendableItemUserCount
);
c2
=
(
float
)
recommendedItemUserCount
/
recommendableItemUserCount
;
logger
.
trace
(
"c2 {}"
,
String
.
format
(
"%.3f"
,
c2
));
c3
=
recommendedItemCount
;
logger
.
trace
(
"c3 {}"
,
c3
);
}
void
analyzeRecommendations
()
{
Reader
in
=
null
;
try
{
recommendedItemUserCount
=
0
;
recommendedItemIds
=
new
HashSet
<>();
in
=
new
InputStreamReader
(
new
FileInputStream
(
dataDir
+
recommandationsFilename
));
Iterable
<
CSVRecord
>
records
=
CSVFormat
.
TDF
.
withFirstRecordAsHeader
().
parse
(
in
);
for
(
CSVRecord
record
:
records
)
{
Long
itemId
=
Long
.
parseLong
(
record
.
get
(
"itemId"
));
Long
userId
=
Long
.
parseLong
(
record
.
get
(
"userId"
));
recommendedItemIds
.
add
(
itemId
);
if
(
sampleItemUserIds
.
containsKey
(
itemId
))
{
Set
<
Long
>
set
=
sampleItemUserIds
.
get
(
itemId
);
if
(!
set
.
contains
(
userId
))
{
recommendedItemUserCount
++;
}
}
}
recommendedItemCount
=
recommendedItemIds
.
size
();
logger
.
trace
(
"Nombre d'objets recommandés {}"
,
recommendedItemCount
);
logger
.
trace
(
"Nombre de couples item-user recommandés {}"
,
recommendedItemUserCount
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"analyzeRecommendations IOException : {}"
,
e
.
getStackTrace
());
}
}
...
...
@@ -59,8 +112,7 @@ public class PostprocessingApplication {
sampleItemIds
=
new
HashSet
<>();
sampleUserIds
=
new
HashSet
<>();
sampleItemUserIds
=
new
HashMap
<>();
//
in
=
new
InputStreamReader
(
this
.
getClass
().
getClassLoader
().
getResourceAsStream
(
dataDir
+
sampleFilename
));
in
=
new
InputStreamReader
(
new
FileInputStream
(
dataDir
+
sampleFilename
));
Iterable
<
CSVRecord
>
records
=
CSVFormat
.
TDF
.
withFirstRecordAsHeader
().
parse
(
in
);
for
(
CSVRecord
record
:
records
)
{
Long
itemId
=
Long
.
parseLong
(
record
.
get
(
"itemId"
));
...
...
@@ -77,7 +129,8 @@ public class PostprocessingApplication {
sampleItemUserIds
.
put
(
itemId
,
set
);
}
}
logger
.
trace
(
"Nombre d'objets recommandables {}"
,
sampleItemIds
.
size
());
recommendableItemCount
=
sampleItemIds
.
size
();
logger
.
trace
(
"Nombre d'objets recommandables {}"
,
recommendableItemCount
);
logger
.
trace
(
"Taille de la matrice item-user {}"
,
sampleItemIds
.
size
()
*
sampleUserIds
.
size
());
int
sampleCoupleCount
=
0
;
...
...
@@ -85,8 +138,9 @@ public class PostprocessingApplication {
sampleCoupleCount
+=
sampleItemUserIds
.
get
(
itemId
).
size
();
}
recommendableItemUserCount
=
sampleItemIds
.
size
()
*
sampleUserIds
.
size
()
-
sampleCoupleCount
;
logger
.
trace
(
"Nombre de couples item-user dans l'échantillon {}"
,
sampleCoupleCount
);
logger
.
trace
(
"Nombre de couples item-user recommandables {}"
,
sampleItemIds
.
size
()
*
sampleUserIds
.
size
()
-
sampleCouple
Count
);
logger
.
trace
(
"Nombre de couples item-user recommandables {}"
,
recommendableItemUser
Count
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"analyzeSample IOException : {}"
,
e
.
getStackTrace
());
...
...
@@ -114,12 +168,9 @@ public class PostprocessingApplication {
Properties
properties
=
new
Properties
();
InputStream
in
=
null
;
try
{
in
=
this
.
getClass
().
getClassLoader
().
getResourceAsStream
(
dataDir
+
parametersFilename
);
// in = new FileInputStream(dataDir + parametersFilename);
in
=
new
FileInputStream
(
dataDir
+
parametersFilename
);
properties
.
load
(
in
);
in
.
close
();
}
catch
(
FileNotFoundException
e
)
{
logger
.
error
(
"loadParametersProperties FileNotFoundException : {}"
,
e
.
getStackTrace
());
}
catch
(
IOException
e
)
{
logger
.
error
(
"loadParametersProperties IOException : {}"
,
e
.
getStackTrace
());
}
...
...
Please
register
or
login
to post a comment