| #------------------------------------------------------------- |
| # |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| # |
| #------------------------------------------------------------- |
| |
| l2norm = function(Matrix[Double] X, Matrix[Double] y, Matrix[Double] B) return (Matrix[Double] loss) { |
| loss = as.matrix(sum((y - X%*%B)^2)); |
| } |
| |
| X = read($1); |
| y = read($2); |
| numTrSamples = 100; |
| numValSamples = 100; |
| |
| X_train = X[1:numTrSamples,]; |
| y_train = y[1:numTrSamples,]; |
| X_val = X[(numTrSamples+1):(numTrSamples+numValSamples+1),]; |
| y_val = y[(numTrSamples+1):(numTrSamples+numValSamples+1),]; |
| X_test = X[(numTrSamples+numValSamples+2):nrow(X),]; |
| y_test = y[(numTrSamples+numValSamples+2):nrow(X),]; |
| |
| params = list("reg"); |
| paramRanges = matrix("0 20", rows=1, cols=2); |
| |
| [bestWeights, optHyperParams] = hyperband(X_train=X_train, y_train=y_train, |
| X_val=X_val, y_val=y_val, params=params, paramRanges=paramRanges); |
| |
| paramRanges2 = list(10^seq(0,-4)) |
| trainArgs = list(X=X_train, y=y_train, icpt=0, reg=-1, tol=1e-9, maxi=0, verbose=FALSE); |
| [bestWeights, optHyperParams2] = gridSearch(X=X_train, y=y_train, numB=ncol(X), |
| train="lm", predict="l2norm", trainArgs=trainArgs, params=params, paramValues=paramRanges2); |
| |
| print(toString(optHyperParams)) |
| print(toString(optHyperParams2)) |