function saveTanh(dataSets)
    for i = 1:length(dataSets)
        ds = dataSets{i};
        eval(['[' ds '_f, ' ...
                ds '_g, ' ...
                ds '_Hv, ' ...
                ds '_n, ' ...
                ds '_pts] = ' ...
                'createTanh(''' ds ''');']);
        save('./tanhEnv.mat', [ds '_f'], [ds '_g'], [ds '_Hv'], [ds '_n'], [ds '_pts'], '-append');
        display(['Done ' ds]);
    end
end

function [f, g, H, n, pts] = createTanh(dataSet)
    try
        [y, X] = libsvmread(dataSet);
        X = [ones(size(X,1),1) X];
        Xt = X';
        if sum(y==1) + sum(y==0) == length(y)
            y = 2*y - 1;
        elseif sum(y==1) + sum(y==2) == length(y)
            y = 2*y - 3;
        end
        if sum(y==1) + sum(y==-1) ~= length(y)
            display(['Error: Failed to transform y to binary classes in ' dataSet]);
            return;
        end
    catch loadFileErr
        display(loadFileErr);
        return;
    end
    M = size(X,1);
    reg = 1/M;
    n = size(X,2);
    pts = size(X, 1);
    
    f = @(x,S) (1/length(S)*tanhLoss(X, y, x, S)  + 1/2*reg*norm(x)^2);
    g = @(x,S) (1/length(S)*tanhGrad(X, y, x, S) + reg*x);
    H = @(x,S,D) (1/length(S)*tanhHessv(X, y, x, D, S) + reg*D);
end