From 91eb8840da3ce5c9d2bfb2c7b9072df6f192ba16 Mon Sep 17 00:00:00 2001 From: leifeld Date: Sat, 10 Feb 2024 12:23:58 +0000 Subject: [PATCH] Efficiency gains in kernel smoothing --- build/bibliography.md | 2 +- dna/src/main/java/dna/Dna.java | 2 +- dna/src/main/java/export/Exporter.java | 47 +++++++++++++++----------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/build/bibliography.md b/build/bibliography.md index b500ceb6..0f673fb2 100644 --- a/build/bibliography.md +++ b/build/bibliography.md @@ -4,7 +4,7 @@ author: bibliography: - bibliography.bib csl: apa-numeric-superscript-brackets.csl -date: 2024-02-04 +date: 2024-02-10 title: "Discourse Network Analysis: Bibliography" --- diff --git a/dna/src/main/java/dna/Dna.java b/dna/src/main/java/dna/Dna.java index 47532b3a..4d61d6b7 100644 --- a/dna/src/main/java/dna/Dna.java +++ b/dna/src/main/java/dna/Dna.java @@ -17,7 +17,7 @@ public class Dna { public static Dna dna; public static Logger logger; public static Sql sql; - public static final String date = "2024-02-04"; + public static final String date = "2024-02-10"; public static final String version = "3.0.11"; public static final String operatingSystem = System.getProperty("os.name"); public static File workingDirectory = null; diff --git a/dna/src/main/java/export/Exporter.java b/dna/src/main/java/export/Exporter.java index 675037d9..e7bb5b62 100644 --- a/dna/src/main/java/export/Exporter.java +++ b/dna/src/main/java/export/Exporter.java @@ -33,6 +33,7 @@ import java.time.format.DateTimeFormatter; import java.time.temporal.WeekFields; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.DoubleStream; @@ -1923,15 +1924,17 @@ private Matrix processTimeSlice(Matrix matrixResult, ArrayList[ for (int j = 0; j < X[0].length; j++) { for (int k = 0; k < X[0][0].length; k++) { for (int t = 0; t < X[i][j][k].size(); t++) { - if (Exporter.this.qualifierAggregation.equals("ignore")) { - m[i][j] = m[i][j] + zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); - } else if (Exporter.this.qualifierAggregation.equals("subtract")) { - if (Exporter.this.dataTypes.get(Exporter.this.qualifier).equals("boolean")) { - m[i][j] = m[i][j] + (((double) k) - 0.5) * 2 * zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); - } else if (Exporter.this.dataTypes.get(Exporter.this.qualifier).equals("integer")) { - m[i][j] = m[i][j] + k * zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); - } else if (Exporter.this.dataTypes.get(Exporter.this.qualifier).equals("short text")) { + if (Exporter.this.kernel.equals("gaussian") || (!X[i][j][k].get(t).getDateTime().isBefore(matrixResult.getStart()) && !X[i][j][k].get(t).getDateTime().isAfter(matrixResult.getStop()))) { // for computational efficiency, don't include statements outside of temporal bandwidth in computations if not necessary + if (Exporter.this.qualifierAggregation.equals("ignore")) { m[i][j] = m[i][j] + zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); + } else if (Exporter.this.qualifierAggregation.equals("subtract")) { + if (Exporter.this.dataTypes.get(Exporter.this.qualifier).equals("boolean")) { + m[i][j] = m[i][j] + (((double) k) - 0.5) * 2 * zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); + } else if (Exporter.this.dataTypes.get(Exporter.this.qualifier).equals("integer")) { + m[i][j] = m[i][j] + k * zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); + } else if (Exporter.this.dataTypes.get(Exporter.this.qualifier).equals("short text")) { + m[i][j] = m[i][j] + zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); + } } } } @@ -1956,18 +1959,22 @@ private Matrix processTimeSlice(Matrix matrixResult, ArrayList[ } double qdiff = 1.0 - qsim; for (int t = 0; t < X[i][j][k].size(); t++) { - double z1 = zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); - for (int t2 = 0; t2 < X[i2][j][k2].size(); t2++) { - double z2 = zeta(X[i2][j][k2].get(t2).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); - double z = Math.sqrt(z1 * z2); - if (Exporter.this.qualifierAggregation.equals("congruence")) { - m[i][i2] = m[i][i2] + qsim * z; - } else if (Exporter.this.qualifierAggregation.equals("conflict")) { - m[i][i2] = m[i][i2] + qdiff * z; - } else if (Exporter.this.qualifierAggregation.equals("subtract")) { - m[i][i2] = m[i][i2] + qsim * z - qdiff * z; - } else if (Exporter.this.qualifierAggregation.equals("ignore")) { - m[i][i2] = m[i][i2] + z; + if (Exporter.this.kernel.equals("gaussian") || (!X[i][j][k].get(t).getDateTime().isBefore(matrixResult.getStart()) && !X[i][j][k].get(t).getDateTime().isAfter(matrixResult.getStop()))) { // for computational efficiency, don't include statements outside of temporal bandwidth in computations if not necessary + double z1 = zeta(X[i][j][k].get(t).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); + for (int t2 = 0; t2 < X[i2][j][k2].size(); t2++) { + if (Exporter.this.kernel.equals("gaussian") || (!X[i2][j][k2].get(t2).getDateTime().isBefore(matrixResult.getStart()) && !X[i2][j][k2].get(t2).getDateTime().isAfter(matrixResult.getStop()))) { // for computational efficiency, don't include statements outside of temporal bandwidth in computations if not necessary + double z2 = zeta(X[i2][j][k2].get(t2).getDateTime(), matrixResult.getDateTime(), Exporter.this.windowSize, Exporter.this.timeWindow, Exporter.this.kernel); + double z = Math.sqrt(z1 * z2); + if (Exporter.this.qualifierAggregation.equals("congruence")) { + m[i][i2] = m[i][i2] + qsim * z; + } else if (Exporter.this.qualifierAggregation.equals("conflict")) { + m[i][i2] = m[i][i2] + qdiff * z; + } else if (Exporter.this.qualifierAggregation.equals("subtract")) { + m[i][i2] = m[i][i2] + qsim * z - qdiff * z; + } else if (Exporter.this.qualifierAggregation.equals("ignore")) { + m[i][i2] = m[i][i2] + z; + } + } } } }