MCMC Order Search

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

Re: MCMC Order Search

Postby vlee14 » Wed Jan 28, 2015 3:12 pm

Code: Select all
do
   {
      for(std::size_t i = 0; i < max_iterations; ++i)
      {
         std::vector<int> swapped_order = bnl::random_swap_order(top_order);
         double swapped_score = bnl::log_score(swapped_order, ds, local);
         double order_ratio = exp(swapped_score - original_score);
         double min = std::min(1.0, order_ratio);
         
         
         if(min == order_ratio)
         {
            if(bnl::random::random_int(0,1) < order_ratio)
            {   
               top_order.clear();
               top_score = 0.0;
               top_order = swapped_order;
               top_score = swapped_score;
            }
         }
         total_score += swapped_score;
         std::cout << swapped_score << '\n';
         swapped_score = 0.0;
         swapped_order.clear();
         order_ratio = 0.0;
         min = 1.0;
         system_time += get_wall_time();
      }
   }
   while(system_time < max_time);


This error continues to occur: *** Error in `./output': double free or corruption (out): 0x00000000025730c0 ***
I made some modifications and improved the likelihood of the program running successfully but cannot successfully run the program multiple times without that error occuring at least once.
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: MCMC Order Search

Postby cwyoo » Wed Jan 28, 2015 7:00 pm

vlee14 wrote:
Code: Select all
do
   {
      for(std::size_t i = 0; i < max_iterations; ++i)
      {
         std::vector<int> swapped_order = bnl::random_swap_order(top_order);
         double swapped_score = bnl::log_score(swapped_order, ds, local);
         double order_ratio = exp(swapped_score - original_score);
         double min = std::min(1.0, order_ratio);
         
         
         if(min == order_ratio)
         {
            if(bnl::random::random_int(0,1) < order_ratio)
            {   
               top_order.clear();
               top_score = 0.0;
               top_order = swapped_order;
               top_score = swapped_score;
            }
         }
         total_score += swapped_score;
         std::cout << swapped_score << '\n';
         swapped_score = 0.0;
         swapped_order.clear();
         order_ratio = 0.0;
         min = 1.0;
         system_time += get_wall_time();
      }
   }
   while(system_time < max_time);


This error continues to occur: *** Error in `./output': double free or corruption (out): 0x00000000025730c0 ***
I made some modifications and improved the likelihood of the program running successfully but cannot successfully run the program multiple times without that error occuring at least once.


Please use a reference or pointer for the parameter to swap the member in a vector in the module in random_swap.cpp

std::vector<int> random_swap_order(std::vector<int> od)

e.g., if you are using reference (recommended), you should use:

std::vector<int> random_swap_order(std::vector<int> & od)

Please read about how to use reference in C++
cwyoo
Site Admin
 
Posts: 379
Joined: Sun Jun 22, 2014 2:38 pm

Re: MCMC Order Search

Postby vlee14 » Wed Jan 28, 2015 7:31 pm

I used bnl::random_swap_order( std::vector<int>& top_order) as a reference and still produced the same error.
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: MCMC Order Search

Postby cwyoo » Wed Jan 28, 2015 8:45 pm

vlee14 wrote:I used bnl::random_swap_order( std::vector<int>& top_order) as a reference and still produced the same error.


When you are using reference, you do not return the object. Your module should just be:

int random_swap_order(std::vector<int>& od, std::vector<int>& swapped_od)

return 0 if there were errors, return 1 if there were no errors.

In the main code instead of

std::vector<int> swapped_order = bnl::random_swap_order(top_order);

you should code it as:

std::vector<int> swapped_order;
if(!bnl::random_swap_order(top_order, swapped_order)) {
//error handle
}
cwyoo
Site Admin
 
Posts: 379
Joined: Sun Jun 22, 2014 2:38 pm

Re: MCMC Order Search

Postby vlee14 » Thu Jan 29, 2015 4:48 pm

Followed your suggestions still gettting errors: undefined reference to `bnl::random_swap_order(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >&)'.
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: MCMC Order Search

Postby cwyoo » Fri Jan 30, 2015 7:32 am

vlee14 wrote:Followed your suggestions still gettting errors: undefined reference to `bnl::random_swap_order(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >&)'.


Please make sure the subprogram prototype (in the header) matches the actual usage in the code.
cwyoo
Site Admin
 
Posts: 379
Joined: Sun Jun 22, 2014 2:38 pm

Re: MCMC Order Search

Postby vlee14 » Fri Jan 30, 2015 11:45 am

I'm not exactly sure what you mean.
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: MCMC Order Search

Postby vlee14 » Fri Jan 30, 2015 12:01 pm

I was able to fix the compilation errors regardless. However, I ended up with a runtime error saying : terminate called after throwing an instance of 'bnl::match_error'
what(): Match Error: The total order and dataset do not match.
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: MCMC Order Search

Postby vlee14 » Wed Feb 04, 2015 8:43 pm

I was able to organize the Tree module and fix majority of the long list of errors in the code. The code should compile by tomorrow morning.
vlee14
 
Posts: 38
Joined: Wed Sep 24, 2014 4:53 pm

Re: MCMC Order Search

Postby cwyoo » Thu Feb 05, 2015 6:56 am

vlee14 wrote:I was able to organize the Tree module and fix majority of the long list of errors in the code. The code should compile by tomorrow morning.


Great. I will ask you to move the Tree structure code discussion to the tree structure forum under Implementation.
cwyoo
Site Admin
 
Posts: 379
Joined: Sun Jun 22, 2014 2:38 pm

PreviousNext

Return to Ordering Search of Structures in Bayesian Networks

Who is online

Users browsing this forum: No registered users and 3 guests