Exemplo n.º 1
0
void database_entity::reshape(std::vector<int> const& new_dims)
{
    LMI_ASSERT(e_number_of_axes == new_dims.size());
    LMI_ASSERT(1 == new_dims[0] || e_max_dim_gender    == new_dims[0]);
    LMI_ASSERT(1 == new_dims[1] || e_max_dim_uw_class  == new_dims[1]);
    LMI_ASSERT(1 == new_dims[2] || e_max_dim_smoking   == new_dims[2]);
    LMI_ASSERT(1 == new_dims[3] || e_max_dim_issue_age == new_dims[3]);
    LMI_ASSERT(1 == new_dims[4] || e_max_dim_uw_basis  == new_dims[4]);
    LMI_ASSERT(1 == new_dims[5] || e_max_dim_state     == new_dims[5]);
    LMI_ASSERT(1 <= new_dims[6] && new_dims[6] <= e_max_dim_duration);

    // Number of times we'll go through the assignment loop.
    int n_iter = getndata(new_dims);

    // Create a new instance of this class having the same key but the
    // desired dimensions, for convenient use of operator[]().
    std::vector<double> new_data(n_iter);
    database_entity new_object(key(), new_dims, new_data);

    std::vector<int> dst_max_idx(e_number_of_axes);
    assign(dst_max_idx, new_dims - 1);

    std::vector<int> src_max_idx(e_number_of_axes);
    assign(src_max_idx, axis_lengths_ - 1);

    std::vector<int> dst_idx(e_number_of_axes); // indexes new_object
    std::vector<int> src_idx(e_number_of_axes); // indexes '*this'

    std::vector<int> working_idx(e_number_of_axes);
    for(int j = 0; j < n_iter; j++)
        {
        int z = j;
        std::vector<int>::const_iterator i = new_dims.begin();
        std::vector<int>::iterator w = working_idx.begin();
        while(i != new_dims.end())
            {
            LMI_ASSERT(0 != *i);
            *w = z % *i;
            z /= *i;
            i++;
            w++;
            }
        LMI_ASSERT(0 == z);

        // limit dst and source indexes to those that actually vary
        assign(dst_idx, apply_binary(lesser_of<int>(), working_idx, dst_max_idx));
        assign(src_idx, apply_binary(lesser_of<int>(), working_idx, src_max_idx));
        new_object[dst_idx] = operator[](src_idx);
        }

    axis_lengths_ = new_dims;
    data_values_  = new_object.data_values_;
    assert_invariants();
}
Exemplo n.º 2
0
void MortalityRates::MakeCoiRateSubstandard(std::vector<double>& coi_rates)
{
    // Nothing to do if no rating.
    if(!IsPolicyRated_)
        {
        return;
        }

    if(!(AllowFlatExtras_ || AllowSubstdTable_))
        {
        fatal_error()
            << "Flat extras and table ratings not permitted."
            << LMI_FLUSH
            ;
        }

    static double const factors[11] =
        {0.0, 0.25, 0.50, 0.75, 1.00, 1.25, 1.50, 2.00, 2.50, 3.00, 4.00,};
    assign
        (coi_rates
        ,apply_binary
            (lesser_of<double>()
            ,MaxMonthlyCoiRate_
            ,   AnnualFlatExtra_ / 12000.0
              + coi_rates * (1.0 + SubstdTblMult_ * factors[SubstandardTable_])
            )
        );
    std::transform(coi_rates.begin(), coi_rates.end(), coi_rates.begin(), round_coi_rate_);
}
Exemplo n.º 3
0
Arquivo: lncky.c Projeto: mjpost/cky
chart
cky(struct vindex terms, grammar g, si_t si)
{
  int left, mid;
  chart c;

  c = chart_make(terms.n);
  
  /* insert lexical items */

  for (left = 0; left < (int) terms.n; left++) {
    si_index	label = terms.e[left];
    sihashcc    chart_entry = CHART_ENTRY(c, left, left+1);
    sihashcc    left_vertex = c->vertex[left];
    chart_cell  cell = add_edge(chart_entry, label, NULL, NULL, 1.0, 
				left+1, left_vertex);    
    
    assert(cell);  /* check that cell was actually added */
    follow_unary(cell, chart_entry, g, left+1, left_vertex);
  }

  /* actually do syntactic rules! */

  for (left = (int) terms.n-1; left >= 0; left--) {
    for (mid = left+1; mid < (int) terms.n; mid++) {
      sihashcc chart_entry = CHART_ENTRY(c, left, mid);
      /* unary close cell spanning from left to mid */
      if (mid - left > 1)
	apply_unary(chart_entry, g, mid, c->vertex[left]);
      /* now apply binary rules */
      apply_binary(chart_entry, left, mid, c, g);
    }
    /* apply unary rules to chart cells spanning from left to end of sentence
     * there's no need to apply binary rules to these
     */
    apply_unary(CHART_ENTRY(c, left, terms.n), g, 
		(int) terms.n, c->vertex[left]);
    /*
      printf("Chart entry %d-%d\n", (int) left, (int) right);
      chart_entry_display(CHART_ENTRY(c,left,right), si);
     */
  }
  return c;
}