Random Order using dataset

This module implements Ordering Search of Structures in Bayesian Networks from Theory & Concepts

Random Order using dataset

Postby vlee14 » Mon Jan 05, 2015 3:57 pm

::std::vector<int> refcounted_dataset::random_order() const
{
typedef ::boost::counting_iterator<int> counter;
::std::vector<int> order(counter(0), counter(dataset_.GetNumberOfVariables()));
return algorithm::random_shuffle(order);
}

bool refcounted_dataset::can_use_order(const ::std::vector<int>& order) const
{
typedef ::std::vector<int>::const_iterator const_iterator;
const int num_variables = dataset_.GetNumberOfVariables();
::std::vector<bool> visited(num_variables, false);

for (const_iterator first = order.begin(); first != order.end(); ++first)
{
const int var = *first;
if (var < 0 || var >= num_variables || visited[var])
{
return false;
}
visited[var] = true;
}
return num_variables > 0;
}

void test_order()
{
std::cout << std::setprecision(std::numeric_limits<double>::digits10);
bnl::refcounted_dataset ds("test.txt");
bnl::local_log_bdeu_score local;
std::vector<std::string> ids;
std::vector<int> order;
for (int i = 0; i < ds.data().GetNumberOfVariables(); ++i)
{
ids.push_back(ds.data().GetId(i));
order.push_back(i);
}
std::vector<std::pair<double, std::vector<int> > > results;
do
{
results.push_back(std::make_pair(bnl::log_score(order, ds, local), order));
} while (std::next_permutation(order.begin(), order.end()));

std::sort(results.begin(), results.end());
double total = bnl::math::logsumexp(results | boost::adaptors::map_keys);
for (std::size_t i = 0; i < results.size(); ++i)
{
const std::vector<int>& od = results[i].second;
std::cout << ids[od[0]];
for (unsigned j = 1; j < od.size(); ++j) std::cout << "<" << ids[od[j]];
std::cout << ": " << results[i].first << " " << std::exp(results[i].first-total) << '\n';
}
}
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: Random Order using dataset

Postby cwyoo » Mon Jan 05, 2015 5:02 pm

Please check in your codes in Git server. Here you might present pseudo-code (an upper level code, e.g., name of the methods and types of parameters it takes and what it does) and just specify the file name and location of the actual code in the Git server. Also your code should include comments (descriptions of your implementation) that will help others read your code better.
cwyoo
Site Admin
 
Posts: 379
Joined: Sun Jun 22, 2014 2:38 pm

Re: Random Order using dataset

Postby vlee14 » Tue Jan 06, 2015 3:47 pm

Updated Code
random_order()
{
dataset_.GetNumberOfVariables()
return algorithm::random_shuffle(order)
}
can_use_order
{
for (const_iterator first = order.begin(); first != order.end(); ++first)
}
make_random_network
{
prepare_structure
randomize_order
randomize_arcs
}
match_network_to_order
{

}
print_network
{
bn.write_file("output.dot")
}
print_order
{
for (int i = 0; i < ds.data().GetNumberOfVariables(); ++i
for (std::size_t i = 0; i < results.size(); ++i)
}
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: Random Order using dataset

Postby cwyoo » Tue Jan 06, 2015 6:57 pm

You need to score the structure and print its log score as well. I suggest you complete this code and make it run by tomorrow. After presenting me with the working program, we will discuss how you will implement the ordering score.
cwyoo
Site Admin
 
Posts: 379
Joined: Sun Jun 22, 2014 2:38 pm

Re: Random Order using dataset

Postby vlee14 » Thu Jan 08, 2015 12:24 pm

main
{
dataset ds
bayesian_network bn
ds.random_order()
bn.make_random_network(ds, true, 3, true)
bn.write_file("output.dot")
print_order()
}

main method pseudocode
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: Random Order using dataset

Postby vlee14 » Tue Jan 13, 2015 3:58 pm

Started the order search code in main.cpp.
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: Random Order using dataset

Postby vlee14 » Wed Jan 14, 2015 3:56 pm

Order Score code has been tested with the datasets provided. Modifications were taken place. Modified code presents no errors and seems to be working correctly.
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm


Return to Ordering Search of Structures in Bayesian Networks

Who is online

Users browsing this forum: No registered users and 1 guest