Program Listing for File edata.h

Return to documentation for file (include/amici/edata.h)

#ifndef AMICI_EDATA_H
#define AMICI_EDATA_H

#include "amici/defines.h"
#include "amici/misc.h"
#include "amici/simulation_parameters.h"

#include <string>
#include <vector>

namespace amici {

class Model;
class ReturnData;

class ExpData : public SimulationParameters {

  public:
    ExpData() = default;

    // needs to be declared to be wrapped by SWIG
    ExpData(ExpData const&) = default;

    ExpData(int nytrue, int nztrue, int nmaxevent);

    ExpData(int nytrue, int nztrue, int nmaxevent, std::vector<realtype> ts);

    ExpData(
        int nytrue, int nztrue, int nmaxevent, std::vector<realtype> ts,
        std::vector<realtype> fixed_parameters
    );

    ExpData(
        int nytrue, int nztrue, int nmaxevent, std::vector<realtype> ts,
        std::vector<realtype> const& observed_data,
        std::vector<realtype> const& observed_data_std_dev,
        std::vector<realtype> const& observed_events,
        std::vector<realtype> const& observed_events_std_dev
    );

    explicit ExpData(Model const& model);

    ExpData(
        ReturnData const& rdata, realtype sigma_y, realtype sigma_z,
        int seed = -1
    );

    ExpData(
        ReturnData const& rdata, std::vector<realtype> sigma_y,
        std::vector<realtype> sigma_z, int seed = -1
    );

    ~ExpData() = default;

    friend inline bool operator==(ExpData const& lhs, ExpData const& rhs);

    int nytrue() const;

    int nztrue() const;

    int nmaxevent() const;

    int nt() const;

    void set_timepoints(std::vector<realtype> const& ts);

    std::vector<realtype> const& get_timepoints() const;

    realtype get_timepoint(int it) const;

    void set_observed_data(std::vector<realtype> const& observed_data);

    void set_observed_data(std::vector<realtype> const& observed_data, int iy);

    bool is_set_observed_data(int it, int iy) const;

    std::vector<realtype> const& get_observed_data() const;

    realtype const* get_observed_data_ptr(int it) const;

    void set_observed_data_std_dev(
        std::vector<realtype> const& observed_data_std_dev
    );

    void set_observed_data_std_dev(realtype stdDev);

    void set_observed_data_std_dev(
        std::vector<realtype> const& observedDataStdDev, int iy
    );

    void set_observed_data_std_dev(realtype stdDev, int iy);

    bool is_set_observed_data_std_dev(int it, int iy) const;

    std::vector<realtype> const& get_observed_data_std_dev() const;

    realtype const* get_observed_data_std_dev_ptr(int it) const;

    void set_observed_events(std::vector<realtype> const& observedEvents);

    void
    set_observed_events(std::vector<realtype> const& observedEvents, int iz);

    bool is_set_observed_events(int ie, int iz) const;

    std::vector<realtype> const& get_observed_events() const;

    realtype const* get_observed_events_ptr(int ie) const;

    void set_observed_events_std_dev(
        std::vector<realtype> const& observedEventsStdDev
    );

    void set_observed_events_std_dev(realtype stdDev);

    void set_observed_events_std_dev(
        std::vector<realtype> const& observedEventsStdDev, int iz
    );

    void set_observed_events_std_dev(realtype stdDev, int iz);

    bool is_set_observed_events_std_dev(int ie, int iz) const;

    std::vector<realtype> const& get_observed_events_std_dev() const;

    realtype const* get_observed_events_std_dev_ptr(int ie) const;

    void clear_observations();

    std::string id;

  protected:
    void apply_dimensions();

    void apply_data_dimension();

    void apply_event_dimension();

    void check_data_dimension(
        std::vector<realtype> const& input, char const* fieldname
    ) const;

    void check_events_dimension(
        std::vector<realtype> const& input, char const* fieldname
    ) const;

    int nytrue_{0};

    int nztrue_{0};

    int nmaxevent_{0};

    std::vector<realtype> observed_data_;

    std::vector<realtype> observed_data_std_dev_;

    std::vector<realtype> observed_events_;

    std::vector<realtype> observed_events_std_dev_;
};

inline bool operator==(ExpData const& lhs, ExpData const& rhs) {
    return *dynamic_cast<SimulationParameters const*>(&lhs)
               == *dynamic_cast<SimulationParameters const*>(&rhs)
           && lhs.id == rhs.id && lhs.nytrue_ == rhs.nytrue_
           && lhs.nztrue_ == rhs.nztrue_ && lhs.nmaxevent_ == rhs.nmaxevent_
           && is_equal(lhs.observed_data_, rhs.observed_data_)
           && is_equal(lhs.observed_data_std_dev_, rhs.observed_data_std_dev_)
           && is_equal(lhs.observed_events_, rhs.observed_events_)
           && is_equal(
               lhs.observed_events_std_dev_, rhs.observed_events_std_dev_
           );
}

void checkSigmaPositivity(
    std::vector<realtype> const& sigmaVector, char const* vectorName
);

void checkSigmaPositivity(realtype sigma, char const* sigmaName);

class ConditionContext : public ContextManager {
  public:
    explicit ConditionContext(
        Model* model, ExpData const* edata = nullptr,
        FixedParameterContext fpc = FixedParameterContext::simulation
    );

    ConditionContext& operator=(ConditionContext const& other) = delete;

    ~ConditionContext();

    void apply_condition(ExpData const* edata, FixedParameterContext fpc);

    void restore();

  private:
    Model* model_ = nullptr;
    std::vector<realtype> original_x0_;
    std::vector<realtype> original_sx0_;
    std::vector<realtype> original_parameters_;
    std::vector<realtype> original_fixed_parameters_;
    realtype original_tstart_;
    realtype original_tstart_preeq_;
    std::vector<realtype> original_timepoints_;
    std::vector<int> original_parameter_list_;
    std::vector<ParameterScaling> original_scaling_;
    bool original_reinitialize_fixed_parameter_initial_states_;
    std::vector<int> original_reinitialization_state_idxs;
};

} // namespace amici

#endif /* AMICI_EDATA_H */