classdef janis_pro_randomMask < janis_pre_roi & janis_processor

    properties (SetAccess = protected)
        nFeatures;                       % mask that schould be applied
        randomStream;
    end

    methods (Static)
        function desc = description
            desc = 'Generates random subspace ensemble for ensemble classification';
        end
        function shortName = name
            shortName = 'Random Mask';
        end
        function beVisible = shouldBeVisible
            beVisible = false;
        end
    end

    methods
        function bool = isConfigurable(this)
            bool = true;
        end

        function [patternTrain, patternTest] = operate(this, patternTrain, patternTest, trainLabels)
            this.randomStream.reset;
            mask = zeros(size(patternTrain,1),1);
            permIdx = randperm(this.randomStream,size(mask,1));
            randIdx = permIdx(1:this.nFeatures);
            mask(randIdx) = 1;
            this.mask = mask;
            patternTrain = patternTrain(logical(reshape(mask,numel(mask),1)),:);
            patternTest = patternTest(logical(reshape(mask,numel(mask),1)),:);
        end

        function this = setRandomStream(this,s)
            this.randomStream = s;
        end

        function this = reset(this)
            this.randomStream.reset;
        end

        function this = setNFeatures(this,nFeat)
            this.nFeatures = nFeat;
        end

        function new = copy(this)
            new = copy@janis_pre_roi(this);
            new.randomStream = this.randomStream;
            new.nFeatures = this.nFeatures;
        end

        function viewSettings(this)
            viewSettings@janis_processor(this);
            fprintf('  Random Seed:\t%i\n',this.randomStream.Seed);
            fprintf('  Number of Features:\t%i\n',this.nFeatures);
        end

    end

end