Fix suggestion not using previous negative feedback
This commit is contained in:
@@ -13,6 +13,7 @@ abstract class IMLDataDB<T> {
|
||||
Future<int> getFaceIndexedFileCount({int minimumMlVersion});
|
||||
Future<Map<String, int>> clusterIdToFaceCount();
|
||||
Future<Set<String>> getPersonIgnoredClusters(String personID);
|
||||
Future<Map<String, Set<String>>> getPersonToRejectedSuggestions();
|
||||
Future<Set<String>> getPersonClusterIDs(String personID);
|
||||
Future<Set<String>> getPersonsClusterIDs(List<String> personID);
|
||||
Future<void> clearTable();
|
||||
|
||||
@@ -212,6 +212,21 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
|
||||
return ignoredClusterIDs.union(rejectClusterIDs);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, Set<String>>> getPersonToRejectedSuggestions() async {
|
||||
final db = await instance.asyncDB;
|
||||
final List<Map<String, dynamic>> rejectMaps = await db.getAll(
|
||||
'SELECT $personIdColumn, $clusterIDColumn FROM $notPersonFeedback',
|
||||
);
|
||||
final Map<String, Set<String>> result = {};
|
||||
for (final map in rejectMaps) {
|
||||
final personID = map[personIdColumn] as String;
|
||||
final clusterID = map[clusterIDColumn] as String;
|
||||
result.putIfAbsent(personID, () => {}).add(clusterID);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Set<String>> getPersonClusterIDs(String personID) async {
|
||||
final db = await instance.asyncDB;
|
||||
|
||||
@@ -357,11 +357,23 @@ class ClusterFeedbackService<T> {
|
||||
allOtherPersonClustersToIgnore,
|
||||
minClusterSize: kMinimumClusterSizeSearchResult,
|
||||
);
|
||||
|
||||
final Map<String, Set<String>> personClusterToIgnoredClusters = {};
|
||||
final personToRejectedSuggestions =
|
||||
await mlDataDB.getPersonToRejectedSuggestions();
|
||||
for (final personID in personToRejectedSuggestions.keys) {
|
||||
final personCluster = personIdToBiggestCluster[personID];
|
||||
if (personCluster == null) continue;
|
||||
final ignoredClusters = personToRejectedSuggestions[personID] ?? {};
|
||||
personClusterToIgnoredClusters[personCluster] = ignoredClusters;
|
||||
}
|
||||
|
||||
final List<(String, double, String)> foundSuggestions =
|
||||
await calcSuggestionsMeanInComputer(
|
||||
clusterAvg,
|
||||
allPersonClusters,
|
||||
allOtherPersonClustersToIgnore,
|
||||
personClusterToIgnoredClusters: personClusterToIgnoredClusters,
|
||||
0.55,
|
||||
);
|
||||
|
||||
@@ -1014,8 +1026,9 @@ class ClusterFeedbackService<T> {
|
||||
Map<String, Vector> clusterAvg,
|
||||
Set<String> personClusters,
|
||||
Set<String> ignoredClusters,
|
||||
double maxClusterDistance,
|
||||
) async {
|
||||
double maxClusterDistance, {
|
||||
Map<String, Set<String>>? personClusterToIgnoredClusters,
|
||||
}) async {
|
||||
return await _computer.compute(
|
||||
_calcSuggestionsMean,
|
||||
param: {
|
||||
@@ -1023,6 +1036,7 @@ class ClusterFeedbackService<T> {
|
||||
'personClusters': personClusters,
|
||||
'ignoredClusters': ignoredClusters,
|
||||
'maxClusterDistance': maxClusterDistance,
|
||||
'personClusterToIgnoredClusters': personClusterToIgnoredClusters,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1341,6 +1355,9 @@ List<(String, double, String)> _calcSuggestionsMean(Map<String, dynamic> args) {
|
||||
final Set<String> personClusters = args['personClusters'];
|
||||
final Set<String> ignoredClusters = args['ignoredClusters'];
|
||||
final double maxClusterDistance = args['maxClusterDistance'];
|
||||
final Map<String, Set<String>>? personClusterToIgnoredClusters =
|
||||
args['personClusterToIgnoredClusters'];
|
||||
final bool extraIgnoreCheck = personClusterToIgnoredClusters != null;
|
||||
|
||||
final Map<String, List<(String, double)>> suggestions = {};
|
||||
const suggestionMax = 2000;
|
||||
@@ -1366,6 +1383,12 @@ List<(String, double, String)> _calcSuggestionsMean(Map<String, dynamic> args) {
|
||||
dev.log('[WARNING] no avg for personcluster $personCluster');
|
||||
continue;
|
||||
}
|
||||
if (extraIgnoreCheck &&
|
||||
personClusterToIgnoredClusters[personCluster] != null &&
|
||||
personClusterToIgnoredClusters[personCluster]!
|
||||
.contains(otherClusterID)) {
|
||||
continue;
|
||||
}
|
||||
final Vector avg = clusterAvg[personCluster]!;
|
||||
final distance = 1 - avg.dot(otherAvg);
|
||||
comparisons++;
|
||||
|
||||
Reference in New Issue
Block a user