Skip to content

Commit f0bda2f

Browse files
committed
Polarisation update; added greedy algo; removed modularity/EI
1 parent d9ef035 commit f0bda2f

File tree

13 files changed

+694
-492
lines changed

13 files changed

+694
-492
lines changed

dna/src/main/java/dna/Dna.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Dna {
1717
public static Dna dna;
1818
public static Logger logger;
1919
public static Sql sql;
20-
public static final String date = "2025-01-10";
20+
public static final String date = "2025-01-11";
2121
public static final String version = "3.0.11.4";
2222
public static final String operatingSystem = System.getProperty("os.name");
2323
public static File workingDirectory = null;

dna/src/main/java/dna/HeadlessDna.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -623,23 +623,23 @@ public void rTimeWindow(String networkType, String statementType, String variabl
623623
* @param invertSources boolean indicating whether the document-level source values should be included (= {@code true}) rather than excluded.
624624
* @param invertSections boolean indicating whether the document-level section values should be included (= {@code true}) rather than excluded.
625625
* @param invertTypes boolean indicating whether the document-level type values should be included (= {@code true}) rather than excluded.
626-
* @param k The number of clusters or factions, for example 2 for bi-polarisation.
627-
* @param numParents The number of cluster solutions (i.e., parents) to generate in each iteration, for example 30 or 50.
628-
* @param iterations For how many generations should the genetic algorithm run at most? This is the maximal number of generations through which optimisation should be attempted. Will be lower if early convergence is detected. A suggested starting value is 1000.
629-
* @param elitePercentage The share of cluster solutions in each parent generation that is copied into the children generation without changes, between 0.0 and 1.0, usually around 0.1.
630-
* @param mutationPercentage The probability with which each bit in any cluster solution is selected for mutation after the cross-over step. For example 0.1 to select 10% of the nodes to swap their memberships.
631-
* @param qualityFunction The quality function to evaluate cluster solutions. Supported values are "modularity", "eiIndex", and "absdiff".
632-
* @param normaliseMatrices boolean indicating whether the network matrices should be normalised before computing the polarisation score.
633-
* @param randomSeed The random seed to use for the random number generator. Pass 0 for random behaviour.
634-
* @return A PolarisationResultTimeSeries object containing the results of the genetic algorithm for each time step and iteration.
626+
* @param algorithm The algorithm to maximise polarisation at each time step. Can be "greedy" (for a greedy algorithm) or "genetic" (for a genetic algorithm).
627+
* @param normaliseScores boolean indicating whether the polarisation scores should be normalised by dividing them by their theoretical maximum within a given network. This takes away the effect of more activity (possibly due to participation by more actors or more statements per actor) contributing to polarisation scores and focuses solely on structure given the edge mass in the network. Without normalisation, time periods with more actors and activity will elevate the polarisation of the network (at constant levels of being divided over concepts).
628+
* @param numClusters The number of clusters or factions k, for example 2 for bi-polarisation.
629+
* @param numParents Only for the genetic algorithm: The number of cluster solutions (i.e., parents) to generate in each iteration, for example 30 or 50.
630+
* @param numterations Only for the genetic algorithm: For how many generations should the genetic algorithm run at most? This is the maximal number of generations through which optimisation should be attempted. Will be lower if early convergence is detected. A suggested starting value is 1000.
631+
* @param elitePercentage Only for the genetic algorithm: The share of cluster solutions in each parent generation that is copied into the children generation without changes, between 0.0 and 1.0, usually around 0.1.
632+
* @param mutationPercentage Only for the genetic algorithm: The probability with which each bit in any cluster solution is selected for mutation after the cross-over step. For example 0.1 to select 10% of the nodes to swap their memberships.
633+
* @param randomSeed Only for the genetic algorithm: The random seed to use for the random number generator. Pass 0 for random behaviour.
634+
* @return A PolarisationResultTimeSeries object containing the results of the algorithm for each time step and iteration.
635635
*/
636636
public PolarisationResultTimeSeries rPolarisation(String statementType, String variable1, boolean variable1Document,
637637
String variable2, boolean variable2Document, String qualifier, String duplicates, String startDate,
638638
String stopDate, String timeWindow, int windowSize, String kernel, boolean indentTime,
639639
String[] excludeVariables, String[] excludeValues, String[] excludeAuthors, String[] excludeSources,
640640
String[] excludeSections, String[] excludeTypes, boolean invertValues, boolean invertAuthors,
641-
boolean invertSources, boolean invertSections, boolean invertTypes, int k, int numParents, int iterations,
642-
double elitePercentage, double mutationPercentage, String qualityFunction, boolean normaliseMatrices,
641+
boolean invertSources, boolean invertSections, boolean invertTypes, String algorithm, boolean normaliseScores,
642+
int numClusters, int numParents, int numIterations, double elitePercentage, double mutationPercentage,
643643
long randomSeed) {
644644

645645
// step 1: preprocess arguments
@@ -667,13 +667,11 @@ public PolarisationResultTimeSeries rPolarisation(String statementType, String v
667667
}
668668
}
669669

670-
Polarisation polarisation = new Polarisation(st, variable1, variable1Document, variable2,
671-
variable2Document, qualifier, false, duplicates,
672-
ldtStart, ldtStop, timeWindow, windowSize, map, excludeAuthors, excludeSources,
673-
excludeSections, excludeTypes, invertValues, invertAuthors, invertSources,
674-
invertSections, invertTypes, kernel, indentTime, k, numParents,
675-
iterations, elitePercentage, mutationPercentage, qualityFunction, normaliseMatrices,
676-
randomSeed);
670+
Polarisation polarisation = new Polarisation(st, variable1, variable1Document, variable2, variable2Document,
671+
qualifier, false, duplicates, ldtStart, ldtStop, timeWindow, windowSize, kernel, indentTime,
672+
map, excludeAuthors, excludeSources, excludeSections, excludeTypes, invertValues, invertAuthors,
673+
invertSources, invertSections, invertTypes, algorithm, normaliseScores, numClusters, numParents,
674+
numIterations, elitePercentage, mutationPercentage, randomSeed);
677675

678676
return polarisation.getResults();
679677
}

dna/src/main/java/dna/export/Exporter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import model.*;
1313
import org.apache.commons.math3.linear.EigenDecomposition;
1414
import org.apache.commons.math3.linear.RealMatrix;
15-
import org.apache.commons.math3.analysis.function.Log;
1615
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
1716
import org.jdom.Attribute;
1817
import org.jdom.Comment;
@@ -27,7 +26,6 @@
2726
import org.ojalgo.matrix.decomposition.Eigenvalue;
2827

2928
import java.io.*;
30-
import java.lang.reflect.Array;
3129
import java.time.Duration;
3230
import java.time.LocalDateTime;
3331
import java.time.Period;

0 commit comments

Comments
 (0)