Page 1 of 1

Random Order using dataset

PostPosted: Mon Jan 05, 2015 3:57 pm
by vlee14
::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';
}
}

Re: Random Order using dataset

PostPosted: Mon Jan 05, 2015 5:02 pm
by cwyoo
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.

Re: Random Order using dataset

PostPosted: Tue Jan 06, 2015 3:47 pm
by vlee14
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)
}

Re: Random Order using dataset

PostPosted: Tue Jan 06, 2015 6:57 pm
by cwyoo
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.

Re: Random Order using dataset

PostPosted: Thu Jan 08, 2015 12:24 pm
by vlee14
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

Re: Random Order using dataset

PostPosted: Tue Jan 13, 2015 3:58 pm
by vlee14
Started the order search code in main.cpp.

Re: Random Order using dataset

PostPosted: Wed Jan 14, 2015 3:56 pm
by vlee14
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.