optimal values for cell data
Show older comments
4 Comments
Walter Roberson
on 10 Mar 2020
We are getting pretty strict there needing to be a really good reason for deleting a Question that has a valid attempt at an Answer. We are having too much trouble with people attempting to use the resource for free private consulting -- posting something, getting their free answer, and then demanding that the question be removed.
Stephen23
on 10 Mar 2020
@Ali: when you posted your question here you agreed to the terms and conditions given here:
This means that your posted content is released under Creative Commons Attribution Share Alike 3.0 license, and as such anyone can copy and distribute your posted content with the appropriate attribution.
Internet archiving websites have likely already saved publicly-available copies of this page.
Summary: if you do not want sensitive data available on the internet, do not post it.
Walter Roberson
on 10 Mar 2020
- Every student claims that their code is "sensitive" on the grounds that other students might read the posting and copy from them.
- There are no National Security considerations here.
- If there are Trade Secret matters here, then legally speaking you destroyed the "secret" as soon as you posted the material (Trade Secret case law is really strict on that point. Like if a piece of paper with a Trade Secret blows out of your hand and someone finds it, then you have just lost Trade Secret status.)
- You would have a difficult time convincing us that you are working on a Patent: people working on Patents know to hire consultants with Non-Disclosure Agreements
When I look at your previous postings, the most generous reading I can come up with is that you must might be working on a thesis. For thesis, the important part is that the ideas are yours; it is permitted to seek assistance with implementation .
Accepted Answer
More Answers (1)
Nipun Katyal
on 4 Mar 2020
Inorder to perform operations on cells use cellfun as mentioned below:
% 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));
cMinus = cellfun(@minus, ypred, y(cv.test), 'UniformOutput', false);
cMean = cellfun(@mean, cMinus);
rmse = sqrt(cMean);
%rmse = sqrt(mean((ypred - y(cv.test)).^2));
end
1 Comment
Nipun Katyal
on 4 Mar 2020
In your case the rmse function will be:
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);
cMean = cellfun(@mean, cSquare);
rmse = sqrt(cMean);
%rmse = sqrt(mean((ypred - y(cv.test)).^2));
end
Categories
Find more on Function Approximation and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
