Beispiel #1
0
int main(int argc, char const *argv[])
{
    std::string FILE="/homes/kgori/scratch/basic_pll/GGPS1.phy";
    std::string PART="/homes/kgori/scratch/basic_pll/GGPS1.partitions.txt";
    std::string TREE="/homes/kgori/scratch/basic_pll/GGPS1.tree";

    auto inst = make_unique<pll>(FILE, PART, TREE, 1, 123);
    std::cout << inst->get_likelihood() << std::endl;
    std::cout << inst->get_partition_name(0) << std::endl;
    std::cout << inst->get_model_name(0) << std::endl;
    std::cout << inst->get_epsilon() << std::endl;
    std::cout << inst->get_alpha(0) << std::endl;
    std::cout << inst->get_number_of_partitions() << std::endl;
    std::cout << inst->get_tree() << std::endl;
    std::cout << inst->get_frac_change() << std::endl;
    inst->set_tree("((Ptro:0.00147084048849247711,Ppan:0.00106294370976534763):0.00444598321816729036,(Cjac:0.05157798212603657839,(Csab:0.00440006365327790666,(Mmul:0.00652936575529242547,Panu:0.00101047194512476272):0.00381049900890796569):0.01359968787254225639):0.01375788728353777995,Hsap:0.00674547067186638278):0.0;");
    inst->set_epsilon(0.001);
    inst->set_alpha(2, 0, true);
    auto ef = inst->get_empirical_frequencies();

    inst->optimise(true, true, true, true);
    inst->optimise_tree_search(true);
    std::cout << inst->get_likelihood() << std::endl;
    std::cout << inst->get_tree() << std::endl;
    return 0;
}
Beispiel #2
0
  void update_delta(const Expression& gradient, int index) {

    if (index >= _delta.size() || index >= _d2.size() || index >= _delta2.size()) {
      _delta.resize(index + 1);
      _delta2.resize(index + 1);
      _d2.resize(index + 1);
    }

    if (!_delta[index] || !_delta2[index] || !_d2[index]) {
      _delta[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _delta2[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _d2[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
    }

    // Perform adadelta updates
    *_d2[index] = get_decay_rate() * *_d2[index] + (1.0 - get_decay_rate()) * reshape(gradient, _d2[index]->size()) * reshape(gradient, _d2[index]->size());
    *_delta[index] = -sqrt(*_delta2[index] + get_epsilon()) / sqrt(*_d2[index] + get_epsilon()) * reshape(gradient, _d2[index]->size());
    *_delta2[index] = get_decay_rate() * *_delta2[index] + (1.0 - get_decay_rate()) * *_delta[index] * *_delta[index];
  }
  double MultivariateFNormalSufficient::get_mean_square_residuals() const
{
    //std::cout << "P " << std::endl << P_ << std::endl;
    //std::cout << "epsilon " << std::endl << get_epsilon() << std::endl;
    VectorXd Peps(get_Peps());
    VectorXd epsilon(get_epsilon());
    double dist = epsilon.transpose()*Peps;
    LOG( "MVN:   get_mean_square_residuals = " << dist << std::endl);
    return dist;
}
VectorXd MultivariateFNormalSufficient::get_Peps() const
{
    if (!flag_Peps_)
    {
        ////Peps
        LOG( "MVN:   solving for P*epsilon" << std::endl);
        const_cast<MultivariateFNormalSufficient *>(this)
            ->set_Peps(get_ldlt().solve(get_epsilon()));
    }
    return Peps_;
}
Beispiel #5
0
double __declspec(dllexport) WINAPI _get_epsilon(lprec *lp)
 {
  double ret;

  if (lp != NULL) {
   freebuferror();
   ret = (double) get_epsilon(lp);
  }
  else
   ret = 0;
  return(ret);
 }
VectorXd MultivariateFNormalSufficient::get_Peps() const
{
    if (!flag_Peps_)
    {
        ////Peps
        timer_.start(SOLVE);
        IMP_LOG(TERSE, "MVN:   solving for P*epsilon" << std::endl);
        const_cast<MultivariateFNormalSufficient *>(this)
            ->set_Peps(get_ldlt().solve(get_epsilon()));
        timer_.stop(SOLVE);
    }
    return Peps_;
}
Beispiel #7
0
  void update_delta(const Expression& gradient, int index) {

    if (index >= _delta.size()) {
      _delta.resize(index + 1);
    }

    if (!_delta[index]) {
      _delta[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
    }

    // Block-wise normalize the gradient
    vector_t norm_grad = reshape(gradient, _delta[index]->size()) / (sqrt(dot(reshape(gradient, _delta[index]->size()), reshape(gradient, _delta[index]->size()))) + get_epsilon());

    // Calculate running averages
    mg = get_decay_rate() * mg + (1.0 - get_decay_rate()) * norm_grad;

    gamma_nume_sqr = gamma_nume_sqr * (1 - 1 / taus_x_t) + (norm_grad - old_grad) * (old_grad - mg) * (norm_grad - old_grad) * (old_grad - mg) / taus_x_t;
    gamma_deno_sqr = gamma_dneo_sqr * (1 - 1 / taus_x_t) + (mg - norm_grad) * (old_grad - mg) * (mg - norm_grad) * (old_grad - mg) / taus_x_t;
    _gamma = sqrt(_gamma_nume) / (sqrt(_gamma_deno_sqr) + get_epsilon());

    // Update delta with momentum and epsilon parameter
    *_delta[index] =  _gamma * mg;
  }
Beispiel #8
0
  void update_delta(const Expression& gradient, int index) {

    if (index >= _delta.size() || index >= _old_grad.size() || index >= _g.size() || index >= _g2.size() ||
        index >= _h.size() || index >= _h2.size() || index >= _tau.size() || index >= _current_iteration.size())
    {
      _delta.resize(index + 1);
      _old_grad.resize(index + 1);
      _g.resize(index + 1);
      _g2.resize(index + 1);
      _h.resize(index + 1);
      _h2.resize(index + 1);
      _tau.resize(index + 1);
      _current_iteration.resize(index + 1);
    }

    if (!_delta[index] || !_old_grad[index] || !_g[index] || !_g2[index] || !_h[index] || !_h2[index] || !_tau[index]) {
      _delta[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _old_grad[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _g[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _g2[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _h[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _h2[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _tau[index] = boost::make_shared<vector_t>(ones<value_t>(gradient.count()));
      _current_iteration[index] = 0;
    }

    ++_current_iteration[index];

    // Detect outlier
//    if (abs(reshape(gradient, _delta[index]->size()) - *_g[index]) > 2 * sqrt(*_g2[index] - *_g[index] * *_g[index]) ||
//        abs(abs((reshape(gradient, _delta[index]->size()) - *_old_grad[index]) / (*_delta[index] + get_epsilon())) - *_h[index]) > 2 * sqrt(*_h2[index] - *_h[index] * *_h[index]))
//    {
//      *_tau[index] = *_tau[index] + 1.0;
//    }

    *_tau[index] = *_tau[index] + abs(reshape(gradient, _delta[index]->size()) - *_g[index]) > 2 * sqrt(*_g2[index] - *_g[index] * *_g[index]);

    // Update moving averages
    *_g[index]  = (1.0 - 1.0 / *_tau[index]) * *_g[index]  + 1.0 / *_tau[index] * reshape(gradient, _delta[index]->size());
    *_g2[index] = (1.0 - 1.0 / *_tau[index]) * *_g2[index] + 1.0 / *_tau[index] * reshape(gradient, _delta[index]->size()) * reshape(gradient, _delta[index]->size());

    if (_current_iteration[index] > 1) {
      // Calculate h and do h updates
      // diag(H) = abs((reshape(gradient, _delta[index]->size()) - *_old_grad[index]) / (*_delta[index] + get_epsilon()));

      *_h[index]  = (1.0 - 1.0 / *_tau[index]) * *_h[index]  + 1.0 / *_tau[index] * abs((reshape(gradient, _delta[index]->size()) - *_old_grad[index]) / (*_delta[index] + get_epsilon()));
      *_h2[index]  = (1.0 - 1.0 / *_tau[index]) * *_h[index]  + 1.0 / *_tau[index] * ((reshape(gradient, _delta[index]->size()) - *_old_grad[index]) / (*_delta[index] + get_epsilon())) * ((reshape(gradient, _delta[index]->size()) - *_old_grad[index]) / (*_delta[index] + get_epsilon()));

      // Initialization phase -> multiply with C where C = D/10
      if (_current_iteration[index] == 2) {
        *_g2[index] = *_g2[index] * get_c();
        *_h[index] = *_h[index] * get_c();
        *_h2[index] = *_h2[index] * get_c();
      }

      *_delta[index] = -*_h[index] * *_g[index] * *_g[index] / (*_h2[index] * *_g2[index] + get_epsilon()) * reshape(gradient, _delta[index]->size());
    } else {
      *_delta[index] = get_epsilon() * *_g[index];
    }

    *_tau[index] = (1.0 - *_g[index] * *_g[index] / (*_g2[index] + get_epsilon())) * *_tau[index] + 1;

    *_old_grad[index] = reshape(gradient, _delta[index]->size());
  }
Beispiel #9
0
  void update_delta(const Expression& gradient, int index) {

    if (index >= _delta.size() || index >= _first_moment.size() || index >= _second_moment.size() || index >= _current_iteration.size()) {
      _delta.resize(index + 1);
      _first_moment.resize(index + 1);
      _second_moment.resize(index + 1);
      _current_iteration.resize(index + 1);
    }

    if (!_delta[index] || !_first_moment[index] || !_second_moment[index]) {
      _delta[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _first_moment[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _second_moment[index] = boost::make_shared<vector_t>(zeros<value_t>(gradient.count()));
      _current_iteration[index] = 0;
    }

    ++_current_iteration[index];

    // Perform adadelta updates
    *_first_moment[index] = get_beta1() * reshape(gradient, _delta[index]->size()) + (1.0 - get_beta1()) * *_first_moment[index];
    *_second_moment[index] = get_beta2() * reshape(gradient, _delta[index]->size()) * reshape(gradient, _delta[index]->size()) + (1.0 - get_beta2()) * *_second_moment[index];

    *_delta[index] = -get_alpha() * *_first_moment[index] / (value_t(1) - ::pow(value_t(1) - get_beta1(), _current_iteration[index])) /
        (sqrt(*_second_moment[index] / (value_t(1) - ::pow(value_t(1) - get_beta2(), _current_iteration[index]))) + get_epsilon());
  }