Skip to content

Commit

Permalink
added old and newX as attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
fzoepffel committed May 7, 2024
1 parent 954274a commit c538998
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
22 changes: 12 additions & 10 deletions scripts/builtin/incSliceLine.dml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#
# INPUT:
# ---------------------------------------------------------------------------------------
# X Feature matrix in recoded/binned representation
# newX Feature matrix in recoded/binned representation
# oldX Original feature matrix
# e Error vector of trained model
# k Number of subsets required
# maxL maximum level L (conjunctions of L predicates), 0 unlimited
Expand All @@ -45,40 +46,41 @@
#
# OUTPUT:
# -----------------------------------------------------------------------------------------
# TK top-k slices (k x ncol(X) if successful)
# TK top-k slices (k x ncol(newX) if successful)
# TKC score, size, error of slices (k x 3)
# D debug matrix, populated with enumeration stats if verbose
# L lattice matrix
# RL statistics matrix for all slices in L
# -----------------------------------------------------------------------------------------

m_incSliceLine = function(Matrix[Double] X, Matrix[Double] e, Int k = 4,
m_incSliceLine = function(Matrix[Double] newX, Matrix[Double] oldX = matrix(0, 0, 0), Matrix[Double] e, Int k = 4,
Int maxL = 0, Int minSup = 32, Double alpha = 0.5, Boolean tpEval = TRUE,
Int tpBlksz = 16, Boolean selFeat = FALSE, Boolean verbose = FALSE, Matrix[Double] prevLattice = matrix(0, 0, 0) , Matrix[Double] prevRL = matrix(0, 0, 0))
Int tpBlksz = 16, Boolean selFeat = FALSE, Boolean verbose = FALSE,
Matrix[Double] prevLattice = matrix(0, 0, 0) , Matrix[Double] prevRL = matrix(0, 0, 0))
return(Matrix[Double] TK, Matrix[Double] TKC, Matrix[Double] D, Matrix[Double] L, Matrix[Double] RL)
{
t1 = time();

# init debug matrix: levelID, enumerated S, valid S, TKmax, TKmin
D = matrix(0, 0, 5);

m = nrow(X);
n = ncol(X);
m = nrow(newX);
n = ncol(newX);

# prepare offset vectors and one-hot encoded X
fdom = colMaxs(X);
# prepare offset vectors and one-hot encoded newX
fdom = colMaxs(newX);
foffb = t(cumsum(t(fdom))) - fdom;
foffe = t(cumsum(t(fdom)))
rix = matrix(seq(1,m)%*%matrix(1,1,n), m*n, 1)
cix = matrix(X + foffb, m*n, 1);
cix = matrix(newX + foffb, m*n, 1);
X2 = table(rix, cix, 1, m, as.scalar(foffe[,n]), FALSE); #one-hot encoded

# initialize statistics and basic slices
n2 = ncol(X2); # one-hot encoded features
eAvg = sum(e) / m; # average error
[S, R, selCols] = createAndScoreBasicSlices(X2, e, eAvg, minSup, alpha, verbose);

# initialize top-k
# initialize Lattice and Statistics
L = S
RL = R

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void testTop10SinglenodeTPSelE2() {

@Test
public void testIncSliceLineCustomInputs1() {
double[][] X = {
double[][] newX = {
{ 2, 1, 1, 2, 3, 2, 3, 3, 1, 2 },
{ 2, 2, 2, 3, 4, 1, 2, 1, 3, 2 },
{ 2, 1, 3, 3, 2, 2, 3, 1, 1, 4 },
Expand Down Expand Up @@ -188,12 +188,12 @@ public void testIncSliceLineCustomInputs1() {
{ 0.061, 2.796, 0.987, 5.000 },
{ 0.038, 3.194, 0.878, 6.000 }
};
testIncSliceLineCustomInputs(X, e, K, correctRes);
testIncSliceLineCustomInputs(newX, e, K, correctRes);
}

@Test
public void testIncSliceLineCustomInputs2() {
double[][] X = {
double[][] newX = {
{ 2, 1, 1, 1, 3, 4, 2, 2, 1, 2 },
{ 3, 3, 3, 2, 1, 2, 3, 1, 4, 2 },
{ 3, 2, 3, 1, 1, 1, 4, 3, 4, 2 },
Expand Down Expand Up @@ -236,12 +236,12 @@ public void testIncSliceLineCustomInputs2() {
{ 0.013, 3.091, 0.931, 5.000 }
};

testIncSliceLineCustomInputs(X, e, K, correctRes);
testIncSliceLineCustomInputs(newX, e, K, correctRes);
}

@Test
public void testIncSliceLineCustomInputs3() {
double[][] X = {
double[][] newX = {
{ 2, 1, 1, 2, 3, 2, 3, 3, 1, 2 },
{ 2, 2, 2, 3, 4, 1, 2, 1, 3, 2 },
{ 2, 1, 3, 3, 2, 2, 3, 1, 1, 4 },
Expand Down Expand Up @@ -306,7 +306,7 @@ public void testIncSliceLineCustomInputs3() {
{ 0.009, 2.923, 0.897, 4.000 },
{ 0.008, 3.391, 0.897, 5.000 }
};
testIncSliceLineCustomInputs(X, e, K, correctRes);
testIncSliceLineCustomInputs(newX, e, K, correctRes);
}

// @Test
Expand All @@ -325,18 +325,18 @@ private void runIncSliceLineTest(int K, String err, boolean dp, boolean selCols,

// run data preparation
fullDMLScriptName = HOME + PREP_NAME + ".dml";
programArgs = new String[] { "-args", data, err, output("X"), output("e") };
programArgs = new String[] { "-args", data, err, output("newX"), output("e") };
runTest(true, false, null, -1);

// read output and store for dml and R
double[][] X = TestUtils.convertHashMapToDoubleArray(readDMLMatrixFromOutputDir("X"));
double[][] newX = TestUtils.convertHashMapToDoubleArray(readDMLMatrixFromOutputDir("newX"));
double[][] e = TestUtils.convertHashMapToDoubleArray(readDMLMatrixFromOutputDir("e"));
writeInputMatrixWithMTD("X", X, true);
writeInputMatrixWithMTD("newX", newX, true);
writeInputMatrixWithMTD("e", e, true);

// execute main test
fullDMLScriptName = HOME + TEST_NAME + ".dml";
programArgs = new String[] { "-args", input("X"), input("e"), String.valueOf(K),
programArgs = new String[] { "-args", input("newX"), input("e"), String.valueOf(K),
String.valueOf(!dp).toUpperCase(), String.valueOf(selCols).toUpperCase(),
String.valueOf(VERBOSE).toUpperCase(), output("R") };

Expand All @@ -346,7 +346,7 @@ private void runIncSliceLineTest(int K, String err, boolean dp, boolean selCols,

// execute main test
fullDMLScriptName = HOME + "slicefinder" + ".dml";
programArgs = new String[] { "-args", input("X"), input("e"), String.valueOf(K),
programArgs = new String[] { "-args", input("newX"), input("e"), String.valueOf(K),
String.valueOf(!dp).toUpperCase(), String.valueOf(selCols).toUpperCase(),
String.valueOf(VERBOSE).toUpperCase(), output("R") };

Expand All @@ -371,7 +371,7 @@ private void runIncSliceLineTest(int K, String err, boolean dp, boolean selCols,
}
}

public void testIncSliceLineCustomInputs(double[][] X, double[][] e, int K, double[][] correctRes) {
public void testIncSliceLineCustomInputs(double[][] newX, double[][] e, int K, double[][] correctRes) {
boolean dp = true, selCols = false;
ExecMode mode = ExecMode.SINGLE_NODE;
ExecMode platformOld = setExecMode(mode);
Expand All @@ -381,11 +381,11 @@ public void testIncSliceLineCustomInputs(double[][] X, double[][] e, int K, doub
try {
loadTestConfiguration(getTestConfiguration(TEST_NAME));

writeInputMatrixWithMTD("X", X, false);
writeInputMatrixWithMTD("newX", newX, false);
writeInputMatrixWithMTD("e", e, false);

fullDMLScriptName = HOME + TEST_NAME + ".dml";
programArgs = new String[] { "-args", input("X"), input("e"), String.valueOf(K),
programArgs = new String[] { "-args", input("newX"), input("e"), String.valueOf(K),
String.valueOf(!dp).toUpperCase(), String.valueOf(selCols).toUpperCase(),
String.valueOf(VERBOSE).toUpperCase(), output("R") };

Expand Down
4 changes: 2 additions & 2 deletions src/test/scripts/functions/builtin/incSliceLine.dml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#
#-------------------------------------------------------------

X = read($1);
newX = read($1);
e = read($2);

# call slice finding
[TS,TR] = incSliceLine(X=X, e=e, k=$3,
[TS,TR] = incSliceLine(newX=newX, e=e, k=$3,
alpha=0.95, minSup=4, tpEval=$4, selFeat=$5, verbose=$6);

write(TR, $7)

0 comments on commit c538998

Please sign in to comment.