blob: b257804f027c4e52e35091830b82fcff4af05f1e [file] [log] [blame]
#-------------------------------------------------------------
#
# 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.
#
#-------------------------------------------------------------
# generates data to test linear regression
# $1 is number of samples
# $2 is number of features (independent variables)
# $3 is maximum feature value (absolute value)
# $4 is maximum weight (absolute value)
# $5 is location to store generated weights
# $6 is location to store generated data
# $7 is location to store generated labels
# $8 is 0/1. 0 suppresses noise, 1 will add noise to Y
# $9 is b, 0 disables intercept
# $10 controls sparsity in the generated data
# $11 output format
numSamples = $1
numFeatures = $2
maxFeatureValue = $3
maxWeight = $4
addNoise = $8
b = $9
fmt = $11
X = Rand(rows=numSamples, cols=numFeatures, min=-1, max=1, pdf="uniform", seed=0, sparsity=$10)
w = Rand(rows=numFeatures, cols=1, min=-1, max=1, pdf="uniform", seed=0)
X = X * maxFeatureValue
w = w * maxWeight
Y = X %*% w
if(b!=0) {
b_mat = Rand(rows=1, cols=1, min=b, max=b, pdf="uniform")
w = t(append(t(w), b_mat))
Y = Y + b
}
noise = Rand(rows=numSamples, cols=1, pdf="normal", seed=0)
Y = Y + addNoise*noise
write(w, $5, format=fmt)
write(X, $6, format=fmt)
write(Y, $7, format=fmt)