You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: test_sampled_newton.m
    path of file: ./repos/SGDLibrary/gd_test
    
    the code of the file until where you have to start completion: function test_sampled_newton()

    clc;
    clear;
    close all;

    
    %% Set algorithms
    algorithms = {'L-BFGS-BKT','Newton-CHOLESKY','Newton-INEXACT','Subsamp-Newton-Uniform', 'Subsamp-Newton-RNS', 'Subsamp-Newton-LS'};
    


    % select problem
    problem_type = 'log_reg';
    %problem_type = 'lin_reg';
    
    lambda = 0.01;
     
    % prepare datasets
    if strcmp(problem_type, 'lin_reg')
        

    
function test_sampled_newton()

    clc;
    clear;
    close all;

    
    %% Set algorithms
    algorithms = {'L-BFGS-BKT','Newton-CHOLESKY','Newton-INEXACT','Subsamp-Newton-Uniform', 'Subsamp-Newton-RNS', 'Subsamp-Newton-LS'};
    


    % select problem
    problem_type = 'log_reg';
    %problem_type = 'lin_reg';
    
    lambda = 0.01;
     
    % prepare datasets
    if strcmp(problem_type, 'lin_reg')
        
        % generate synthtic data
        % sample data generating for training: y = w1*x1 + w2*x2 + ... * wd*1
        n = 10000;
        d = 10;
        std = 0.25;
        data = linear_regression_data_generator(n, d, std);
        
        x_train = data.x_train;
        y_train = data.y_train;    
        x_test = data.x_test;
        y_test = data.y_test;
        
        % solution
        w_opt = pinv(x_train * x_train') * x_train * y_train';
        % for intersect
        d = d + 1;          


        % define problem definitions
        problem = linear_regression(x_train, y_train, x_test, y_test, lambda);    
        f_opt1 = problem.cost(w_opt);
        fprintf('f_opt: %.16e\n', f_opt1);
        
        w_opt = problem.calc_solution(100, 'lbfgs');
        f_opt2 = problem.cost(w_opt); 
        fprintf('f_opt1: %.16e, f_opt2: %.16e, diff: %.16e\n', f_opt1, f_opt2, f_opt2 - f_opt1);    
        
        if f_opt2 < f_opt1
            f_opt = f_opt2;
        else
            f_opt = f_opt1;
        end