function [out] = f_predict2(X1,X2,beta_mixing,beta_kernel,tau,threshold,q,type)
    
    % infer dimensions
    n        = size(X1,1);
    R        = size(beta_mixing,3);
    
    if strcmp(type,'mean')
        pred_mean = zeros(n,R);
        
        for r = 1:R
            pred_mean(:,r) = f_pred_mean(X1,X2,beta_mixing(:,:,r),beta_kernel(:,:,r));
        end
        out = pred_mean;
        
    elseif strcmp(type,'variance')
        
        pred_variance = zeros(n,R);
        
        for r = 1:R
            pred_variance(:,r) = f_pred_var(X1,X2,beta_mixing(:,:,r),beta_kernel(:,:,r),tau(:,r));
        end
        out = pred_variance;
        
    elseif strcmp(type,'cdf')
        
        cdf = zeros(n,R);
        
        for r = 1:R
            cdf(:,r) = f_pred_cdf(X1,X2,beta_mixing(:,:,r),beta_kernel(:,:,r),tau(:,r),threshold);
        end
        out = cdf; 
            
    elseif strcmp(type,'quantile')
        
        
        quantiles = zeros(n,length(q));
        if size(beta_mixing,3)>1
            for t = 1:n
                for r = 1:length(q)
                    quantiles(t,r) = fzero(@(x) (f_pred_cdf(X1(t,:),X2(t,:),mean(beta_mixing,3),mean(beta_kernel,3),mean(tau,2),x))-q(r), [-100,100]);
                end
            end
        else
            for t = 1:n
                for r = 1:length(q)
                    quantiles(t,r) = fzero(@(x) (f_pred_cdf(X1(t,:),X2(t,:),beta_mixing,beta_kernel,tau,x))-q(r), [-100,100]);
                end
            end
        end
        
        out = quantiles;
        
        %qmist2n = fzero(@(x) mean(f_pred_cdf(X1,X2,beta_mixing(:,:,r),beta_kernel(:,:,r),tau(:,r),x))-q, [-10,10]);
    elseif strcmp(type,'contributions')
        p = size(X1,2);
        contributions = zeros(n,p,R);
        
        for r = 1:R
            contributions(:,:,r) = f_pred_contribs(X1,X2,beta_mixing(:,:,r),beta_kernel(:,:,r));
        end
        out = contributions;
        
    elseif strcmp(type,'CRPS')
        CRPS = zeros(R,1);
        
        for r = 1:R
            CRPS(r,1) = f_pred_CPRS(threshold,X1,X2,beta_mixing(:,:,r),beta_kernel(:,:,r),tau(:,r));
        end
        out = CRPS; 
    end

end

