-
Notifications
You must be signed in to change notification settings - Fork 0
/
createTrainValidationDatastores.m
61 lines (40 loc) · 2.05 KB
/
createTrainValidationDatastores.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function [fdsTrainCombined, fdsValCombined] = createTrainValidationDatastores(sampleSize)
c = split(fileread('noisy_train.txt'));
c = cellfun(@(x) replace(x, 'noisy_train', ''), c, 'UniformOutput', false);
n = numel(c);
ii = randperm(n);
listLightCurves = c(ii);
listLightCurves = listLightCurves(1:sampleSize);
partition = cvpartition(sampleSize,'HoldOut',0.2);
uniqueIds = 1:sampleSize;
trainIds = uniqueIds(partition.training);
valIds = uniqueIds(partition.test);
trainFiles = listLightCurves(trainIds);
valFiles = listLightCurves(valIds);
train_folderName = "/noisy_train/home/ucapats/Scratch/ml_data_challenge/training_set/noisy_train";
trainPredictors = convertCharsToStrings(cellstr(cellfun(@(x) append(train_folderName, x), trainFiles, 'UniformOutput', false)));
valPredictors = convertCharsToStrings(cellstr(cellfun(@(x) append(train_folderName, x), valFiles, 'UniformOutput', false)));
params_folderName = '/params_train/home/ucapats/Scratch/ml_data_challenge/training_set/params_train';
trainTargets = convertCharsToStrings(cellstr(cellfun(@(x) append(params_folderName, x), trainFiles, 'UniformOutput', false)));
valTargets = convertCharsToStrings(cellstr(cellfun(@(x) append(params_folderName, x), valFiles, 'UniformOutput', false)));
% Train
fdsTrainPredictors = fileDatastore(trainPredictors, ...
'ReadFcn',@(filename) handlePredictors(filename));
fdsTrainTargets = fileDatastore(trainTargets, ...
'ReadFcn',@(filename) handleTargets(filename));
fdsTrainCombined = combine(fdsTrainPredictors, fdsTrainTargets);
% Validation
fdsValPredictors = fileDatastore(valPredictors, ...
'ReadFcn',@(filename) handlePredictors(filename));
fdsValTargets = fileDatastore(valTargets, ...
'ReadFcn',@(filename) handleTargets(filename));
fdsValCombined = combine(fdsValPredictors, fdsValTargets);
end
function lightcurve = handlePredictors(filename)
lightcurve = readmatrix(filename, 'Range', 7);
lightcurve = lightcurve';
lightcurve = (lightcurve - 1) ./ 0.04;
end
function target = handleTargets(filename)
target = readmatrix(filename, 'Range', 3);
end