
function [FacMat lambda fixed] = SamBaTen_start(X,F,sample_factor,nonneg)
%Ekta Gujral,Ravdeep Pasricha , Vagelis Papalexakis 2017
%Computer Science and Engineering, University of California, Riverside
%Demonstrating the use of the SambaTen algorithm, using samplaing based
%approach for online tensors
if nargin == 3
    nonneg = 0;
end
p = 1;
s = size(X); I = s(1); J = s(2); K = s(3);
        [Xs idx_i idx_j idx_k] = SamBaTen_initilize(X,sample_factor);
        fixed_i = idx_i(1:ceil(p*length(idx_i)));
        fixed_j = idx_j(1:ceil(p*length(idx_j)));
        fixed_k = idx_k(1:ceil(p*length(idx_k)));  % again
        fixed{1} = fixed_i; fixed{2} = fixed_j; fixed{3}=fixed_k;

    initOpt.printitn = 0;    
    if nnz(Xs)>0
        if nonneg
            factors = cp_nmu(X,F,initOpt);
        else
            factors = cp_als(X,F,initOpt);
        end
        As=sparse(factors.U{1});Bs=sparse(factors.U{2});Cs=sparse(factors.U{3});%lambda = factors.lambda;As = As*diag(lambda);
        lambda = factors.lambda;
        A = As*diag(lambda.^(1/3)); B= Bs*diag(lambda.^(1/3)); C = Cs*diag(lambda.^(1/3));  
    else
       A = 0; B = 0; C = 0; 
    end

     %now, normalize the common part of every column
   
    fixed_val=cell(3,1);
    fixed_val{1}=fixed_i;    fixed_val{2}=fixed_j;     fixed_val{3}=fixed_k;
A(A<10^-5) = 0;
B(B<10^-5) = 0;
C(C<10^-5) = 0;
FacMat{1}=A;FacMat{2}=B;FacMat{3}=C;

end


