% Make some data Daten = rand(100, 3); Daten(:,3) = Daten(:,1) + Daten(:,2) + .1*randn(100, 1); % Minimum asymptotic error is .1 [m,n] = size(Daten) ; % Split into train and test P = 0.7 ; Training = Daten(1:round(P*m),:) ; Testing = Daten(round(P*m)+1:end,:); XTr = Training(:,1:n-1); YTr = Training(:,n); XTe = Testing(:,1:n-1); YTe = Testing(:,n); XTrain=num2cell(XTr(:,1)); YTrain=num2cell(YTr(:,1)); XTest=num2cell(XTe); YTest=num2cell(YTe); % Define a train/validation split to use inside the objective function cv = cvpartition(numel(YTrain), 'Holdout', 1/3); % Define hyperparameters to optimize vars = [optimizableVariable('hiddenLayerSize', [1,20], 'Type', 'integer'); optimizableVariable('lr', [1e-3 1], 'Transform', 'log')]; % Optimize minfn = @(T)kfoldLoss(XTrain', YTrain', cv, T.hiddenLayerSize, T.lr); results = bayesopt(minfn, vars,'IsObjectiveDeterministic', false,... 'AcquisitionFunctionName', 'expected-improvement-plus'); T = bestPoint(results); function rmse = kfoldLoss(x, y, cv, numHid, lr) % Train net. net = feedforwardnet(numHid, 'traingd'); net.trainParam.lr = lr; net = train(net, x(:,cv.training), y(:,cv.training)); % Evaluate on validation set and compute rmse ypred = net(x(:, cv.test)); n = size(ypred); pw = 2*ones(n); pw = num2cell(pw); cMinus = cellfun(@minus, ypred, y(cv.test), 'UniformOutput', false); cSquare = cellfun(@power, cMinus, pw, 'UniformOutput', false); cSquareVect = cell2mat(cSquare); cMean = mean(cSquareVect); rmse = sqrt(cMean); %rmse = sqrt(mean((ypred - y(cv.test)).^2)); end
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.