pict icon indicating copy to clipboard operation
pict copied to clipboard

Using non default random seed for a model will produce invalid set of results

Open MilanAssuied opened this issue 7 months ago • 1 comments

Consider the following test case that use 3 parameters of two values each:

 This test uses three parameters with two values each:
 
 AValues: A0, B1
 BValues: B0, B1
 CValues: C0, C1
 
 To be pair-wise covered, the following values pairs need to be generated:
 
 (A0, B0), (A0, B1),
 (A1, B0), (A1, B1),
 (A0, C0), (A0, C1),
 (A1, C0), (A1, C1),
 (B0, C0), (B0, C1)
 (B1, C0), (B1, C1)
 
 Aka: A total of 12 combinations is expected.
 
 This pairs can be covered with the following 3-parameters combinations:
 
 (A0, B0, C1): covers (A0, B0), (A0, C1), (B0, C1)
 (A0, B1, C0): covers (A0, B1), (A0, C0), (B1, C0)
 (A1, B0, C0): covers (A1, B0), (A1, C0), (B0, C0)
 (A1, B1, C1):  covers (A1, B1), (A1, C1), (B1, C1)
 
 Which means that 4 results lines are expected, covering all those combinations.

While this may not be the only set of valid combination, this case establishes that the necessary number of sets to cover all pair-wise combination is 4.

Consider now the following implementation of this test:

void test_that_random_seed_will_produce_invalid_results() {
    std::vector<std::vector<unsigned int>> actual_results;

    const auto random_seed = 6;
    const auto task = PictCreateTask();
    const auto model = PictCreateModel(random_seed);

    PictSetRootModel(task, model);

    PictAddParameter(model, 2);
    PictAddParameter(model, 2);
    PictAddParameter(model, 2);

    const PICT_RESULT_ROW row = PictAllocateResultBuffer(task);
    const size_t paramCount = PictGetTotalParameterCount(task);

    PictGenerate(task);
    PictResetResultFetching(task);

    while (PictGetNextResultRow(task, row)) {
        std::vector<unsigned int> temp_row;

        for (size_t index = 0; index < paramCount; ++index) {
            temp_row.push_back(static_cast<unsigned int>(row[index]));
        }

        actual_results.push_back(temp_row);
    }

    PictFreeResultBuffer(row);

    assert(actual_results.size() == 4);

    PictDeleteModel(model);
    PictDeleteTask(task);
}

This code will produce not 4 but 5 set of results as follow:

{(0, 1, 1), (1, 0, 0), (0, 0, 0), (1, 1, 0), (1, 0, 1)}

As we can see the pair (A1, B0), (B0, C0) and (A1, C0) are present several times.

I found out that between values of 0 and 600, 497 random seeds will produce invalid results. Using default random seed (0) will produce actual results for this test, but I cannot be sure the results will be valid for any possible models.

MilanAssuied avatar Jul 18 '24 18:07 MilanAssuied