Skip to content

Commit 0a4aa72

Browse files
authored
Merge pull request #79 from cpp-lln-lab/remi-update_randomize
add functions for randomizations with their tests
2 parents 8fdb408 + 07f10bc commit 0a4aa72

15 files changed

+222
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![](https://img.shields.io/badge/Octave-CI-blue?logo=Octave&logoColor=white)](https://github.com/cpp-lln-lab/CPP_PTB/actions)
22
![](https://github.com/cpp-lln-lab/CPP_PTB/workflows/CI/badge.svg)
33

4-
[![Build Status](https://travis-ci.com/cpp-lln-lab/CPP_BIDS.svg?branch=master)](https://travis-ci.com/cpp-lln-lab/CPP_PTB)
4+
[![Build Status](https://travis-ci.com/cpp-lln-lab/CPP_PTB.svg?branch=master)](https://travis-ci.com/cpp-lln-lab/CPP_PTB)
55

66
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
77
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)

manualTests/miss_hit.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# style guide (https://florianschanda.github.io/miss_hit/style_checker.html)
2+
line_length: 100
3+
regex_function_name: "((test_[a-z]+)|[a-z]+)(([A-Z]){1}[A-Za-z]+)*"
4+
suppress_rule: "copyright_notice"
5+
6+
# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html)
7+
metric "cnest": limit 4
8+
metric "file_length": limit 500
9+
metric "cyc": limit 15
10+
metric "parameters": limit 5
File renamed without changes.

miss_hit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# styly guide (https://florianschanda.github.io/miss_hit/style_checker.html)
1+
# style guide (https://florianschanda.github.io/miss_hit/style_checker.html)
22
line_length: 100
33
regex_function_name: "[a-z]+(([A-Z]){1}[A-Za-z]+)*"
44
suppress_rule: "copyright_notice"

src/isOctave.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function retval = isOctave
2+
% Return: true if the environment is Octave.
3+
persistent cacheval % speeds up repeated calls
4+
5+
if isempty (cacheval)
6+
cacheval = (exist ('OCTAVE_VERSION', 'builtin') > 0);
7+
end
8+
9+
retval = cacheval;
10+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function shuffledRepeats = repeatShuffleConditions(baseConditionVector, nbRepeats)
2+
% shuffledRepeats = repeatShuffleConditions(baseConditionVector, nbRepeats)
3+
%
4+
% given baseConditionVector, a vector of conditions (coded as numbers), this will
5+
% create a longer vector made of nbRepeats of this base vector and makesure
6+
% that a given condition is not repeated one after the other
7+
8+
% TODO
9+
% - needs some input checks to make sure that there is actually a solution
10+
% for this randomization (e.g having [1 1 1 1 1 2] as input will lead to an
11+
% infinite loop)
12+
13+
if numel(unique(baseConditionVector)) == 1
14+
error('There should be more than one condition to shuffle');
15+
end
16+
17+
baseConditionVector = baseConditionVector(:)';
18+
19+
while 1
20+
tmp = [];
21+
for iRepeat = 1:nbRepeats
22+
23+
tmp = [tmp, shuffle(baseConditionVector)];
24+
25+
end
26+
if ~any(diff(tmp, [], 2) == 0)
27+
break
28+
end
29+
end
30+
31+
shuffledRepeats = tmp;
32+
33+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function chosenPositions = setTargetPositionInSequence(seqLength, nbTarget, forbiddenPos)
2+
% chosenPositions = setTargetPositionInSequence(seqLength, nbTarget, forbiddenPos)
3+
%
4+
% For a sequence of length seqLength where we want to insert nbTarget targets, this
5+
% will return nbTarget random position in that sequence and make sure that,
6+
% they are not consecutive positions.
7+
8+
REPLACE = false;
9+
10+
allowedPositions = setxor(forbiddenPos, 1:seqLength);
11+
12+
chosenPositions = [];
13+
14+
if nbTarget < 1
15+
return
16+
17+
elseif nbTarget == 1
18+
19+
chosenPositions = randsample(allowedPositions, nbTarget, REPLACE);
20+
21+
else
22+
23+
targetDifference = 0;
24+
25+
while any(abs(targetDifference) < 2)
26+
chosenPositions = randsample(allowedPositions, nbTarget, REPLACE);
27+
chosenPositions = sort(chosenPositions);
28+
targetDifference = diff(chosenPositions, [], 2);
29+
end
30+
31+
end
32+
33+
end

src/randomization/shuffle.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function shuffled = shuffle(unshuffled)
2+
% in case PTB is not in the path
3+
% mostly for unit test
4+
%
5+
6+
try
7+
shuffled = Shuffle(unshuffled);
8+
catch
9+
shuffled = unshuffled(randperm(length(unshuffled)));
10+
end
11+
end

tests/manualTests/miss_hit.cfg

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/miss_hit.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# style guide (https://florianschanda.github.io/miss_hit/style_checker.html)
12
line_length: 100
23
regex_function_name: "((test_[a-z]+)|[a-z]+)(([A-Z]){1}[A-Za-z]+)*"
3-
suppress_rule: "copyright_notice"
4+
suppress_rule: "copyright_notice"
5+
6+
# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html)
7+
metric "cnest": limit 4
8+
metric "file_length": limit 500
9+
metric "cyc": limit 15
10+
metric "parameters": limit 5

0 commit comments

Comments
 (0)