Skip to content

Update of Damping not working with negative coefficients #1118

@HenrZu

Description

@HenrZu

Bug description

Assume we use the following damping factors

auto cont_freq_param = std::vector<double>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
auto cont_freq_param = std::vector<double>{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10};

we get

Initial contact matrix: 1
Adding changepoint at 1 with damping 2
Contact matrix at 1 is:-1
Adding changepoint at 2 with damping 3
Contact matrix at 2 is:-2
Adding changepoint at 3 with damping 4
Contact matrix at 3 is:-3
Adding changepoint at 4 with damping 5
Contact matrix at 4 is:-4
Adding changepoint at 5 with damping 6
Contact matrix at 5 is:-5
Adding changepoint at 6 with damping 7
Contact matrix at 6 is:-6
Adding changepoint at 7 with damping 8
Contact matrix at 7 is:-7
Adding changepoint at 8 with damping 9
Contact matrix at 8 is:-8
Adding changepoint at 9 with damping 10
Contact matrix at 9 is:-9

in the first example, everything works fine.

Initial contact matrix: 1
Adding changepoint at 1 with damping -2
Contact matrix at 1 is:3
Adding changepoint at 2 with damping -3
Contact matrix at 2 is:1
Adding changepoint at 3 with damping -4
Contact matrix at 3 is:1
Adding changepoint at 4 with damping -5
Contact matrix at 4 is:1
Adding changepoint at 5 with damping -6
Contact matrix at 5 is:1
Adding changepoint at 6 with damping -7
Contact matrix at 6 is:1
Adding changepoint at 7 with damping -8
Contact matrix at 7 is:1
Adding changepoint at 8 with damping -9
Contact matrix at 8 is:1
Adding changepoint at 9 with damping -10
Contact matrix at 9 is:1

Here, the dampings are ignored.

Version

Linux

To reproduce

    double cont_freq = 1; // see Polymod study

    double nb_total_t0 = 10000, nb_exp_t0 = 100, nb_inf_t0 = 50, nb_car_t0 = 50, nb_hosp_t0 = 20, nb_icu_t0 = 10,
           nb_rec_t0 = 10, nb_dead_t0 = 0;

    mio::osecir::Model<double> model(1);

    model.parameters.template set<mio::osecir::StartDay>(60);
    model.parameters.set<mio::osecir::Seasonality<double>>(0.2);

    model.parameters.get<mio::osecir::TimeExposed<double>>()            = 3.2;
    model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>() = 2.0;
    model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()   = 5.8;
    model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()     = 9.5;
    model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()   = 7.1;

    mio::ContactMatrixGroup& contact_matrix = model.parameters.get<mio::osecir::ContactPatterns<double>>();
    contact_matrix[0]                       = mio::ContactMatrix(Eigen::MatrixXd::Constant(1, 1, cont_freq));
    std::cout << "Initial contact matrix: " << contact_matrix[0].get_baseline() << std::endl;

    // auto cont_freq_param = std::vector<double>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    auto cont_freq_param = std::vector<double>{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10};

    double eps = 1;
    for (size_t t = 1; t < cont_freq_param.size(); ++t) {
        std::cout << "Adding changepoint at " << t << " with damping " << cont_freq_param[t] << std::endl;
        contact_matrix.add_damping(cont_freq_param[t], mio::SimulationTime(static_cast<double>(t)));
        // model.parameters.get<mio::osecir::ContactPatterns<double>>().make_matrix();

        auto new_fac = contact_matrix.get_matrix_at(mio::SimulationTime(static_cast<double>(t) + eps));
        std::cout << "Contact matrix at " << t << " is:" << new_fac << std::endl;
    }

Relevant log output

No response

Add any relevant information, e.g. used compiler, screenshots.

No response

Checklist

  • Attached labels, especially loc:: or model:: labels.
  • Linked to project

Metadata

Metadata

Assignees

Labels

class::bugBugs found in the softwareloc::backendThis issue concerns the C++ backend implementation.model::odeThis issue concerns any kind of ODE-based model.prio::highThe priority of this task is high.

Type

No type

Projects

Status

Done (Total)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions