Skip to content

Commit

Permalink
Merge branch '2023_project_test' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
parmisnaddaf authored Mar 11, 2024
2 parents b1ccb32 + 3b4aa5e commit caffa88
Show file tree
Hide file tree
Showing 80 changed files with 4,799 additions and 866 deletions.
Binary file added code/common/target/common-1.0-SNAPSHOT 2.jar
Binary file not shown.
Binary file added code/common/target/common-1.0-SNAPSHOT.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions code/common/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=common
groupId=ca.sfu.cs
version=1.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca/sfu/cs/common/Configuration/Config.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca/sfu/cs/common/Configuration/Config.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/parmis/Desktop/FactorBase/code/common/src/main/java/ca/sfu/cs/common/Configuration/Config.java
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions code/componentsrunner/target/maven-archiver/pom 2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=componentsrunner
groupId=ca.sfu.cs
version=1.0-SNAPSHOT
3 changes: 3 additions & 0 deletions code/componentsrunner/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=componentsrunner
groupId=ca.sfu.cs
version=1.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca/sfu/cs/componentsrunner/app/RunComponent.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca/sfu/cs/componentsrunner/app/RunComponent.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/parmis/Desktop/FactorBase/code/componentsrunner/src/main/java/ca/sfu/cs/componentsrunner/app/RunComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/parmis/Desktop/FactorBase/code/componentsrunner/src/main/java/ca/sfu/cs/componentsrunner/app/RunComponent.java
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ public static void main(
databaseCollation,
countingStrategy
);

RuntimeLogger.logRunTime(logger, "Running BayesBaseH", bayesBaseHStart, System.currentTimeMillis());

// Now eliminate temporary tables. Keep only the tables for the longest Rchain. Turn this off for debugging.
long cleanupStart = System.currentTimeMillis();
factorBaseDatabase.cleanupDatabase();

//factorBaseDatabase.cleanupDatabase();
RuntimeLogger.logRunTime(logger, "Cleanup Database", cleanupStart, System.currentTimeMillis());

// Disconnect from the database.
Expand Down
197 changes: 174 additions & 23 deletions code/factorbase/src/main/java/ca/sfu/cs/factorbase/learning/CP.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringJoiner;
import java.util.logging.Logger;
Expand Down Expand Up @@ -191,6 +192,30 @@ public static void prepare(String rchain, Connection con1) throws SQLException {
" FROM Path_BayesNets as FamilyRNodes, FNodes as RNode_check " +
" where FamilyRNodes.Rchain = '" + rchain + "' and RNode_check.Fid = FamilyRNodes.parent and RNode_check.Type = 'RNode';"
);
// pnaddaf Dec 5ht 2023
st.execute("drop view if exists RNodes_inFamily_view;");
st.execute(
"CREATE VIEW RNodes_inFamily_view AS " +
"SELECT distinct child, rnid, short_rnid " +
"from `Final_Path_BayesNets_view` `BN`, `RNodes`, lattice_mapping lm " +
"where `RNodes`.`rnid` = `BN`.`parent` AND lm.orig_rnid = BN.parent " +
"union " +
"select distinct `BN`.`child` AS `child`, `RNodes`.`rnid` AS rnid, short_rnid " +
"from `Final_Path_BayesNets_view` `BN`, `RNodes`, lattice_mapping lm " +
"where `RNodes`.`rnid` = `BN`.`child` AND lm.orig_rnid = child " +
"union " +
"select distinct `BN`.`child` AS `child`, `RNodes_2Nodes`.`rnid` AS `Rnid`,short_rnid " +
"from (`Final_Path_BayesNets_view` `BN`, lattice_mapping lm " +
"join `RNodes_2Nodes`) " +
"where `RNodes_2Nodes`.`2nid` = `BN`.`parent` and `RNodes_2Nodes`.`rnid`=lm.orig_rnid " +
"union " +
"select distinct `BN`.`child` AS `child`, `RNodes_2Nodes`.`rnid` AS `Rnid`, short_rnid " +
"from (`Final_Path_BayesNets_view` `BN`, lattice_mapping lm " +
"join `RNodes_2Nodes`) " +
"where `RNodes_2Nodes`.`2nid` = `BN`.`child` and `RNodes_2Nodes`.`rnid` = lm.orig_rnid ; "
);



st.execute("drop table if exists 2Nodes_inFamily;");
st.execute(
Expand Down Expand Up @@ -285,24 +310,83 @@ public static void nopar(String rchain, Connection con1) throws SQLException {
logger.fine("noparent node: " + rst.getString(1));
noparent_tables.add(rst.getString(1));
}
// zqian Nov 13, computing sum(mult) from biggest CT table
// and close the connections
java.sql.Statement st2 = con1.createStatement();
String sql2 =
"SELECT SUM(MULT) " +
"FROM " + databaseName2 + ".`" + bigTable + "`;"; // Only need to do this query once, Nov 12 zqian.
logger.fine(sql2 + "\n");
ResultSet deno = st2.executeQuery(sql2);
deno.absolute(1);
double mydeno = deno.getDouble(1);
logger.fine("SUM(mult) in bigCTTable : "+mydeno + "\n");
for(int i = 0; i < noparent_tables.size(); i++) {
// pnaddaf Dec 5th 2023
for (int i = 0; i < noparent_tables.size(); i++) {
ResultSet rst_short_rnids = st.executeQuery("SELECT short_rnid FROM RNodes_inFamily_view where child = '" + noparent_tables.get(i) + "' ORDER BY short_rnid;");
logger.fine("*************************************************");
logger.fine("SELECT short_rnid FROM RNodes_inFamily_view where child = '" + noparent_tables.get(i) + "';");
// Initialize a StringBuilder to concatenate the elements
StringBuilder concatenated_rnids = new StringBuilder();
boolean isFirst = true;
if (rst_short_rnids.next()) {
do{
// Add a comma if it's not the first value
if (!isFirst) {
concatenated_rnids.append(",");
} else {
isFirst = false;
}
// Retrieve data from the result set
String short_rnid = rst_short_rnids.getString("short_rnid");

// Append the value to the StringBuilder
concatenated_rnids.append(short_rnid);

} while(rst_short_rnids.next());

bigTable = concatenated_rnids.toString() + "_CT";
logger.fine("tableName for " + noparent_tables.get(i) + " is: " + bigTable);


} else {
// ResultSet is empty

logger.fine("ResultSet is empty");
ResultSet rst_pvid = st.executeQuery("SELECT distinct pvid FROM Pvars_Family WHERE child = '" + noparent_tables.get(i) + "' ;");
if (rst_pvid.next()) {
do {
// Add a comma if it's not the first value
if (!isFirst) {
concatenated_rnids.append(",");
} else {
isFirst = false;
}
// Retrieve data from the result set
String short_rnid = rst_pvid.getString("pvid");

// Append the value to the concatenated_rnids
concatenated_rnids.append(short_rnid);
} while (rst_pvid.next());

}
bigTable = concatenated_rnids.toString() + "_counts";
logger.fine("tableName is: " + bigTable);

// Close the ResultSet when you're done with it
rst_pvid.close();
}

// Close the ResultSet when you're done with it
rst_short_rnids.close();


// zqian Nov 13, computing sum(mult) from biggest CT table
// and close the connections
java.sql.Statement st2 = con1.createStatement();
String sql2 =
"SELECT SUM(MULT) " +
"FROM " + databaseName2 + ".`" + bigTable + "`;";
logger.fine(sql2 + "\n");
ResultSet deno = st2.executeQuery(sql2);
deno.absolute(1);
double mydeno = deno.getDouble(1);
logger.fine("SUM(mult) in bigTable : "+mydeno + "\n");
nopar_update(rchain, bigTable, noparent_tables.get(i), con1, mydeno);
}
st2.close();
}
st.close();
}

st2.close();
st.close();
}

/**
* Similar simpler computation for nodes without parents.
Expand All @@ -322,6 +406,10 @@ public static void nopar_update(String rchain, String bigTable, String nodeName,
"local_mult DECIMAL(65)" +
");"
);
logger.fine("tableName : "+ tableName + "\n");
logger.fine("nodeName : "+ nodeName + "\n");
logger.fine("databaseName2 : "+ databaseName2 + "\n");
logger.fine("bigTable : "+ bigTable + "\n");
st.execute(
"INSERT INTO `" + tableName + "` (`" + nodeName + "`) " +
"SELECT DISTINCT `" + nodeName + "` " +
Expand Down Expand Up @@ -370,13 +458,13 @@ public static void nopar_update(String rchain, String bigTable, String nodeName,
while(rs.next()) {
local = Long.parseLong (rs.getString("Tuples"));
logger.fine("local is " + local);
mynume = mynume / local;
// mynume = mynume / local; set local_mult = mult OS Dec 5, 2023
// logger.fine("set local_mult = mult, May 21, 2014 zqian ");
// set local_mult = mult, May 21, 2014 zqian
}
if (!rs.first()) {
logger.fine("local is 1, ******");
mynume = mynume / local;
// mynume = mynume / local; set local_mult = mult OS Dec 5, 2023
}
// updating the local_mult = mult / local , Dec 3rd
String sql4 =
Expand Down Expand Up @@ -460,10 +548,71 @@ public static void haspar(String rchain, Connection con1) throws SQLException {
logger.fine("hasparent node: " + rst.getString(1));
hasparent_tables.add(rst.getString(1));
}
for(int i = 0; i < hasparent_tables.size(); i++) {


// pnaddaf Dec 8th 2023
for (int i = 0; i < hasparent_tables.size(); i++) {
ResultSet rst_short_rnids = st.executeQuery("SELECT short_rnid FROM RNodes_inFamily_view where child = '" + hasparent_tables.get(i) + "' ORDER BY short_rnid ;");
logger.fine("*************************************************");
logger.fine("SELECT short_rnid FROM RNodes_inFamily_view where child = '" + hasparent_tables.get(i) + "';");
// Initialize a StringBuilder to concatenate the elements
StringBuilder concatenated_rnids = new StringBuilder();
boolean isFirst = true;
if (rst_short_rnids.next()) {
do{
// Add a comma if it's not the first value
if (!isFirst) {
concatenated_rnids.append(",");
} else {
isFirst = false;
}
// Retrieve data from the result set
String short_rnid = rst_short_rnids.getString("short_rnid");

// Append the value to the StringBuilder
concatenated_rnids.append(short_rnid);

} while(rst_short_rnids.next());

bigTable = concatenated_rnids.toString() + "_CT";
logger.fine("tableName for " + hasparent_tables.get(i) + " is: " + bigTable);


} else {
// ResultSet is empty

logger.fine("ResultSet is empty");
ResultSet rst_pvid = st.executeQuery("SELECT distinct pvid FROM Pvars_Family WHERE child = '" + hasparent_tables.get(i) + "';");
if (rst_pvid.next()) {
do {
// Add a comma if it's not the first value
if (!isFirst) {
concatenated_rnids.append(",");
} else {
isFirst = false;
}
// Retrieve data from the result set
String short_rnid = rst_pvid.getString("pvid");

// Append the value to the concatenated_rnids
concatenated_rnids.append(short_rnid);
} while (rst_pvid.next());

}
bigTable = concatenated_rnids.toString() + "_counts";
logger.fine("tableName is: " + bigTable);

// Close the ResultSet when you're done with it
rst_pvid.close();
}

// Close the ResultSet when you're done with it
rst_short_rnids.close();
haspar_update(rchain, bigTable, hasparent_tables.get(i), con1, databaseName2);


}
st.close();
st.close();
}

/**
Expand Down Expand Up @@ -573,18 +722,20 @@ public static void haspar_update(String rchain, String bigTable, String nodeName
while(rs.next()) {
local = Long.parseLong (rs.getString("Tuples"));
logger.fine("local is " + local);
String sql = "UPDATE " + escapedTableName + " SET local_mult = MULT / " + local + ";";
// String sql = "UPDATE " + escapedTableName + " SET local_mult = MULT / " + local + ";"; OS Dec 5 make local_mult = mult
String sql = "UPDATE " + escapedTableName + " SET local_mult = MULT;";
// String sql = "update " + table_name + " set local_mult = mult;";
logger.fine(sql);
// set local_mult = mult, May 21, 2014 zqian
st1.execute(sql);
}
if (!rs.first()) {
logger.fine("local is 1, ******" );
String sql = "UPDATE " + escapedTableName + " SET local_mult = MULT / " + local + ";";
String sql = "UPDATE " + escapedTableName + " SET local_mult = MULT; ";
// String sql = "UPDATE " + escapedTableName + " SET local_mult = MULT / " + local + ";"; OS Dec 5 make local_mult = mult
st1.execute(sql);
}

logger.fine("UPDATE " + escapedTableName + " SET likelihood = LOG(CP) * local_mult;");
st.execute("UPDATE " + escapedTableName + " SET likelihood = LOG(CP) * local_mult;");
st.execute("drop table if exists temp;");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,13 @@ public final void setEdgeForbidden(String var1, String var2,
throw new IllegalStateException("The edge " + var1 + "-->" + var2 +
" is required by a knowledge group. Please remove that requirement first.");
}

/*
if (edgeRequired(var1, var2)) {
throw new IllegalStateException("The edge " + var1 + "-->" +
var2 +
" is already required. Please first remove that requirement.");
}
*/

explicitlyForbiddenEdges.add(new KnowledgeEdge(var1, var2));
this.forbiddenEdges = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- Initialize the databases required by FactorBase.
SET collation_server = @dbcollation@;

SET collation_server = 'utf8_general_ci';

DROP SCHEMA IF EXISTS @database@_setup;
CREATE SCHEMA @database@_setup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
SET storage_engine=INNODB;

CREATE TABLE lattice_membership (
name VARCHAR(398),
member VARCHAR(398),
name VARCHAR(300),
member VARCHAR(300),
PRIMARY KEY(name, member)
);


CREATE TABLE lattice_rel (
parent VARCHAR(398),
child VARCHAR(398),
removed VARCHAR(199),
parent VARCHAR(300),
child VARCHAR(300),
removed VARCHAR(300),
PRIMARY KEY(parent, child)
);


CREATE TABLE lattice_set (
name VARCHAR(398),
name VARCHAR(300),
length INT(11),
PRIMARY KEY(name, length)
);


CREATE TABLE lattice_mapping (
orig_rnid VARCHAR(398),
orig_rnid VARCHAR(300),
short_rnid VARCHAR(20),
PRIMARY KEY(orig_rnid, short_rnid)
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
SET storage_engine=MEMORY;

CREATE TABLE lattice_membership (
name VARCHAR(398),
member VARCHAR(398),
name VARCHAR(300),
member VARCHAR(300),
PRIMARY KEY(name, member)
);


CREATE TABLE lattice_rel (
parent VARCHAR(398),
child VARCHAR(398),
removed VARCHAR(199),
parent VARCHAR(300),
child VARCHAR(300),
removed VARCHAR(300),
PRIMARY KEY(parent, child)
);


CREATE TABLE lattice_set (
name VARCHAR(398),
name VARCHAR(300),
length INT(11),
PRIMARY KEY(name, length)
);
Expand Down
Loading

0 comments on commit caffa88

Please sign in to comment.