updates?

cmurphy [2010-03-15 19:49:16]
updates?
Filename
org/columbia/seas/cs/amsterdam/ArffFile.java
org/columbia/seas/cs/amsterdam/DataProcessor.java
org/columbia/seas/cs/amsterdam/MetaDescriptorParser.java
org/columbia/seas/cs/amsterdam/SimpleParser.java
org/columbia/seas/cs/amsterdam/Util.java
test/naivebayestest.java
diff --git a/org/columbia/seas/cs/amsterdam/ArffFile.java b/org/columbia/seas/cs/amsterdam/ArffFile.java
index 1e9cfa7..6f9bae9 100644
--- a/org/columbia/seas/cs/amsterdam/ArffFile.java
+++ b/org/columbia/seas/cs/amsterdam/ArffFile.java
@@ -10,17 +10,373 @@
 package org.columbia.seas.cs.amsterdam;

 import java.io.*;
+import weka.core.*;

 /**
  *
  * @author Kuang Shen
  */
-public class ArffFile extends File{
+public class ArffFile extends File implements Variable{

     /** Creates a new instance of ArffFile */
     public ArffFile(String fileName) {
         super(fileName);
     }

+    public Variable add(int colNumber, int rowNumber, double val)
+    {
+        weka.core.converters.ArffLoader loader = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
+        try{
+            FileInputStream fis = new FileInputStream(this);
+            loader.setSource(fis);
+            Instances structure = loader.getStructure();
+            Instances instances = loader.getDataSet();
+
+            // perform addition to the values of all attributes at the speicified row
+            if (colNumber == 0)
+            {
+                int nAttr = instances.numAttributes();
+                Instance instance = instances.instance(rowNumber-1);
+                for (int i = 0; i < nAttr; i++)
+                {
+                    instance.setValue(i, instance.value(i)+val );
+                }
+            }
+
+            // peform addition to the values of all rows on the specified attribute
+            else if (rowNumber == 0)
+            {
+                int nInst = instances.numInstances();
+                for (int i = 0; i < nInst; i++)
+                {
+                    Instance instance = instances.instance(i);
+                    instance.setValue(colNumber-1, instance.value(colNumber-1)+val );
+                }
+            }
+
+            // perform addition to a single cell with specified row and column number
+            else
+            {
+                Instance instance = instances.instance(rowNumber-1);
+                instance.setValue(colNumber-1, instance.value(colNumber-1)+val );
+            }
+
+            saver.setStructure(structure);
+            saver.setInstances(instances);
+
+            loader.reset();
+            fis.close();
+
+            saver.setFile(this);
+            saver.writeBatch();
+
+        }catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return this;
+    }
+
+    public Variable multiply(int colNumber, int rowNumber, double val)
+    {
+        weka.core.converters.ArffLoader loader = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
+        try{
+            FileInputStream fis = new FileInputStream(this);
+            loader.setSource(fis);
+            Instances structure = loader.getStructure();
+            Instances instances = loader.getDataSet();
+
+            // perform multiplication to the values of all attributes at the speicified row
+            if (colNumber == 0)
+            {
+                int nAttr = instances.numAttributes();
+                Instance instance = instances.instance(rowNumber-1);
+                for (int i = 0; i < nAttr; i++)
+                {
+                    instance.setValue(i, instance.value(i)*val );
+                }
+            }
+
+            // peform multiplication to the values of all rows on the specified attribute
+            else if (rowNumber == 0)
+            {
+                int nInst = instances.numInstances();
+                for (int i = 0; i < nInst; i++)
+                {
+                    Instance instance = instances.instance(i);
+                    instance.setValue(colNumber-1, (instance.value(colNumber-1))*val );
+                }
+            }
+
+            // perform multiplication to a single cell with specified row and column number
+            else
+            {
+                Instance instance = instances.instance(rowNumber-1);
+                instance.setValue(colNumber-1, (instance.value(colNumber-1))*val );
+            }
+
+            saver.setStructure(structure);
+            saver.setInstances(instances);
+
+            loader.reset();
+            fis.close();
+
+            saver.setFile(this);
+            saver.writeBatch();
+
+        }catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return this;
+    }
+
+    public Variable permute()
+    {
+        System.out.println("Permuting Arff file: "+this.getPath());
+        weka.core.converters.ArffLoader loader = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
+        try{
+            FileInputStream fis = new FileInputStream(this);
+            loader.setSource(fis);
+            Instances structure = loader.getStructure();
+            Instances instances = loader.getDataSet();
+            instances.randomize(new java.util.Random());
+
+            saver.setStructure(structure);
+            saver.setInstances(instances);
+
+            loader.reset();
+            fis.close();
+
+            saver.setFile(this);
+            saver.writeBatch();
+            System.out.println("Finished permuteing instances object for: "+this.getName());
+
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return this;
+    }
+
+    public Variable inverse()
+    {
+        System.out.println("Inverting Arff file: "+this.getPath());
+        weka.core.converters.ArffLoader loader = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
+        try{
+            FileInputStream fis = new FileInputStream(this);
+            loader.setSource(fis);
+            Instances structure = loader.getStructure();
+            Instances instances = loader.getDataSet();
+
+            Instances inst2 = new Instances(structure, instances.numInstances());
+            for (int i=instances.numInstances()-1; i>=0; i--)
+            {
+                inst2.add(instances.instance(i));
+            }
+
+            saver.setStructure(structure);
+            saver.setInstances(inst2);
+
+            loader.reset();
+            fis.close();
+
+            saver.setFile(this);
+            saver.writeBatch();
+            System.out.println("Finished inverting instances object for: "+this.getName());
+
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return this;
+    }
+
+    public Variable negate(int colNumber, int rowNumber)
+    {
+        System.out.println("Negating values for Arff file: "+this.getPath()+" on column "+colNumber+" and row "+rowNumber);
+        weka.core.converters.ArffLoader loader = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
+        try{
+            FileInputStream fis = new FileInputStream(this);
+            loader.setSource(fis);
+            Instances structure = loader.getStructure();
+            Instances instances = loader.getDataSet();
+
+            multiply(colNumber, rowNumber, -1);
+
+            saver.setStructure(structure);
+            saver.setInstances(instances);
+
+            loader.reset();
+            fis.close();
+
+            saver.setFile(this);
+            saver.writeBatch();
+            System.out.println("Finished negating "+this.getName());
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return this;
+    }
+
+    public Variable sort(int attributeToSortBy)
+    {
+        System.out.println("sorting values for Arff file: "+this.getPath()+" on attribute "+attributeToSortBy);
+        weka.core.converters.ArffLoader loader = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
+        try{
+            FileInputStream fis = new FileInputStream(this);
+            loader.setSource(fis);
+            Instances structure = loader.getStructure();
+            Instances instances = loader.getDataSet();
+
+            instances.sort(attributeToSortBy-1);
+
+            saver.setStructure(structure);
+            saver.setInstances(instances);
+
+            loader.reset();
+            fis.close();
+
+            saver.setFile(this);
+            saver.writeBatch();
+            System.out.println("Finished sorting "+this.getName()+" on attribute "+attributeToSortBy);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return this;
+    }
+
+    public Variable exclude(int rowNumber)
+    {
+        System.out.println("Excluding row " + rowNumber + " from Arff file: "+this.getPath());
+        weka.core.converters.ArffLoader loader = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
+        try{
+            FileInputStream fis = new FileInputStream(this);
+            loader.setSource(fis);
+            Instances structure = loader.getStructure();
+            Instances instances = loader.getDataSet();
+
+            instances.delete(rowNumber-1);
+
+            saver.setStructure(structure);
+            saver.setInstances(instances);
+
+            loader.reset();
+            fis.close();
+
+            saver.setFile(this);
+            saver.writeBatch();
+            System.out.println("Finished excluding row "+ rowNumber +" "+ this.getName());
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return this;
+    }
+
+    public Variable randomSubset(int size)
+    {
+        System.out.println("Taking random subset with the size of " + size + " from Arff file: "+this.getPath());
+        weka.core.converters.ArffLoader loader = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
+        try{
+            FileInputStream fis = new FileInputStream(this);
+            loader.setSource(fis);
+            Instances structure = loader.getStructure();
+            Instances instances = loader.getDataSet();
+
+            if (size < instances.numInstances())
+            {
+                instances.randomize(new java.util.Random());
+
+                saver.setStructure(structure);
+                saver.setInstances(instances);
+
+                loader.reset();
+                fis.close();
+
+                saver.setFile(this);
+                saver.writeBatch();
+            }
+
+            System.out.println("Finished taking random subset from Arff file"+ this.getName());
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return this;
+    }
+
+    public boolean equal(Variable var)
+    {
+        boolean flag = true;
+        System.out.println("checking outputs consistency");
+        weka.core.converters.ArffLoader loader1 = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffLoader loader2 = new weka.core.converters.ArffLoader();
+        try{
+                System.out.println("loading file:"+this.getAbsolutePath());
+                loader1.setFile(this);
+                System.out.println("loading file:"+((ArffFile)var).getAbsolutePath());
+                loader2.setFile((ArffFile)var);
+                Instances structure1 = loader1.getStructure();
+                Instances instances1 = loader1.getDataSet();
+                instances1.setClassIndex(instances1.numAttributes() - 1);
+                Instances structure2 = loader2.getStructure();
+                Instances instances2 = loader2.getDataSet();
+                instances2.setClassIndex(instances2.numAttributes() - 1);
+
+                if (instances1.numInstances()!=instances1.numInstances())
+                    flag = false;
+                for (int z=0; z<instances1.numInstances(); z++)
+                {
+                    if (instances1.instance(z).classValue()!=instances2.instance(z).classValue())
+                        return false;
+                }
+
+                    System.out.println("checking result: "+flag);
+                } catch (Exception ex) {
+                    ex.printStackTrace();
+                }
+        return flag;
+    }
+
+    public boolean similar(Variable var, double offset)
+    {
+        boolean flag = true;
+        System.out.println("checking outputs consistency");
+        weka.core.converters.ArffLoader loader1 = new weka.core.converters.ArffLoader();
+        weka.core.converters.ArffLoader loader2 = new weka.core.converters.ArffLoader();
+        try{
+                System.out.println("loading file:"+this.getAbsolutePath());
+                loader1.setFile(this);
+                System.out.println("loading file:"+((ArffFile)var).getAbsolutePath());
+                int numberOfInconsistency = 0;
+                loader2.setFile((ArffFile)var);
+                Instances structure1 = loader1.getStructure();
+                Instances instances1 = loader1.getDataSet();
+                instances1.setClassIndex(instances1.numAttributes() - 1);
+                Instances structure2 = loader2.getStructure();
+                Instances instances2 = loader2.getDataSet();
+                instances2.setClassIndex(instances2.numAttributes() - 1);
+
+                if (instances1.numInstances()!=instances1.numInstances())
+                    flag = false;
+                else
+                {
+                    for (int z=0; z<instances1.numInstances(); z++)
+                    {
+                        if (instances1.instance(z).classValue()!=instances2.instance(z).classValue())
+                            numberOfInconsistency++;
+                    }
+                    if (numberOfInconsistency / instances1.numInstances() > offset)
+                        flag = false;
+                }
+                    System.out.println("checking result: "+flag);
+           } catch (Exception ex) {
+                ex.printStackTrace();
+           }
+        return flag;
+    }

 }
diff --git a/org/columbia/seas/cs/amsterdam/DataProcessor.java b/org/columbia/seas/cs/amsterdam/DataProcessor.java
index bde5fce..f952303 100644
--- a/org/columbia/seas/cs/amsterdam/DataProcessor.java
+++ b/org/columbia/seas/cs/amsterdam/DataProcessor.java
@@ -37,36 +37,8 @@ public class DataProcessor {
             {
                 Object var1 = o1.get(i);
                 Object var2 = o2.get(i);
-                if ( (var1 instanceof org.columbia.seas.cs.amsterdam.ArffFile) && (var2 instanceof org.columbia.seas.cs.amsterdam.ArffFile))
-                {
-                    System.out.println("checking outputs consistency");
-                    weka.core.converters.ArffLoader loader1 = new weka.core.converters.ArffLoader();
-                    weka.core.converters.ArffLoader loader2 = new weka.core.converters.ArffLoader();
-                    try{
-                        System.out.println("loading file:"+((File)var1).getAbsolutePath());
-                        loader1.setFile((File)var1);
-                        System.out.println("loading file:"+((File)var2).getAbsolutePath());
-                        loader2.setFile((File)var2);
-                        Instances structure1 = loader1.getStructure();
-                        Instances instances1 = loader1.getDataSet();
-                        instances1.setClassIndex(instances1.numAttributes() - 1);
-                        Instances structure2 = loader2.getStructure();
-                        Instances instances2 = loader2.getDataSet();
-                        instances2.setClassIndex(instances2.numAttributes() - 1);
-
-                        if (instances1.numInstances()!=instances1.numInstances())
-                            flag = false;
-                        for (int z=0; z<instances1.numInstances(); z++)
-                        {
-                            if (instances1.instance(z).classValue()!=instances2.instance(z).classValue())
-                                return false;
-                        }
-
-                        System.out.println("checking result: "+flag);
-                    } catch (Exception ex) {
-                        ex.printStackTrace();
-                    }
-                }
+                flag = ((Variable)var1).equal((Variable)var2);
+
             }
         }

@@ -85,26 +57,7 @@ public class DataProcessor {
             {
                 Object var1 = i1.get(i);
                 Object var2 = i2.get(i);
-                if ( (var1 instanceof org.columbia.seas.cs.amsterdam.ArffFile) && (var2 instanceof org.columbia.seas.cs.amsterdam.ArffFile))
-                {
-                    System.out.println("checking outputs consistency");
-                    weka.core.converters.ArffLoader loader1 = new weka.core.converters.ArffLoader();
-                    weka.core.converters.ArffLoader loader2 = new weka.core.converters.ArffLoader();
-                    try{
-                        loader1.setFile((File)var1);
-                        loader2.setFile((File)var2);
-                        Instances structure1 = loader1.getStructure();
-                        Instances instances1 = loader1.getDataSet();
-                        Instances structure2 = loader2.getStructure();
-                        Instances instances2 = loader2.getDataSet();
-
-                        if (instances1.numInstances()!=instances1.numInstances())
-                            flag = false;
-                        System.out.println("checking result: "+flag);
-                    } catch (Exception ex) {
-                        ex.printStackTrace();
-                    }
-                }
+                flag = ((Variable)var1).equal((Variable)var2);
             }
         }

@@ -148,28 +101,13 @@ public class DataProcessor {
     // create copy of the original file then permute the order of the data instances
     public static void permute(Object o)
     {
-        if (o instanceof org.columbia.seas.cs.amsterdam.ArffFile)
-        {
-            permute((ArffFile)o);
-        }
-        if (o instanceof org.columbia.seas.cs.amsterdam.DBResultSet)
-        {
-            permute((DBResultSet)o);
-        }
+        ((Variable)o).permute();
     }

     // create copy of the original file then negate the value of the data instances's column or row
-    public static void negate(Object o, String operator, int number)
+    public static void negate(Object o, int colNumber, int rowNumber)
     {
-        System.out.println("Negating values  ");
-        if (o instanceof org.columbia.seas.cs.amsterdam.ArffFile)
-        {
-            negate((ArffFile)o, operator, number);
-        }
-        if (o instanceof org.columbia.seas.cs.amsterdam.DBResultSet)
-        {
-            //permute((DBResultSet)o);
-        }
+        ((Variable)o).negate(colNumber, rowNumber);
     }

     public static void negate(ArffFile af, String operator, int number)
@@ -218,14 +156,7 @@ public class DataProcessor {
     // create copy of the original file then inverse the order of the data instances
     public static void inverse(Object o)
     {
-        if (o instanceof org.columbia.seas.cs.amsterdam.ArffFile)
-        {
-            inverse((ArffFile)o);
-        }
-        if (o instanceof org.columbia.seas.cs.amsterdam.DBResultSet)
-        {
-            //inverse((DBResultSet)o);
-        }
+        ((Variable)o).inverse();
     }

     public static void inverse(ArffFile af)
@@ -300,6 +231,33 @@ public class DataProcessor {
                     e.printStackTrace();
                 }
             }
+            else if (var instanceof org.columbia.seas.cs.amsterdam.ModelFile )
+            {
+                String path = ((org.columbia.seas.cs.amsterdam.ModelFile)var).getPath();
+
+                try {
+
+                    org.columbia.seas.cs.amsterdam.ModelFile newFile
+                        = new org.columbia.seas.cs.amsterdam.ModelFile( "./tmp/branch"+offset+"/"+path);
+
+
+                    FileReader fileIn = new FileReader((org.columbia.seas.cs.amsterdam.ArffFile)var);
+                    FileWriter fileOut = new FileWriter(newFile);
+                    int c;
+
+                    while ((c = fileIn.read()) != -1)
+                    fileOut.write(c);
+
+                    fileIn.close();
+                    fileOut.close();
+
+                    newIn.add(newFile);
+
+                } catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
             else{
                 newIn.add(var);
             }
@@ -309,13 +267,14 @@ public class DataProcessor {

     public static String processParam(ArrayList in, int offset, String paramStr)
     {
-        String newStr = paramStr;
+        String newStr = new String(paramStr);
         for (int i=0; i<in.size(); i++)
         {
             Object var = in.get(i);
-            if (var instanceof org.columbia.seas.cs.amsterdam.ArffFile )
+            if (var instanceof File )
             {
-                String path = ((org.columbia.seas.cs.amsterdam.ArffFile)var).getPath();
+                String path = ((File)var).getPath();
+                //System.out.println("path:"+path);
                 //System.out.println("old string:"+newStr);
                 newStr = newStr.replaceAll(path, "./tmp/branch"+offset+"/"+path);
                 //System.out.println("new string:"+newStr);
@@ -326,6 +285,14 @@ public class DataProcessor {

     }

+    public static String processParam(ArrayList in, ArrayList out, int offset, String paramStr)
+    {
+        String str = "";
+        str = processParam(in, offset, paramStr);
+        str = processParam(out, offset, str);
+        return str;
+    }
+


     public static Output clone(Output out, int offset)
@@ -335,7 +302,9 @@ public class DataProcessor {
         Output newOut = new Output();
         for (int i=0; i<out.size(); i++)
         {
+
             Object var = out.get(i);
+            //System.out.println(var instanceof org.columbia.seas.cs.amsterdam.ModelFile);
             if (var instanceof org.columbia.seas.cs.amsterdam.ArffFile )
             {
                 String path = ((org.columbia.seas.cs.amsterdam.ArffFile)var).getPath();
@@ -351,6 +320,21 @@ public class DataProcessor {
                     e.printStackTrace();
                 }
             }
+            else if (var instanceof org.columbia.seas.cs.amsterdam.ModelFile )
+            {
+                String path = ((org.columbia.seas.cs.amsterdam.ModelFile)var).getPath();
+
+                try {
+
+                    org.columbia.seas.cs.amsterdam.ModelFile newFile
+                        = new org.columbia.seas.cs.amsterdam.ModelFile( "./tmp/branch"+offset+"/"+path);
+                    newOut.add(newFile);
+
+                } catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
             else{
                 newOut.add(var);
             }
diff --git a/org/columbia/seas/cs/amsterdam/MetaDescriptorParser.java b/org/columbia/seas/cs/amsterdam/MetaDescriptorParser.java
index 19a25ef..9a03d50 100644
--- a/org/columbia/seas/cs/amsterdam/MetaDescriptorParser.java
+++ b/org/columbia/seas/cs/amsterdam/MetaDescriptorParser.java
@@ -125,9 +125,6 @@ public class MetaDescriptorParser {
                             int number = j+1;
                             testFileContent += "\t\tSystem.out.println(\"Pre-condition:"+number+" checking failed. \"); \n\n";
                         }
-
-
-
                     }
                 }

@@ -137,23 +134,21 @@ public class MetaDescriptorParser {
                     List branches = post.getChildren("BRANCH");
                     if (!branches.isEmpty())
                     {
+                        testFileContent += "\t"+"long cpuTimePreTrans = Util.getSystemTime(); \n";
                         for (int t=0; t<branches.size(); t++)
                         {
                             Element branch = (Element)branches.get(t);
                             int num = t+1;
-                            testFileContent += "\t// code block for branch"+num+"\n";

+                            testFileContent += "\t// code block for branch"+num+"\n";


                             if (branch.getAttributeValue("OPTION").equals("main"))
                             {
-                                testFileContent += "\ttry {\n";
-                                testFileContent += "\t\tRuntime.getRuntime().exec(exec).waitFor();\n";
-                                //testFileContent += "\t\tRuntime.getRuntime().exec(\"cmd /C \"+exec);\n";

-                                testFileContent += "\t} catch(Exception e) {e.printStackTrace();}\n\n";
+                                testFileContent += "\t"+"final String mainExec="+"new String(exec);"+"\n";
                             }
-                            if (branch.getAttributeValue("OPTION").equals("sequantial"))
+                            else
                             {
                                 String operationLine = Util.processKeywordsBranch(branch.getValue(), t+1);
                                 String paramStr = "";
@@ -162,24 +157,15 @@ public class MetaDescriptorParser {
                                     paramStr = parameters.getValue();
                                     paramStr = paramStr.replaceAll("\"", "\\\\"+"\"");
                                 }
-                                testFileContent += "\t" + "Input input" + num
+                                testFileContent += "\t" + "final Input input" + num
                                                     + " = DataProcessor.clone(input,"+num+");" + "\n";
-                                testFileContent += "\t" + "String param" + num
-                                                    + " = DataProcessor.processParam(input,"+num+",\"" +paramStr+ "\");" + "\n";
-
-                                testFileContent += "\t" + "Output output" + num
+                                testFileContent += "\t" + "final Output output" + num
                                                     + " = DataProcessor.clone(output,"+ num +");" + "\n";
-                                testFileContent += "\t" + "param" + num
-                                                    + " = DataProcessor.processParam(output,"+num+",param"+num+");" + "\n";
-                                testFileContent += "\t" + operationLine + " \n";
-                                testFileContent += "\tString exec"+num+" = \""+Util.escapeChars(execution.getValue())+"\";\n";
-
-                                testFileContent += "\texec"+num+" = exec"+num+".replaceAll(\"@param\", param"+num+");\n";
-                                testFileContent += "\tSystem.out.println(\"Execution for branch"+num+": \"+exec"+num+");\n";
-
+                                testFileContent += "\t" + "final String param" + num
+                                                    + " = DataProcessor.processParam(input, output,"+num+",\"" +paramStr+ "\");" + "\n";

-                                testFileContent += "\ttry {\n";
-                                testFileContent += "\t\tRuntime.getRuntime().exec(exec"+num+").waitFor();\n";
+                                testFileContent += "\t" + operationLine + " \n";
+                                testFileContent += "\t"+"final String exec"+num+" = \""+Util.escapeChars(execution.getValue())+"\""+".replaceAll(\"@param\", param"+num+");\n";
                                 //testFileContent += "\t\tRuntime.getRuntime().exec(\"cmd /C \"+exec"+num+");\n";
                                 /*testFileContent += "\t\tOutput output" + num + " = new Output();\n";

@@ -195,16 +181,62 @@ public class MetaDescriptorParser {
                                     }
                                 }*/

+                            }
+
+                        }
+                        testFileContent += "\t"+"long cpuTimeCostTrans = Util.getSystemTime()-cpuTimePreTrans; \n";
+                        testFileContent += "\t"+"System.out.println(\"CPU time cost for sandboxing: \"+cpuTimeCostTrans+\" nanosec\"); \n";
+                        for (int t=0; t<branches.size(); t++)
+                        {
+                            Element branch = (Element)branches.get(t);
+                            int num = t+1;
+
+                            testFileContent += "\t// code block for branch"+num+"\n";
+
+
+                            if (branch.getAttributeValue("OPTION").equals("main"))
+                            {
+                                testFileContent += "\t" + "new Thread(new Runnable() {\n";
+                                testFileContent += "\t\t" + "public void run() {\n";
+                                testFileContent += "\t\t\t" + "try {\n";
+                                testFileContent += "\t\t\t\t"+"final long cpuTimePreMain = Util.getSystemTime(); \n";
+
+                                testFileContent += "\t\t\t\t"+"Runtime.getRuntime().exec(mainExec).waitFor();\n";
+                                //testFileContent += "\t\tRuntime.getRuntime().exec(\"cmd /C \"+exec);\n";
+
+                                testFileContent += "\t\t\t\t"+"final long cpuTimeCostMain = Util.getSystemTime()-cpuTimePreMain; \n";
+                                testFileContent += "\t\t\t\t"+"System.out.println(\"CPU time cost for main branch: \"+cpuTimeCostMain+\" nanosec\"); \n";
+
+                                testFileContent += "\t\t\t" + "} catch(Exception ex) {} }\n";
+                                testFileContent += "\t\t" + "}).start();\n";
+                            }
+                            if (branch.getAttributeValue("OPTION").equals("sequential"))
+                            {
+
+
+                                testFileContent += "\t"+"System.out.println(\"Execution for branch"+num+": \"+exec"+num+");\n";
+
+
+                                testFileContent += "\t"+"try {\n";
+                                testFileContent += "\t"+"Runtime.getRuntime().exec(exec"+num+").waitFor();\n";
                                 testFileContent += "\t} catch(Exception e) {e.printStackTrace();}\n\n";
                             }
                             if (branch.getAttributeValue("OPTION").equals("para"))
                             {
-                                String operationLine = Util.processKeywords(branch.getValue());
+                                testFileContent += "\t" + "new Thread(new Runnable() {\n";
+                                testFileContent += "\t\t" + "public void run() {\n";
+                                testFileContent += "\t\t\t" + "try {\n";
+

-                                testFileContent += "\t" + operationLine + " \n";
-                                testFileContent += "\ttry {\n";
-                                testFileContent += "\t\tRuntime.getRuntime().exec(exec);\n";
-                                testFileContent += "\t} catch(Exception e) {e.printStackTrace();}\n\n";
+                                testFileContent += "\t\t\t\t"+"System.out.println(\"Execution for branch"+num+": \"+exec"+num+");\n";
+
+
+
+                                testFileContent += "\t\t\t\t"+"Runtime.getRuntime().exec(exec"+num+").waitFor();\n";
+
+                                testFileContent += "\t\t\t" + "} catch(Exception ex) {} }\n";
+                                testFileContent += "\t\t" + "}).start();\n";
+
                             }
                         }
                     }
diff --git a/org/columbia/seas/cs/amsterdam/SimpleParser.java b/org/columbia/seas/cs/amsterdam/SimpleParser.java
index 5fd5821..70c3206 100644
--- a/org/columbia/seas/cs/amsterdam/SimpleParser.java
+++ b/org/columbia/seas/cs/amsterdam/SimpleParser.java
@@ -92,7 +92,7 @@ public class SimpleParser {
                         String[] statements = line.split(" then ");

                         Element newBranch = new Element("BRANCH");
-                        newBranch.setAttribute("OPTION", "sequantial");
+                        newBranch.setAttribute("OPTION", "sequential");
                         String branchOp = statements[0];
                         branchCounter++;
                         branchOp = replaceOperators(branchOp,branchCounter);
diff --git a/org/columbia/seas/cs/amsterdam/Util.java b/org/columbia/seas/cs/amsterdam/Util.java
index 0413ba1..2b752de 100644
--- a/org/columbia/seas/cs/amsterdam/Util.java
+++ b/org/columbia/seas/cs/amsterdam/Util.java
@@ -10,6 +10,7 @@
 package org.columbia.seas.cs.amsterdam;

 import com.martiansoftware.jsap.*;
+import java.lang.management.*;

 /**
  *
@@ -28,6 +29,10 @@ public class Util {
         {
             content += "\tArffFile " + nameString + " = new ArffFile(" + value + ");\n";
         }
+        if (typeString.equals("MODEL_FILENAME"))
+        {
+            content += "\tModelFile " + nameString + " = new ModelFile(" + value + ");\n";
+        }
         if (typeString.equals("RESULT_SET"))
         {
             content += "\tResultSet " + nameString + " = " + value + ";\n";
@@ -90,4 +95,25 @@ public class Util {
         return str;
     }

+        public static long getCpuTime( ) {
+        ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
+        return bean.isCurrentThreadCpuTimeSupported( ) ?
+        bean.getCurrentThreadCpuTime( ) : 0L;
+        }
+
+    /** Get user time in nanoseconds. */
+    public static long getUserTime( ) {
+        ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
+        return bean.isCurrentThreadCpuTimeSupported( ) ?
+        bean.getCurrentThreadUserTime( ) : 0L;
+    }
+
+    /** Get system time in nanoseconds. */
+    public static long getSystemTime( ) {
+        ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
+
+        return bean.isCurrentThreadCpuTimeSupported( ) ?
+        ( bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime() ) : 0L;
+    }
+
 }
diff --git a/test/naivebayestest.java b/test/naivebayestest.java
index a4babe1..905e459 100644
--- a/test/naivebayestest.java
+++ b/test/naivebayestest.java
@@ -1,13 +1,14 @@
 package test;
 import org.columbia.seas.cs.amsterdam.*;
+import java.util.*;
 //import weka.core.converters.*;

 public class naivebayestest
 {
  public static void main(String[] args)
 {
-	String[] param = {"","-t","trainingData.arff","-l","testingData.arff","-d","outputData.arff"};
-	String exec = "java -cp .\\lib\\JSAP-2.1.jar;.\\lib\\jdom.jar;.\\lib\\weka.jar;. NaiveBayesUpdatableTest -t \"trainingData.arff\" -l \"testingData.arff\" -d \"outputData.arff\"";
+	String[] param = {"","-t","iris.arff","-l","irisTest.arff","-d","outputData.arff"};
+	String exec = "java -cp .\\lib\\JSAP-2.1.jar;.\\lib\\jdom.jar;.\\lib\\weka.jar;. NaiveBayesUpdatableTest -t \"iris.arff\" -l \"irisTest.arff\" -d \"outputData.arff\"";

 	Input input = new Input();
 	ArffFile inputVar1 = new ArffFile(param[2]);
@@ -26,37 +27,50 @@ public class naivebayestest
 	if (! (DataProcessor.numAttributes(input.var(1)) == DataProcessor.numAttributes(output.var(1))) )
 		System.out.println("Pre-condition:2 checking failed. ");

+	long cpuTimePreTrans = new Date().getTime();
 	// code block for branch1
-	try {
-		Runtime.getRuntime().exec(exec).waitFor();
-	} catch(Exception e) {e.printStackTrace();}
-
+	final String mainExec=new String(exec);
 	// code block for branch2
-	Input input2 = DataProcessor.clone(input,2);
-	String param2 = DataProcessor.processParam(input,2,"-t \"trainingData.arff\" -l \"testingData.arff\" -d \"outputData.arff\"");
-	Output output2 = DataProcessor.clone(output,2);
-	param2 = DataProcessor.processParam(output,2,param2);
+	final Input input2 = DataProcessor.clone(input,2);
+	final Output output2 = DataProcessor.clone(output,2);
+	final String param2 = DataProcessor.processParam(input, output,2,"-t \"iris.arff\" -l \"irisTest.arff\" -d \"outputData.arff\"");
 	 DataProcessor.permute(input2.var(1));
-	String exec2 = "java -cp .\\lib\\JSAP-2.1.jar;.\\lib\\jdom.jar;.\\lib\\weka.jar;. NaiveBayesUpdatableTest @param";
-	exec2 = exec2.replaceAll("@param", param2);
-	System.out.println("Execution for branch2: "+exec2);
-	try {
-		Runtime.getRuntime().exec(exec2).waitFor();
-	} catch(Exception e) {e.printStackTrace();}
-
+	final String exec2 = "java -cp .\\lib\\JSAP-2.1.jar;.\\lib\\jdom.jar;.\\lib\\weka.jar;. NaiveBayesUpdatableTest @param".replaceAll("@param", param2);
 	// code block for branch3
-	Input input3 = DataProcessor.clone(input,3);
-	String param3 = DataProcessor.processParam(input,3,"-t \"trainingData.arff\" -l \"testingData.arff\" -d \"outputData.arff\"");
-	Output output3 = DataProcessor.clone(output,3);
-	param3 = DataProcessor.processParam(output,3,param3);
+	final Input input3 = DataProcessor.clone(input,3);
+	final Output output3 = DataProcessor.clone(output,3);
+	final String param3 = DataProcessor.processParam(input, output,3,"-t \"iris.arff\" -l \"irisTest.arff\" -d \"outputData.arff\"");
 	 DataProcessor.inverse(input3.var(2));
-	String exec3 = "java -cp .\\lib\\JSAP-2.1.jar;.\\lib\\jdom.jar;.\\lib\\weka.jar;. NaiveBayesUpdatableTest @param";
-	exec3 = exec3.replaceAll("@param", param3);
-	System.out.println("Execution for branch3: "+exec3);
-	try {
-		Runtime.getRuntime().exec(exec3).waitFor();
-	} catch(Exception e) {e.printStackTrace();}
-
+	final String exec3 = "java -cp .\\lib\\JSAP-2.1.jar;.\\lib\\jdom.jar;.\\lib\\weka.jar;. NaiveBayesUpdatableTest @param".replaceAll("@param", param3);
+	final long cpuTimeCostTrans = new Date().getTime()-cpuTimePreTrans;
+
+	// code block for branch1
+	new Thread(new Runnable() {
+		public void run() {
+			try {
+				final long cpuTimePreMain = new Date().getTime();
+				Runtime.getRuntime().exec(mainExec).waitFor();
+				final long cpuTimeCostMain = new Date().getTime()-cpuTimePreMain;
+                                System.out.println("CPU time cost for sandboxing: "+cpuTimeCostTrans+" nanosec");
+				System.out.println("CPU time cost for main branch: "+cpuTimeCostMain+" nanosec");
+			} catch(Exception ex) {} }
+		}).start();
+	// code block for branch2
+	/*new Thread(new Runnable() {
+		public void run() {
+			try {
+				System.out.println("Execution for branch2: "+exec2);
+				Runtime.getRuntime().exec(exec2).waitFor();
+			} catch(Exception ex) {} }
+		}).start();
+	// code block for branch3
+	new Thread(new Runnable() {
+		public void run() {
+			try {
+				System.out.println("Execution for branch3: "+exec3);
+				Runtime.getRuntime().exec(exec3).waitFor();
+			} catch(Exception ex) {} }
+		}).start();*/
 	if (!(DataProcessor.equal( output, output2)) )
 		System.out.println("Post-condition:1 checking failed. ");
 	else