Exemplo n.º 1
0
void Chain_Factorial::update_x_BlockGibbs(){
  if(nrows_gibbs == K){
    // forward step
    FHMM_forward_step(pi, A, emission_probs, P_FHMM, loglik_marginal, k_restricted, n, x, restricted_space);
    
    // now backward sampling
    FHMM_backward_sampling(x, P_FHMM, k_restricted, n, restricted_space);
    
  } else{
    for(int i=0; i<all_combinations.ncol(); i++){
      // Restrict the state space to block Gibbs updates
      IntegerVector which_rows_fixed = all_combinations(_, i);
      //IntegerVector which_rows_fixed = sample_helper(K, K-nrows_gibbs);
      restricted_space = construct_all_restricted_space(k_restricted, which_rows_fixed, mapping);
      // forward step
      FHMM_forward_step(pi, A, emission_probs, P_FHMM, loglik_marginal, k_restricted, n, x, restricted_space);
      
      // now backward sampling
      FHMM_backward_sampling(x, P_FHMM, k_restricted, n, restricted_space);
    }
    
  }
  // conditional loglikelihood
  loglik_cond = loglikelihood(x, emission_probs, n);
  
  convert_x_to_X();
}
Exemplo n.º 2
0
void HLFscheduler::get_initial_schedule(const Intree& t,
        vector<vector<task_id>>& target) const {
    // fetch all tasks, and sort them according to their level
    vector<task_id> tasks = t.get_tasks();
    vector<task_id> tmp;
    for(auto const& it : tasks){
        if(t.get_in_degree(it) == 0)
            tmp.push_back(it);
    }
    sort(tmp.begin(), tmp.end(),
        [&t](const task_id& a, const task_id& b) -> bool {
            return t.get_level(a) > t.get_level(b);
        }
        ); 
    // compute possible combinations
    vector<vector<task_id>> combos;
    vector<task_id> dummy;
    vector<unsigned int> referencelevels;
    unsigned int numtasks = tmp.size();
    unsigned int actualprocs = min(processorcount, numtasks);
    for(unsigned int i=0; i<actualprocs; ++i){
        referencelevels.push_back(t.get_level(tmp[i]));
    }
    all_combinations(tmp, actualprocs, -1, t, referencelevels, dummy, combos);
    for(auto const& it : combos){
        target.push_back(it);
    }
}
Exemplo n.º 3
0
Arquivo: pearson.c Projeto: jjg/unstor
int main(int argc, char *argv[]){

  int total_hash_time = 0;
  int total_generate_time = 0;

  // generate a hash of the supplied string
  char output_hash[8];
  size_t output_len = 8;

  Pearson16(argv[1], strlen(argv[1]), output_hash, output_len);

  printf("Original input hash: %s\n", output_hash);

  printf("Thinking...\n");
  int start_time = time(NULL);

  // loop through all possible input data to find 
  // data that returns a matching hash and track how
  // long this takes
  const int maxlen = strlen(argv[1]);
  char match[maxlen];
  char x[maxlen+1];
  for(int thislen=1; thislen <= maxlen; thislen++){
    x[thislen] = 0;
    all_combinations(x, thislen-1, output_hash, match);
  }

  int end_time = time(NULL);

  printf("\nReconstituted original input: %s\n", match);
  printf("Elapsed time: %ds\n", end_time - start_time);
  return 0;
}
Exemplo n.º 4
0
void HLFscheduler::all_combinations(vector<task_id> nums, 
        unsigned int n, 
        unsigned int minindex,
        const Intree& t,
        const vector<unsigned int>& referencelevels,
        vector<task_id>& current,
        vector<vector<task_id>>& target) const {
    if(n==0){
        for(unsigned int i=0; i<current.size(); ++i){
            if(t.get_level(current[i]) != referencelevels[i])
                return;
            if(t.get_in_degree(current[i]) > 0)
                return;
        }
        target.push_back(current);
        return;
    }
    if(nums.size() - minindex <= n)
        return;
    for(unsigned int i=minindex+1; i<nums.size(); ++i){
        vector<task_id> newcombo(current);
        newcombo.push_back(nums[i]);
        all_combinations(nums,
            n-1,
            i,
            t,
            referencelevels,
            newcombo,
            target);
    }
}
Exemplo n.º 5
0
Arquivo: pearson.c Projeto: jjg/unstor
void all_combinations(char* x, const int len, char* target_hash, char* match)
{
  for (char c = 97; c < 122; ++c){
    x[len] = c;
    if(len>0){
        all_combinations(x, len - 1, target_hash, match );
    } else {
      //printf("\t%d\n", strncmp(x, target_hash, strlen(target_hash)));

      // test input candidate
      char test_hash[8];
      size_t test_hash_len = 8;
      Pearson16(x, strlen(x), test_hash, test_hash_len);

      if(strncmp(test_hash, target_hash, strlen(test_hash)) == 0){
        strcpy(match, x);
      }
    }
  }
}