Skip to content

sam::Experiment

Module: Experiment Modules

Experiment encapsulates data and methods needed by the Researcher to conduct its research. More...

#include <Experiment.h>

Public Functions

Name
DependentVariable & operator[](std::size_t idx)
const DependentVariable & operator[](std::size_t idx) const
auto begin()
auto end()
auto begin() const
auto end() const
Experiment() =default
Default constructor.
Experiment(json & experiment_config)
Constructs an Experiment object using the given JSON configuration.
Experiment(ExperimentSetup & e)
Constructs an Experiment using an already initialized ExperimentSetup.
Experiment(ExperimentSetup & e, std::shared_ptr< DataStrategy > & ds, std::shared_ptr< TestStrategy > & ts, std::shared_ptr< EffectStrategy > & es)
Directly constructs an Experiment from its components.
void addNewCondition()
void addNewCondition(const std::vector< DependentVariable > & dvs)
void addNewDependentVariable(const DependentVariable & dv)
Adds a new dependent variable to the list.
void addNewCandidates(const std::vector< Submission > & subs)
Adds new submissions to the list of submissions.
void setHackedStatus(const bool status)
Sets the hacked status of the experiment.
void setPublishedStatus(const bool status)
Sets the published status of the experiment.
void setHackedStatusOf(const std::vector< size_t > & idxs, const bool status)
Sets the hacked status of a group of dvs.
void setCandidateStatusOf(const std::vector< size_t > & idxs, const bool status)
Sets the candidate status of a group of dvs.
bool isHacked() const
Returns true if the experiment is hacked.
bool isModified() const
Returns true if the experiment has been modified in anyway.
bool hasCandidates() const
Returns true if there is an candidate in the experiment.
bool hasCovariants() const
Returns true if there is an candidate in the experiment.
bool isPublished() const
Returns true if the experiment has been published by the Journal.
size_t nCandidates() const
Returns the number of candidate DVs.
int nCovariants() const
void reset()
Clears and re-initializes the dependent variables.
void generateData()
Uses the DataStrategy to populate every DVs with raw the data.
void generateCovariants()
Generates covariants data.
void calculateStatistics()
Asks each DependentVariable to update its general statistics, e.g., mean, var.
void calculateTests()
Uses the TestStrategy to run the statistical test.
void calculateEffects()
Uses the EffectStrategy to calculates the effect sizes.
void recalculateEverything()
Runs calculateStatistics(), calculateTests(), and calculateEffects() in order.
void clear()
Clears the content of the experiment.
void setTestStrategy(std::shared_ptr< TestStrategy > & ts)
void setDataStrategy(std::shared_ptr< DataStrategy > & ds)
void setEffectSizeEstimator(std::shared_ptr< EffectStrategy > & es)

Public Attributes

Name
int simid
int exprid
int repid
int n_covariants
Indicates the number of covariants.
arma::Mat< int > covariants
ExperimentSetup setup
std::shared_ptr< DataStrategy > data_strategy
std::shared_ptr< TestStrategy > test_strategy
std::shared_ptr< EffectStrategy > effect_strategy
std::vector< DependentVariable > dvs_
std::optional< std::vector< Submission > > candidates
List of all possible candidates from this experiment so far!

Detailed Description

class sam::Experiment;

Experiment encapsulates data and methods needed by the Researcher to conduct its research.

Experiment has a full access to all data-related strategies, e.g., DataStrategy, TestStrategy, and EffectStrategy. It also contains the raw research data in the form of list of DependentVariable(s). Moreover, the Experiment stores a copy of the ExperimentSetup where most study parameters are stored in.

Public Functions Documentation

function operator[]

DependentVariable & operator[](
    std::size_t idx
)

Todo: I'm not the fan of this find_if here, and I think I can do better.

I think I can avoid this search if I use std::reference_wrapper

These operators are returning the correct group, even if the group list is not sorted.

function operator[]

const DependentVariable & operator[](
    std::size_t idx
) const

function begin

inline auto begin()

function end

inline auto end()

function begin

inline auto begin() const

function end

inline auto end() const

function Experiment

Experiment() =default

Default constructor.

function Experiment

Experiment(
    json & experiment_config
)

Constructs an Experiment object using the given JSON configuration.

This constructs an Experiment, and allocates the resources necessary for the experiment to setup its dependent variables, etc. Using the config parameters of the Data, Test, and Effect strategies, it also initializes those to be used by the Researcher or the Experiment itself

function Experiment

Experiment(
    ExperimentSetup & e
)

Constructs an Experiment using an already initialized ExperimentSetup.

Note: This can be used in cases where the underlying strategies should be preserved while some experiment parameters needs to be modified.

Since ExperimentSetup already contains the definition of Data, Test, and Effect strategies, this method accepts the ExperimentSetup as it is, and only initialize those strategies.

function Experiment

Experiment(
    ExperimentSetup & e,
    std::shared_ptr< DataStrategy > & ds,
    std::shared_ptr< TestStrategy > & ts,
    std::shared_ptr< EffectStrategy > & es
)

Directly constructs an Experiment from its components.

Note: This is mainly used by the ExperimentBuilder

This directly constructs the experiment by directly constructing its internal based on the set of given parameters.

function addNewCondition

void addNewCondition()

Adds a new condition @TODO TO BE IMPLEMENTED!

function addNewCondition

void addNewCondition(
    const std::vector< DependentVariable > & dvs
)

Adds a new condition @TODO TO BE IMPLEMENTED!

function addNewDependentVariable

void addNewDependentVariable(
    const DependentVariable & dv
)

Adds a new dependent variable to the list.

function addNewCandidates

void addNewCandidates(
    const std::vector< Submission > & subs
)

Adds new submissions to the list of submissions.

Adds new candidates to the list of selected candidates

function setHackedStatus

void setHackedStatus(
    const bool status
)

Sets the hacked status of the experiment.

Attention: Setting this to true will make the [isHacked()](/doxygen/Classes/classsam_1_1_experiment/#function-ishacked) to return true. Basically, this overrules the status of the dependent variables, but it doesn't overwrite them!

It sets the overall hacked status of the experiment to status.

function setPublishedStatus

void setPublishedStatus(
    const bool status
)

Sets the published status of the experiment.

function setHackedStatusOf

void setHackedStatusOf(
    const std::vector< size_t > & idxs,
    const bool status
)

Sets the hacked status of a group of dvs.

function setCandidateStatusOf

void setCandidateStatusOf(
    const std::vector< size_t > & idxs,
    const bool status
)

Sets the candidate status of a group of dvs.

function isHacked

bool isHacked() const

Returns true if the experiment is hacked.

An experiment is hacked if its hacked status has been set to true, or one of its dependent variables has been flagged as hacked

function isModified

bool isModified() const

Returns true if the experiment has been modified in anyway.

function hasCandidates

bool hasCandidates() const

Returns true if there is an candidate in the experiment.

function hasCovariants

bool hasCovariants() const

Returns true if there is an candidate in the experiment.

function isPublished

bool isPublished() const

Returns true if the experiment has been published by the Journal.

function nCandidates

size_t nCandidates() const

Returns the number of candidate DVs.

function nCovariants

int nCovariants() const

function reset

void reset()

Clears and re-initializes the dependent variables.

This cleanup the Experiment, and reallocate its memory again. Technically, preparing the experiment for a new run.

function generateData

void generateData()

Uses the DataStrategy to populate every DVs with raw the data.

function generateCovariants

void generateCovariants()

Generates covariants data.

@Todo Check if all groups are the same size

function calculateStatistics

void calculateStatistics()

Asks each DependentVariable to update its general statistics, e.g., mean, var.

function calculateTests

void calculateTests()

Uses the TestStrategy to run the statistical test.

function calculateEffects

void calculateEffects()

Uses the EffectStrategy to calculates the effect sizes.

function recalculateEverything

void recalculateEverything()

Runs calculateStatistics(), calculateTests(), and calculateEffects() in order.

function clear

void clear()

Clears the content of the experiment.

Todo: I think this is a bad implementation, and I should probably just discard the list of DVs and recreate them for the new Experiment, which is probably safer! Something like dvs_.clear()

It clears every DVs individually, and also sort them back into the correct order.

function setTestStrategy

inline void setTestStrategy(
    std::shared_ptr< TestStrategy > & ts
)

Parameters:

  • t A reference to a Test Strategy instance

Set or re-set the Test Strategy

function setDataStrategy

inline void setDataStrategy(
    std::shared_ptr< DataStrategy > & ds
)

Parameters:

  • d A reference to a Data Strategy instance

Set or re-set the Data Strategy

function setEffectSizeEstimator

inline void setEffectSizeEstimator(
    std::shared_ptr< EffectStrategy > & es
)

Parameters:

  • es A reference to an Effect Strategy instance.

Set or re-set the Effect Strategy

Public Attributes Documentation

variable simid

int simid {0};

variable exprid

int exprid {0};

variable repid

int repid {0};

variable n_covariants

int n_covariants {0};

Indicates the number of covariants.

variable covariants

arma::Mat< int > covariants;

variable setup

ExperimentSetup setup;

An instance of the ExperimentSetup. All other strategies can access and query it for meta information about the Experiment

variable data_strategy

std::shared_ptr< DataStrategy > data_strategy;

variable test_strategy

std::shared_ptr< TestStrategy > test_strategy;

variable effect_strategy

std::shared_ptr< EffectStrategy > effect_strategy;

variable dvs_

std::vector< DependentVariable > dvs_;

variable candidates

std::optional< std::vector< Submission > > candidates;

List of all possible candidates from this experiment so far!

Note: This is not yet in use!

This is a list of any dvs that has been flagged as submissions during the lifespan of this experiment


Updated on 29 June 2021 at 16:13:47 CEST


Last update: 2021-09-18