Skip to content
Snippets Groups Projects
Commit 67fb1150 authored by ITC22366\local-study-admin's avatar ITC22366\local-study-admin
Browse files

improe randomization to not get confused by non-combined factors

parent e7d1fc17
Branches
No related tags found
No related merge requests found
...@@ -116,6 +116,9 @@ TArray<USFCondition*> USFStudyPhase::GenerateConditions(int ParticipantSequenceN ...@@ -116,6 +116,9 @@ TArray<USFCondition*> USFStudyPhase::GenerateConditions(int ParticipantSequenceN
// first restructure factors, such that: // first restructure factors, such that:
// - a potential enBlock factor is the first one // - a potential enBlock factor is the first one
// - then follow InOrder factors
// - then Random factors
// - and in the end non-combined factors
TArray<USFStudyFactor*> SortedFactors = SortFactors(); TArray<USFStudyFactor*> SortedFactors = SortFactors();
const bool bHasEnBlock = SortedFactors[0]->MixingOrder == EFactorMixingOrder::EnBlock; const bool bHasEnBlock = SortedFactors[0]->MixingOrder == EFactorMixingOrder::EnBlock;
...@@ -139,7 +142,7 @@ TArray<USFCondition*> USFStudyPhase::GenerateConditions(int ParticipantSequenceN ...@@ -139,7 +142,7 @@ TArray<USFCondition*> USFStudyPhase::GenerateConditions(int ParticipantSequenceN
// Generate Condition Indices // Generate Condition Indices
// **************************** // ****************************
//create an array holding for each condition an array of each factors' level index //create an array holding for each condition an array of each factors' level index (leaving -1 for nonCombined factors, they will be considered later)
TArray<TArray<int>> ConditionsIndices; TArray<TArray<int>> ConditionsIndices;
ConditionsIndices.Reserve(NumberOfConditions); ConditionsIndices.Reserve(NumberOfConditions);
CreateAllConditionsRecursively(0, {}, SortedFactors, ParticipantSequenceNr, ConditionsIndices); CreateAllConditionsRecursively(0, {}, SortedFactors, ParticipantSequenceNr, ConditionsIndices);
...@@ -153,18 +156,24 @@ TArray<USFCondition*> USFStudyPhase::GenerateConditions(int ParticipantSequenceN ...@@ -153,18 +156,24 @@ TArray<USFCondition*> USFStudyPhase::GenerateConditions(int ParticipantSequenceN
ConditionsIndices.Empty(); ConditionsIndices.Empty();
//compute what factors we have to consider: //compute what factors we have to consider:
int FullyRandomFactorsStartIndex = 0; int NumRandomConditions = 1;
int NumFullyRandomConditions = ConditionsIndicesCopy.Num(); int NumEnBlockLevels = 1;
int NumEnBlockLevels = bHasEnBlock ? SortedFactors[0]->Levels.Num() : 1;
int NumInOrderLevels = 1; int NumInOrderLevels = 1;
#
while (FullyRandomFactorsStartIndex < SortedFactors.Num() && SortedFactors[FullyRandomFactorsStartIndex]->MixingOrder != EFactorMixingOrder::RandomOrder) { for (USFStudyFactor* Factor : SortedFactors)
//so we jump over all inOrder factors and the enBlock factor (if it exists) {
NumFullyRandomConditions /= SortedFactors[FullyRandomFactorsStartIndex]->Levels.Num(); if (Factor->bNonCombined) {
if (SortedFactors[FullyRandomFactorsStartIndex]->MixingOrder == EFactorMixingOrder::InOrder) { continue;
NumInOrderLevels *= SortedFactors[FullyRandomFactorsStartIndex]->Levels.Num(); }
else if (Factor->MixingOrder == EFactorMixingOrder::EnBlock) {
NumEnBlockLevels *= Factor->Levels.Num();
}
else if (Factor->MixingOrder == EFactorMixingOrder::InOrder) {
NumInOrderLevels *= Factor->Levels.Num();
}
else if (Factor->MixingOrder == EFactorMixingOrder::RandomOrder) {
NumRandomConditions *= Factor->Levels.Num();
} }
FullyRandomFactorsStartIndex++;
} }
...@@ -176,15 +185,15 @@ TArray<USFCondition*> USFStudyPhase::GenerateConditions(int ParticipantSequenceN ...@@ -176,15 +185,15 @@ TArray<USFCondition*> USFStudyPhase::GenerateConditions(int ParticipantSequenceN
{ {
for (int InOrderLevel = 0; InOrderLevel < NumInOrderLevels; InOrderLevel++) for (int InOrderLevel = 0; InOrderLevel < NumInOrderLevels; InOrderLevel++)
{ {
const TArray<int> FullyRandomLatinSquare = USFStudyFactor::GenerateLatinSquareOrder( const TArray<int> LatinSquare = USFStudyFactor::GenerateLatinSquareOrder(
ParticipantSequenceNr + PhaseIndex + EnBlockLevel + InOrderLevel, NumFullyRandomConditions); ParticipantSequenceNr + PhaseIndex + EnBlockLevel + InOrderLevel, NumRandomConditions);
//we use all EnBlockLevel + InOrderLevel also for "seeding" so it is not repetitive //we use all EnBlockLevel + InOrderLevel also for "seeding" so it is not repetitive
for (int FullyRandomCondition = 0; FullyRandomCondition < FullyRandomLatinSquare.Num(); FullyRandomCondition++) for (int RandomLevel = 0; RandomLevel < LatinSquare.Num(); RandomLevel++)
{ {
ConditionsIndices.Add(ConditionsIndicesCopy[ ConditionsIndices.Add(ConditionsIndicesCopy[
NumInOrderLevels * NumFullyRandomConditions * EnBlockLatinSquare[EnBlockLevel] NumInOrderLevels * NumRandomConditions * EnBlockLatinSquare[EnBlockLevel]
+ NumFullyRandomConditions * InOrderLevel + NumRandomConditions * InOrderLevel
+ FullyRandomLatinSquare[FullyRandomCondition] + LatinSquare[RandomLevel]
]); ]);
} }
} }
...@@ -376,16 +385,22 @@ int USFStudyPhase::GetMapFactorIndex() const ...@@ -376,16 +385,22 @@ int USFStudyPhase::GetMapFactorIndex() const
TArray<USFStudyFactor*> USFStudyPhase::SortFactors() const TArray<USFStudyFactor*> USFStudyPhase::SortFactors() const
{ {
//puts the enBlock factor first! (in PhaseValid() it is checked that max one exists!) //puts the enBlock factor first! (in PhaseValid() it is checked that max one exists!)
//then it puts th inOrder factors and then the rest //then it puts th inOrder factors, then random factors and in the end nonCombined factors
TArray<USFStudyFactor*> EnBlockFactor; TArray<USFStudyFactor*> EnBlockFactor;
TArray<USFStudyFactor*> InOrderFactors; TArray<USFStudyFactor*> InOrderFactors;
TArray<USFStudyFactor*> RandomFactors; TArray<USFStudyFactor*> RandomFactors;
TArray<USFStudyFactor*> NonCombinedFactors;
for (USFStudyFactor* Factor : Factors) for (USFStudyFactor* Factor : Factors)
{ {
if (Factor->MixingOrder == EFactorMixingOrder::RandomOrder) if (Factor->bNonCombined)
{
NonCombinedFactors.Add(Factor);
}
else if (Factor->MixingOrder == EFactorMixingOrder::RandomOrder)
{ {
RandomFactors.Add(Factor); RandomFactors.Add(Factor);
} }
...@@ -409,6 +424,7 @@ TArray<USFStudyFactor*> USFStudyPhase::SortFactors() const ...@@ -409,6 +424,7 @@ TArray<USFStudyFactor*> USFStudyPhase::SortFactors() const
TArray<USFStudyFactor*> SortedFactors = EnBlockFactor; TArray<USFStudyFactor*> SortedFactors = EnBlockFactor;
SortedFactors.Append(InOrderFactors); SortedFactors.Append(InOrderFactors);
SortedFactors.Append(RandomFactors); SortedFactors.Append(RandomFactors);
SortedFactors.Append(NonCombinedFactors);
return SortedFactors; return SortedFactors;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment