Skip to content

Commit f096e87

Browse files
committed
BE to AE and fixed time window options, remaining files
1 parent 71948f2 commit f096e87

File tree

9 files changed

+346
-193
lines changed

9 files changed

+346
-193
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ public void rTimeWindow(String networkType, String statementType, String variabl
597597
}
598598

599599
/**
600-
* Compute a sequence of one-mode network matrices or a single one-mode network matrix, and compute their polarisation score(s) and diagnostics.
600+
* Compute a sequence of one-mode network matrices or a single one-mode network matrix, and compute their polarization score(s) and diagnostics.
601601
*
602602
* @param statementType Statement type as a {@link String}.
603603
* @param variable1 First variable for export, provided as a {@link String}.
@@ -623,17 +623,17 @@ 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 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.
626+
* @param algorithm The algorithm to maximise polarization at each time step. Can be "greedy" (for a greedy algorithm) or "genetic" (for a genetic algorithm).
627+
* @param normaliseScores boolean indicating whether the polarization 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 polarization 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 polarization 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-polarization.
629629
* @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.
630630
* @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.
631631
* @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.
632632
* @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.
633633
* @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.
634+
* @return A PolarizationResultTimeSeries object containing the results of the algorithm for each time step and iteration.
635635
*/
636-
public PolarisationResultTimeSeries rPolarisation(String statementType, String variable1, boolean variable1Document,
636+
public PolarizationResultTimeSeries rPolarization(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,
@@ -667,13 +667,13 @@ public PolarisationResultTimeSeries rPolarisation(String statementType, String v
667667
}
668668
}
669669

670-
Polarisation polarisation = new Polarisation(st, variable1, variable1Document, variable2, variable2Document,
670+
Polarization polarization = new Polarization(st, variable1, variable1Document, variable2, variable2Document,
671671
qualifier, false, duplicates, ldtStart, ldtStop, timeWindow, windowSize, kernel, indentTime,
672672
map, excludeAuthors, excludeSources, excludeSections, excludeTypes, invertValues, invertAuthors,
673673
invertSources, invertSections, invertTypes, algorithm, normaliseScores, numClusters, numParents,
674674
numIterations, elitePercentage, mutationPercentage, randomSeed);
675675

676-
return polarisation.getResults();
676+
return polarization.getResults();
677677
}
678678

679679
/**

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,7 +3385,7 @@ public void initializeNestedBackbone() {
33853385
fullMatrix = this.computeOneModeMatrix(this.filteredStatements, this.qualifierAggregation, this.startDateTime, this.stopDateTime);
33863386
this.isolates = true; // include isolates in the iterations but not in the full matrix; will be adjusted to smaller full matrix dimensions without isolates manually each time in the iterations; necessary because some actors may be deleted in the backbone matrix otherwise after deleting their concepts
33873387

3388-
// compute normalised eigenvalues for the full matrix; no need to recompute every time as they do not change
3388+
// compute normalized eigenvalues for the full matrix; no need to recompute every time as they do not change
33893389
eigenvaluesFull = computeNormalizedEigenvalues(fullMatrix.getMatrix(), "ojalgo");
33903390
iteration = new int[fullConcepts.length];
33913391
backboneLoss = new double[fullConcepts.length];
@@ -3422,7 +3422,7 @@ public void iterateNestedBackbone() {
34223422
candidateMatrix = this.computeOneModeMatrix(candidateStatementList, this.qualifierAggregation, this.startDateTime, this.stopDateTime);
34233423
candidateMatrix = this.reduceCandidateMatrix(candidateMatrix, fullMatrix.getRowNames()); // ensure it has the right dimensions by purging isolates relative to the full matrix
34243424
candidateMatrices.add(candidateMatrix);
3425-
eigenvaluesCandidate = computeNormalizedEigenvalues(candidateMatrix.getMatrix(), "ojalgo"); // normalised eigenvalues for the candidate matrix
3425+
eigenvaluesCandidate = computeNormalizedEigenvalues(candidateMatrix.getMatrix(), "ojalgo"); // normalized eigenvalues for the candidate matrix
34263426
currentLosses[i] = spectralLoss(eigenvaluesFull, eigenvaluesCandidate);
34273427
}
34283428
double smallestLoss = 0.0;
@@ -3505,7 +3505,7 @@ public void initializeSimulatedAnnealingBackbone(boolean penalty, double p, int
35053505
fullMatrix = this.computeOneModeMatrix(this.filteredStatements, this.qualifierAggregation, this.startDateTime, this.stopDateTime);
35063506
this.isolates = true; // include isolates in the iterations; will be adjusted to full matrix without isolates manually each time
35073507

3508-
// compute normalised eigenvalues for the full matrix; no need to recompute every time as they do not change
3508+
// compute normalized eigenvalues for the full matrix; no need to recompute every time as they do not change
35093509
eigenvaluesFull = computeNormalizedEigenvalues(fullMatrix.getMatrix(), "ojalgo");
35103510

35113511
if (penalty) { // simulated annealing with penalty: initially one randomly chosen entity in the backbone set
@@ -3558,7 +3558,7 @@ public void initializeSimulatedAnnealingBackbone(boolean penalty, double p, int
35583558
finalMatrix = this.reduceCandidateMatrix(finalMatrix, fullMatrix.getRowNames()); // ensure it has the right dimensions by purging isolates relative to the full matrix
35593559

35603560
// eigenvalues for final matrix
3561-
eigenvaluesFinal = computeNormalizedEigenvalues(finalMatrix.getMatrix(), "ojalgo"); // normalised eigenvalues for the candidate matrix
3561+
eigenvaluesFinal = computeNormalizedEigenvalues(finalMatrix.getMatrix(), "ojalgo"); // normalized eigenvalues for the candidate matrix
35623562

35633563
// create an initial current backbone set B_0, also with the one c_j concept like in B: B_0 <- {c_j}
35643564
currentBackboneList = new ArrayList<String>(finalBackboneList);
@@ -3671,7 +3671,7 @@ public void iterateSimulatedAnnealingBackbone(boolean penalty) {
36713671
.collect(Collectors.toCollection(ArrayList::new));
36723672
candidateMatrix = this.computeOneModeMatrix(candidateStatementList, this.qualifierAggregation, this.startDateTime, this.stopDateTime); // create candidate matrix after filtering the statements based on the action that was executed
36733673
candidateMatrix = this.reduceCandidateMatrix(candidateMatrix, fullMatrix.getRowNames()); // ensure it has the right dimensions by purging isolates relative to the full matrix
3674-
eigenvaluesCandidate = computeNormalizedEigenvalues(candidateMatrix.getMatrix(), "ojalgo"); // normalised eigenvalues for the candidate matrix
3674+
eigenvaluesCandidate = computeNormalizedEigenvalues(candidateMatrix.getMatrix(), "ojalgo"); // normalized eigenvalues for the candidate matrix
36753675
if (penalty) {
36763676
newLoss = penalizedLoss(eigenvaluesFull, eigenvaluesCandidate, p, candidateBackboneList.size(), fullConcepts.length); // spectral distance between full and candidate matrix
36773677
} else {
@@ -3749,7 +3749,7 @@ public double[] evaluateBackboneSolution(String[] backboneEntities, int p) {
37493749
fullMatrix = this.computeOneModeMatrix(this.filteredStatements, this.qualifierAggregation, this.startDateTime, this.stopDateTime);
37503750
this.isolates = true; // include isolates in the iterations; will be adjusted to full matrix without isolates manually each time
37513751

3752-
// compute normalised eigenvalues for the full matrix; no need to recompute every time as they do not change
3752+
// compute normalized eigenvalues for the full matrix; no need to recompute every time as they do not change
37533753
eigenvaluesFull = computeNormalizedEigenvalues(fullMatrix.getMatrix(), "ojalgo");
37543754

37553755
// create copy of filtered statements and remove redundant entities
@@ -3771,7 +3771,7 @@ public double[] evaluateBackboneSolution(String[] backboneEntities, int p) {
37713771
.collect(Collectors.toCollection(ArrayList::new));
37723772
candidateMatrix = this.computeOneModeMatrix(candidateStatementList, this.qualifierAggregation, this.startDateTime, this.stopDateTime); // create candidate matrix after filtering the statements based on the action that was executed
37733773
candidateMatrix = this.reduceCandidateMatrix(candidateMatrix, fullMatrix.getRowNames()); // ensure it has the right dimensions by purging isolates relative to the full matrix
3774-
eigenvaluesCandidate = computeNormalizedEigenvalues(candidateMatrix.getMatrix(), "ojalgo"); // normalised eigenvalues for the candidate matrix
3774+
eigenvaluesCandidate = computeNormalizedEigenvalues(candidateMatrix.getMatrix(), "ojalgo"); // normalized eigenvalues for the candidate matrix
37753775
results[0] = penalizedLoss(eigenvaluesFull, eigenvaluesCandidate, p, backboneSet.size(), fullConcepts.length); // spectral distance between full and candidate matrix
37763776

37773777
// spectral distance between full and redundant set
@@ -3781,7 +3781,7 @@ public double[] evaluateBackboneSolution(String[] backboneEntities, int p) {
37813781
.collect(Collectors.toCollection(ArrayList::new));
37823782
candidateMatrix = this.computeOneModeMatrix(candidateStatementList, this.qualifierAggregation, this.startDateTime, this.stopDateTime); // create candidate matrix after filtering the statements based on the action that was executed
37833783
candidateMatrix = this.reduceCandidateMatrix(candidateMatrix, fullMatrix.getRowNames()); // ensure it has the right dimensions by purging isolates relative to the full matrix
3784-
eigenvaluesCandidate = computeNormalizedEigenvalues(candidateMatrix.getMatrix(), "ojalgo"); // normalised eigenvalues for the candidate matrix
3784+
eigenvaluesCandidate = computeNormalizedEigenvalues(candidateMatrix.getMatrix(), "ojalgo"); // normalized eigenvalues for the candidate matrix
37853785
results[1] = penalizedLoss(eigenvaluesFull, eigenvaluesCandidate, p, redundantSet.size(), fullConcepts.length); // spectral distance between full and candidate matrix
37863786

37873787
return results;

dna/src/main/java/dna/export/Matrix.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public Matrix(double[][] matrix, String[] rowNames, String[] columnNames, boolea
2626
this.integer = integer;
2727
this.start = start;
2828
this.stop = stop;
29+
30+
// calculate the mid-point date/time
31+
long startEpoch = start.toEpochSecond(ZoneOffset.UTC);
32+
long endEpoch = stop.toEpochSecond(ZoneOffset.UTC);
33+
long midpointEpoch = (startEpoch + endEpoch) / 2; // Average of timestamps
34+
this.dateTime = LocalDateTime.ofEpochSecond(midpointEpoch, 0, ZoneOffset.UTC);
2935
}
3036

3137
/**

0 commit comments

Comments
 (0)