Skip to content

Commit

Permalink
Efficiency gains in kernel smoothing
Browse files Browse the repository at this point in the history
  • Loading branch information
leifeld committed Feb 10, 2024
1 parent 3d6bd05 commit 91eb884
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build/bibliography.md
Expand Up @@ -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"
---

Expand Down
2 changes: 1 addition & 1 deletion dna/src/main/java/dna/Dna.java
Expand Up @@ -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;
Expand Down
47 changes: 27 additions & 20 deletions dna/src/main/java/export/Exporter.java
Expand Up @@ -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;
Expand Down Expand Up @@ -1923,15 +1924,17 @@ private Matrix processTimeSlice(Matrix matrixResult, ArrayList<ExportStatement>[
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);
}
}
}
}
Expand All @@ -1956,18 +1959,22 @@ private Matrix processTimeSlice(Matrix matrixResult, ArrayList<ExportStatement>[
}
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;
}
}
}
}
}
Expand Down

0 comments on commit 91eb884

Please sign in to comment.