Skip to content

Commit

Permalink
without parallelization
Browse files Browse the repository at this point in the history
  • Loading branch information
mufwan committed Feb 19, 2024
1 parent 502ec80 commit 04143a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
16 changes: 8 additions & 8 deletions scripts/keywordSpotting.dml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ y_shuffled = Xy_shuffled[,num_col] # Labels, the last column
[X_train, X_test, y_train, y_test] = split(X=X_shuffled, Y=y_shuffled, seed= 13)

# Preprocess with fft Optionally move before split.
[X_train_re, X_train_im] = stft(X_train, 256, 128)
[X_test_re, X_test_im] = stft(X_test, 256, 128)
[X_train_re, X_train_im] = stft(X_train, 4, 2)
[X_test_re, X_test_im] = stft(X_test, 4, 2)


X_train_re_sq = X_train_re^2
Expand All @@ -38,15 +38,15 @@ magnitudes_test = sqrt(sum_X_test_sq)
bias = lm(X=magnitudes_train, y=y_train, reg=1e-1, maxi=10, verbose=TRUE)
predictions = lmPredict(X=magnitudes_test, B=bias, verbose=FALSE)

sign_predictions = sign(predictions)
sign_Y = sign(y_test)
#sign_predictions = sign(predictions)
#sign_Y = sign(y_test)

correct = sum(sign_predictions == sign_Y)
total = nrow(y_test)
accuracy = correct / total
#correct = sum(sign_predictions == sign_Y)
#total = nrow(y_test)
#accuracy = correct / total

#print(toString(predictions))
print(toString(accuracy))
#print(toString(accuracy))

R = lmPredictStats(yhat=predictions, ytest=y_test, lm=TRUE)
print(toString(R))
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static MatrixBlock[] stft(MatrixBlock re, MatrixBlock im, int windowSize,
double[] re_inter = new double[out_len];
double[] im_inter = new double[out_len];

ExecutorService pool = CommonThreadPool.get(1);
//ExecutorService pool = CommonThreadPool.get(1);

for (int h = 0; h < rows; h++){
for (int i = 0; i < numberOfFramesPerRow; i++) {
Expand All @@ -75,35 +75,14 @@ public static MatrixBlock[] stft(MatrixBlock re, MatrixBlock im, int windowSize,
stftOutput_im[h * rowLength + i * windowSize + j] = im.getDenseBlockValues()[h * cols + i * stepSize + j];
}
}
final int finalH = h;
final int finalI = i;
pool.submit(() -> fft_one_dim(stftOutput_re, stftOutput_im, re_inter, im_inter, finalH * rowLength + finalI * windowSize, finalH * rowLength + (finalI+1) * windowSize, windowSize, 1));
awaitParallelExecution(pool);
//final int finalH = h;
//final int finalI = i;
fft_one_dim(stftOutput_re, stftOutput_im, re_inter, im_inter, h * rowLength + i * windowSize, h * rowLength + (i+1) * windowSize, windowSize, 1);
//pool.submit(() -> fft_one_dim(stftOutput_re, stftOutput_im, re_inter, im_inter, finalH * rowLength + finalI * windowSize, finalH * rowLength + (finalI+1) * windowSize, windowSize, 1));
//awaitParallelExecution(pool);
}
}


/*
for (int i = 0; i < stftOutput_re.length; i++) {
System.out.println(stftOutput_re[i] + stftOutput_im[i]);
}
*/
int i = 0;
while (i < 1000000000) {
i = i + 1;
}
i = 0;
while (i < 1000000000) {
i = i + 1;
}
i = 0;
while (i < 1000000000) {
i = i + 1;
}



return new MatrixBlock[]{new MatrixBlock(rows, rowLength, stftOutput_re), new MatrixBlock(rows, rowLength, stftOutput_im)};
}

Expand Down

0 comments on commit 04143a5

Please sign in to comment.