Skip to content

Commit

Permalink
[SYSTEMDS-3696] Fix incremental SliceLine naming conflicts in namespace
Browse files Browse the repository at this point in the history
This patch fixes the SliceLine builtin in order to allow joint use of
SliceLine and incSliceLine without any naming conflicts in the
.builtin namespace.
  • Loading branch information
mboehm7 committed Sep 11, 2024
1 parent 1406e7b commit 95cfb76
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions scripts/builtin/incSliceLine.dml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ m_incSliceLine = function(
# create and score basic slices (conjunctions of 1 feature)
maxsc = getMaxScoreAllFeatures(nrow(X2), ncol(X2), prevLattice, metaPrevLattice,
prevStats, encodeLat, differentOffsets, alpha, eAvg, prevFoffb, prevFoffe, foffb, foffe);
[S, R, selCols] = createAndScoreBasicSlices(X2, changedX2, prevTK2, totalE, changedE,
[S, R, selCols] = createAndScoreBasicSlicesInc(X2, changedX2, prevTK2, totalE, changedE,
eAvg, eAvgOld, eAvgNew, minSup, alpha, minsc, maxsc, verbose, disableIncScorePruning);

# initialize lattice and statistics for incremental updates
Expand All @@ -194,10 +194,10 @@ m_incSliceLine = function(
Stats = list(R);

# initialize top-k
[TK, TKC] = maintainTopK(S, R, prevTK2, prevTKC2, k, minSup, foffb, foffe);
[TK, TKC] = maintainTopKInc(S, R, prevTK2, prevTKC2, k, minSup, foffb, foffe);

if( verbose ) {
[maxsc2, minsc2] = analyzeTopK(TKC);
[maxsc2, minsc2] = analyzeTopKInc(TKC);
print("incSliceLine: initial top-K: count="+nrow(TK)+", max="+maxsc2+", min="+minsc2+" (time="+(time()-t1)+")")
D = rbind(D, t(as.matrix(list(1, n2, nrow(S), maxsc2, minsc2))));
}
Expand All @@ -217,7 +217,7 @@ m_incSliceLine = function(

# enumerate candidate join pairs, incl size/error pruning
nrS = nrow(S);
S = getPairedCandidates(S, R, TKC, level, eAvg, minSup, alpha, n2, foffb, foffe);
S = getPairedCandidatesInc(S, R, TKC, level, eAvg, minSup, alpha, n2, foffb, foffe);
S2 = S;

# prepare and store output lattice for next run
Expand Down Expand Up @@ -264,21 +264,21 @@ m_incSliceLine = function(
parfor( i in 1:ceil(nrow(S)/tpBlksz), check=0 ) {
beg = (i-1)*tpBlksz + 1;
end = min(i*tpBlksz, nrow(R));
R[beg:end,] = evalSlice(X2, totalE, eAvg, t(S2[beg:end,]), level, alpha);
R[beg:end,] = evalSliceInc(X2, totalE, eAvg, t(S2[beg:end,]), level, alpha);
}
}
else { # data-parallel
R = evalSlice(X2, totalE, eAvg, t(S2), level, alpha);
R = evalSliceInc(X2, totalE, eAvg, t(S2), level, alpha);
}

# update output statistics
Stats = append(Stats, R);

# maintain top-k after evaluation
[TK, TKC] = maintainTopK(S, R, TK, TKC, k, minSup, foffb, foffe);
[TK, TKC] = maintainTopKInc(S, R, TK, TKC, k, minSup, foffb, foffe);

if(verbose) {
[maxsc2, minsc2] = analyzeTopK(TKC);
[maxsc2, minsc2] = analyzeTopKInc(TKC);
valid = as.integer(sum(R[,2]>0 & R[,4]>=minSup));
print(" -- valid slices after eval: "+valid+"/"+nrow(S));
print(" -- top-K: count="+nrow(TK)+", max="+maxsc2+", min="+minsc2);
Expand All @@ -299,7 +299,7 @@ m_incSliceLine = function(
}
}

createAndScoreBasicSlices = function(Matrix[Double] X2, Matrix[Double] X2p,
createAndScoreBasicSlicesInc = function(Matrix[Double] X2, Matrix[Double] X2p,
Matrix[Double] prevTK2, Matrix[Double] e, Matrix[Double] ep,
Double eAvg, Double eAvgOld, Double eAvgNew, Double minSup, Double alpha,
Double minsc, Matrix[Double] maxsc, Boolean verbose, Boolean disableIncScorePruning)
Expand Down Expand Up @@ -338,13 +338,13 @@ createAndScoreBasicSlices = function(Matrix[Double] X2, Matrix[Double] X2p,
S = table(seq(1,nrow(attr)), attr, nrow(attr), n2);

# score 1-slices and create initial top-k
sc = score(ss, se, eAvg, alpha, nrow(X2));
sc = scoreInc(ss, se, eAvg, alpha, nrow(X2));
R = cbind(sc, se, sm, ss);

# c) score pruning
# compute upper bound scores for all remaining slices
if(minsc > -Inf & !disableIncScorePruning) {
ubSc = scoreUB(ss, se, sm, eAvg, minSup, alpha, nrow(X2));
ubSc = scoreUBInc(ss, se, sm, eAvg, minSup, alpha, nrow(X2));
selCols3 = (ubSc > max(0, minsc));
S = removeEmpty(target=S, margin="rows", select=selCols3);
R = removeEmpty(target=R, margin="rows", select=selCols3);
Expand All @@ -361,14 +361,14 @@ createAndScoreBasicSlices = function(Matrix[Double] X2, Matrix[Double] X2p,
}
}

score = function(Matrix[Double] ss, Matrix[Double] se, Double eAvg, Double alpha, Integer n)
scoreInc = function(Matrix[Double] ss, Matrix[Double] se, Double eAvg, Double alpha, Integer n)
return(Matrix[Double] sc)
{
sc = alpha * ((se/ss) / eAvg - 1) - (1-alpha) * (n/ss - 1);
sc = replace(target=sc, pattern=NaN, replacement=-Inf);
}

scoreUB = function(Matrix[Double] ss, Matrix[Double] se, Matrix[Double] sm,
scoreUBInc = function(Matrix[Double] ss, Matrix[Double] se, Matrix[Double] sm,
Double eAvg, Integer minSup, Double alpha, Integer n)
return(Matrix[Double] sc)
{
Expand All @@ -384,7 +384,7 @@ scoreUB = function(Matrix[Double] ss, Matrix[Double] se, Matrix[Double] sm,
}


maintainTopK = function(Matrix[Double] S, Matrix[Double] R,
maintainTopKInc = function(Matrix[Double] S, Matrix[Double] R,
Matrix[Double] TK, Matrix[Double] TKC, Integer k,
Integer minSup, Matrix[Double] foffb, Matrix[Double] foffe)
return(Matrix[Double] TK, Matrix[Double] TKC)
Expand Down Expand Up @@ -419,7 +419,7 @@ maintainTopK = function(Matrix[Double] S, Matrix[Double] R,
}
}

analyzeTopK = function(Matrix[Double] TKC) return(Double maxsc, Double minsc) {
analyzeTopKInc = function(Matrix[Double] TKC) return(Double maxsc, Double minsc) {
maxsc = -Inf;
minsc = -Inf;
if( nrow(TKC)>0 ) {
Expand All @@ -428,7 +428,7 @@ analyzeTopK = function(Matrix[Double] TKC) return(Double maxsc, Double minsc) {
}
}

getPairedCandidates = function(Matrix[Double] S,
getPairedCandidatesInc = function(Matrix[Double] S,
Matrix[Double] R, Matrix[Double] TKC, Integer level,
Double eAvg, Integer minSup, Double alpha, Integer n2,
Matrix[Double] foffb, Matrix[Double] foffe)
Expand Down Expand Up @@ -490,8 +490,8 @@ getPairedCandidates = function(Matrix[Double] S,
ubError = replace(target=ubError, pattern=Inf, replacement=0);
ubMError = 1/rowMaxs(map * (1/t(sm)));
ubMError = replace(target=ubMError, pattern=Inf, replacement=0);
ubScores = scoreUB(ubSizes, ubError, ubMError, eAvg, minSup, alpha, n2);
[maxsc, minsc] = analyzeTopK(TKC);
ubScores = scoreUBInc(ubSizes, ubError, ubMError, eAvg, minSup, alpha, n2);
[maxsc, minsc] = analyzeTopKInc(TKC);

# score pruning
fScores = (ubScores > minsc & ubScores > 0)
Expand All @@ -512,7 +512,7 @@ getPairedCandidates = function(Matrix[Double] S,
}
}

evalSlice = function(Matrix[Double] X, Matrix[Double] e, Double eAvg,
evalSliceInc = function(Matrix[Double] X, Matrix[Double] e, Double eAvg,
Matrix[Double] tS, Integer l, Double alpha)

return(Matrix[Double] R)
Expand All @@ -525,7 +525,7 @@ evalSlice = function(Matrix[Double] X, Matrix[Double] e, Double eAvg,
sm = t(colMaxs(I * e)); # maximum tuple error in slice

# score of relative error and relative size
sc = score(ss, se, eAvg, alpha, nrow(X));
sc = scoreInc(ss, se, eAvg, alpha, nrow(X));
R = cbind(sc, se, sm, ss);
}

Expand Down Expand Up @@ -602,7 +602,7 @@ computeLowestPrevTK = function(Matrix[Double] prevTK2, Matrix[Double] X2,
sm = t(colMaxs(I * totalE)); # maximum tuple error in slice

# score slice and if applicable set min score for pruning
sc = score(ss, se, eAvg, alpha, nrow(X2));
sc = scoreInc(ss, se, eAvg, alpha, nrow(X2));
sc = replace(target=sc, pattern=-Inf, replacement=0)
R = cbind(sc, se, sm, ss);
minsc = min(sc);
Expand Down Expand Up @@ -711,7 +711,7 @@ getMaxScoreAllFeatures = function(Int numRows, Int numFeatures, List[Unknown] pr
if( length(prevStats) >= level ) {
R = as.matrix(prevStats[level]);
# rescaling of scores according to new size of X and eAvg
sc = score(R[,4], R[,2], eAvg, alpha, numRows);
sc = scoreInc(R[,4], R[,2], eAvg, alpha, numRows);
# robustness for S * sc creating NaNs because 0 * -Inf = NaN
sc = replace(target=sc, pattern=-Inf, replacement=0);
maxsc = max(maxsc, t(colMaxs(S*sc)));
Expand Down

0 comments on commit 95cfb76

Please sign in to comment.