Skip to content

Commit 8573008

Browse files
committed
Improved error handling for polarisation
1 parent c944acd commit 8573008

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

dna/src/main/java/dna/export/Polarization.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ private void validateArguments(int n, int k) {
533533
Dna.logger.log(log);
534534
}
535535
if (n <= k) {
536-
LogEvent log = new LogEvent(Logger.ERROR, "Invalid number of nodes and clusters.",
537-
"Number of nodes (N) must be greater than the number of clusters (K).");
536+
LogEvent log = new LogEvent(Logger.WARNING, "Invalid number of nodes and clusters.",
537+
"Number of nodes (N) must be greater than the number of clusters (K). Try increasing the time window size for more statements.");
538538
Dna.logger.log(log);
539539
}
540540
}
@@ -1017,8 +1017,8 @@ public PolarizationResultTimeSeries geneticAlgorithm() {
10171017
* @return The PolarizationResult for the given time step.
10181018
*/
10191019
private PolarizationResult geneticTimeStep(int t, long seed) {
1020-
// Skip empty networks
1021-
if (this.congruence.get(t).getMatrix().length == 0 ||
1020+
// Skip empty or near-empty networks
1021+
if (this.congruence.get(t).getMatrix().length <= numClusters ||
10221022
(calculateMatrixNorm(this.congruence.get(t).getMatrix()) + calculateMatrixNorm(this.conflict.get(t).getMatrix())) == 0) {
10231023

10241024
return new PolarizationResult(
@@ -1512,7 +1512,7 @@ private PolarizationResult greedyTimeStep(Matrix congruence, Matrix conflict, bo
15121512
Dna.logger.log(log);
15131513
}
15141514

1515-
if (congruenceMatrix.length > 0 || combinedNorm == 0.0) { // if the network has no nodes or edges, skip this step and return 0 directly
1515+
if (congruenceMatrix.length >= numClusters || combinedNorm == 0.0) { // if the network has no (or too few) nodes or edges, skip this step and return 0 directly
15161516

15171517
// Create initially random cluster solution to update
15181518
Random random = new Random(seed);
@@ -1572,7 +1572,7 @@ private PolarizationResult greedyTimeStep(Matrix congruence, Matrix conflict, bo
15721572
congruence.getStop(),
15731573
congruence.getDateTime());
15741574
return pr;
1575-
} else { // zero result because network is empty
1575+
} else { // zero result because network is empty or too small
15761576
PolarizationResult pr = new PolarizationResult(
15771577
new double[] { 0 },
15781578
new double[] { 0 },

0 commit comments

Comments
 (0)