Skip to content

Commit 2a9d30b

Browse files
committed
update randomization
1 parent 2cc7ab9 commit 2a9d30b

File tree

9 files changed

+179
-103
lines changed

9 files changed

+179
-103
lines changed

.github/workflows/moxunit.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches: '*'
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
submodules: true
17+
fetch-depth: 1
18+
- name: MOxUnit Action
19+
uses: joergbrech/[email protected]
20+
with:
21+
tests: tests
22+
src: subfun
23+
with_coverage: true
24+
cover_xml_file: coverage.xml
25+
- name: Code coverage
26+
uses: codecov/codecov-action@v1
27+
with:
28+
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
29+
file: coverage.xml # optional
30+
flags: unittests # optional
31+
name: codecov-umbrella # optional
32+
fail_ci_if_error: true # optional (default = false)

audioLocTranslational.m

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,8 @@
4040
[cfg] = initPTB(cfg);
4141

4242
[el] = eyeTracker('Calibration', cfg);
43-
44-
% % % REFACTOR THIS FUNCTION % % %
45-
46-
[cfg] = expDesign(cfg);
4743

48-
cfg.design.blockNames
49-
50-
% % % REFACTOR THIS FUNCTION % % %
44+
[cfg] = expDesign(cfg);
5145

5246
% Prepare for the output logfiles with all
5347
logFile.extraColumns = cfg.extraColumns;

initEnv.m

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
% - struct
99
% - statistics
1010
%
11-
% MATLAB > R2017a
11+
% MATLAB >= R2015b
1212
%
1313
% 2 - Add project to the O/M path
1414

@@ -17,34 +17,28 @@
1717
octaveVersion = '4.0.3';
1818
matlabVersion = '8.6.0';
1919

20+
installlist = {'io', 'statistics', 'image'};
21+
2022
if isOctave
2123

2224
% Exit if min version is not satisfied
2325
if ~compare_versions(OCTAVE_VERSION, octaveVersion, '>=')
2426
error('Minimum required Octave version: %s', octaveVersion);
2527
end
2628

27-
installlist = {'statistics', 'image'};
2829
for ii = 1:length(installlist)
30+
31+
packageName = installlist{ii};
32+
2933
try
3034
% Try loading Octave packages
31-
disp(['loading ' installlist{ii}]);
32-
pkg('load', installlist{ii});
35+
disp(['loading ' packageName]);
36+
pkg('load', packageName);
3337

3438
catch
35-
errorcount = 1;
36-
while errorcount % Attempt twice in case installation fails
37-
try
38-
pkg('install', '-forge', installlist{ii});
39-
pkg('load', installlist{ii});
40-
errorcount = 0;
41-
catch err
42-
errorcount = errorcount + 1;
43-
if errorcount > 2
44-
error(err.message);
45-
end
46-
end
47-
end
39+
40+
tryInstallFromForge(packageName);
41+
4842
end
4943
end
5044

@@ -58,7 +52,9 @@
5852

5953
% If external dir is empty throw an exception
6054
% and ask user to update submodules.
61-
if numel(dir('lib')) <= 2 % Means that the external is empty
55+
libDirectory = fullfile(fileparts(mfilename('fullpath')), 'lib');
56+
57+
if numel(dir(libDirectory)) <= 2 % Means that the external is empty
6258
error(['Git submodules are not cloned!', ...
6359
'Try this in your terminal:', ...
6460
' git submodule update --recursive ']);
@@ -70,25 +66,41 @@
7066

7167
end
7268

73-
%%
74-
%% Return: true if the environment is Octave.
75-
%%
7669
function retval = isOctave
70+
% Return: true if the environment is Octave.
7771
persistent cacheval % speeds up repeated calls
7872

7973
if isempty (cacheval)
8074
cacheval = (exist ('OCTAVE_VERSION', 'builtin') > 0);
8175
end
8276

8377
retval = cacheval;
78+
79+
end
80+
81+
function tryInstallFromForge(packageName)
82+
83+
errorcount = 1;
84+
while errorcount % Attempt twice in case installation fails
85+
try
86+
pkg('install', '-forge', packageName);
87+
pkg('load', packageName);
88+
errorcount = 0;
89+
catch err
90+
errorcount = errorcount + 1;
91+
if errorcount > 2
92+
error(err.message);
93+
end
94+
end
95+
end
96+
8497
end
8598

8699
function addDependencies()
87100

88101
pth = fileparts(mfilename('fullpath'));
89102
addpath(genpath(fullfile(pth, 'lib', 'CPP_BIDS', 'src')));
90-
addpath(fullfile(pth, 'lib', 'CPP_PTB'));
103+
addpath(genpath(fullfile(pth, 'lib', 'CPP_PTB', 'src')));
91104
addpath(fullfile(pth, 'subfun'));
92-
addpath(fullfile(pth, 'input'));
93105

94106
end

lib/CPP_BIDS

setParameters.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
% cfg.design.motionType = 'radial';
3939
cfg.design.motionType = 'translation';
4040
cfg.design.names = {'static'; 'motion'};
41-
cfg.design.possibleDirections = [-1 1]; % 1 motion , -1 static %NOT IN USE AT THE MOMENT
42-
% cfg.design.nbBlocks = size(cfg.design.names, 2); % TO CHECK
43-
cfg.design.nbRepetitions = 14; % AT THE MOMENT IT IS NOT SET IN THE MAIN SCRIPT
41+
cfg.design.motionDirections = [-1 -1 1 1];
42+
cfg.design.nbRepetitions = 14;
4443
cfg.design.nbEventsPerBlock = 12;
4544

4645
%% Timing
@@ -80,7 +79,7 @@
8079
cfg.fixation.xDisplacement = 0;
8180
cfg.fixation.yDisplacement = 0;
8281

83-
cfg.target.maxNbPerBlock = 0;
82+
cfg.target.maxNbPerBlock = 2;
8483
cfg.target.duration = 0.5; % In secs
8584

8685
cfg.extraColumns = {'direction', 'speed', 'target', 'event', 'block', 'keyName'};

subfun/expDesign.m

Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,16 @@
5757

5858
% Set variables here for a dummy test of this function
5959
if nargin < 1 || isempty(cfg)
60-
% cfg.design.motionType = 'translation';
61-
cfg.design.motionType = 'translation';
62-
cfg.design.names = {'static'; 'motion'};
63-
cfg.design.nbRepetitions = 16;
64-
cfg.design.nbEventsPerBlock = 12;
65-
cfg.target.maxNbPerBlock = 0;
66-
displayFigs = 1;
60+
error('give me something to work with');
6761
end
6862

6963
fprintf('\n\nCreating design.\n\n')
7064

71-
7265
[NB_BLOCKS, NB_REPETITIONS, NB_EVENTS_PER_BLOCK, MAX_TARGET_PER_BLOCK] = getInput(cfg);
7366
[~, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg);
7467

75-
RANGE_TARGETS = [1 MAX_TARGET_PER_BLOCK];
76-
targetPerCondition = repmat(RANGE_TARGETS, 1, NB_REPETITIONS / 2);
68+
RANGE_TARGETS = 1:MAX_TARGET_PER_BLOCK;
69+
targetPerCondition = repmat(RANGE_TARGETS, 1, NB_REPETITIONS / MAX_TARGET_PER_BLOCK);
7770

7871
numTargetsForEachBlock = zeros(1, NB_BLOCKS);
7972
numTargetsForEachBlock(STATIC_INDEX) = shuffle(targetPerCondition);
@@ -92,33 +85,19 @@
9285
% - targets cannot be on the first or last event of a block
9386
% - no more than 2 target in the same event order
9487

95-
chosenTarget = [];
96-
97-
tmpTarget = numTargetsForEachBlock(iBlock);
98-
99-
switch tmpTarget
100-
101-
case 1
102-
103-
chosenTarget = randsample(2:NB_EVENTS_PER_BLOCK - 1, tmpTarget, false);
88+
nbTarget = numTargetsForEachBlock(iBlock);
10489

105-
case 2
90+
chosenPosition = setTargetPositionInSequence( ...
91+
NB_EVENTS_PER_BLOCK, ...
92+
nbTarget, ...
93+
[1 NB_EVENTS_PER_BLOCK]);
10694

107-
targetDifference = 0;
108-
109-
while any(targetDifference <= 2)
110-
chosenTarget = randsample(2:NB_EVENTS_PER_BLOCK - 1, tmpTarget, false);
111-
targetDifference = diff(chosenTarget);
112-
end
113-
114-
end
115-
116-
fixationTargets(iBlock, chosenTarget) = 1;
95+
fixationTargets(iBlock, chosenPosition) = 1;
11796

11897
end
11998

12099
% Check rule 3
121-
if max(sum(fixationTargets)) < 3
100+
if max(sum(fixationTargets)) < NB_REPETITIONS - 1
122101
break
123102
end
124103

@@ -154,26 +133,17 @@
154133
directions = zeros(NB_BLOCKS, NB_EVENTS_PER_BLOCK);
155134

156135
% Create a vector for the static condition
136+
NB_REPEATS_BASE_VECTOR = NB_EVENTS_PER_BLOCK / length(STATIC_DIRECTIONS);
137+
157138
static_directions = repmat( ...
158139
STATIC_DIRECTIONS, ...
159-
1, NB_EVENTS_PER_BLOCK / length(STATIC_DIRECTIONS));
140+
1, NB_REPEATS_BASE_VECTOR);
160141

161142
for iMotionBlock = 1:NB_REPETITIONS
162143

163-
% Check that we never have twice the same direction
164-
while 1
165-
tmp = [ ...
166-
shuffle(MOTION_DIRECTIONS), ...
167-
shuffle(MOTION_DIRECTIONS), ...
168-
shuffle(MOTION_DIRECTIONS)];
169-
170-
if ~any(diff(tmp, [], 2) == 0)
171-
break
172-
end
173-
end
174-
175144
% Set motion direction and static order
176-
directions(MOTION_INDEX(iMotionBlock), :) = tmp;
145+
directions(MOTION_INDEX(iMotionBlock), :) = ...
146+
repeatShuffleConditions(MOTION_DIRECTIONS, NB_REPEATS_BASE_VECTOR);
177147
directions(STATIC_INDEX(iMotionBlock), :) = static_directions;
178148

179149
end
@@ -187,15 +157,8 @@
187157
% CONSTANTS
188158
% Set directions for static and motion condition
189159

190-
STATIC_DIRECTIONS = [-1 -1 -1 -1];
191-
192-
switch cfg.design.motionType
193-
case 'translation'
194-
MOTION_DIRECTIONS = [0 0 180 180];
195-
case 'radial'
196-
STATIC_DIRECTIONS = [666 -666 666 -666];
197-
MOTION_DIRECTIONS = [666 -666 666 -666];
198-
end
160+
MOTION_DIRECTIONS = cfg.design.motionDirections;
161+
STATIC_DIRECTIONS = repmat(-1, size(MOTION_DIRECTIONS));
199162

200163
end
201164

@@ -206,25 +169,16 @@
206169
nbBlocks = length(cfg.design.names) * nbRepet;
207170
end
208171

209-
function [condition, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg)
172+
function [conditionNamesVector, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg)
210173

211174
[~, nbRepet] = getInput(cfg);
212175

213-
condition = repmat(cfg.design.names, nbRepet, 1);
176+
conditionNamesVector = repmat(cfg.design.names, nbRepet, 1);
214177

215178
% Get the index of each condition
216-
STATIC_INDEX = find(strcmp(condition, 'static'));
217-
MOTION_INDEX = find(strcmp(condition, 'motion'));
218-
219-
end
179+
STATIC_INDEX = find(strcmp(conditionNamesVector, 'static'));
180+
MOTION_INDEX = find(strcmp(conditionNamesVector, 'motion'));
220181

221-
function shuffled = shuffle(unshuffled)
222-
% in case PTB is not in the path
223-
try
224-
shuffled = Shuffle(unshuffled);
225-
catch
226-
shuffled = unshuffled(randperm(length(unshuffled)));
227-
end
228182
end
229183

230184
function diplayDesign(cfg, displayFigs)

tests/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

0 commit comments

Comments
 (0)