class Perceptron extends PredictorMat
The Perceptron
class supports single-output, 2-layer (input and output)
Neural-Networks. Although perceptrons are typically used for classification,
this class is used for prediction. Given several input vectors and output
values (training data), fit the weights/parameters 'b' connecting the layers,
so that for a new input vector 'z', the net can predict the output value, i.e.,
z = f (b dot z)
The parameter vector 'b' (w) gives the weights between input and output layers. Note, 'b0' is treated as the bias, so 'x0' must be 1.0.
- Alphabetic
- By Inheritance
- Perceptron
- PredictorMat
- Predictor
- Model
- Fit
- Error
- QoF
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
Perceptron(x: MatriD, y: VectoD, fname_: Strings = null, hparam: HyperParameter = Optimizer.hp, f: AFF = f_sigmoid, itran: FunctionV_2V = null)
- x
the data/input m-by-n matrix (data consisting of m input vectors)
- y
the response/output m-vector (data consisting of m output values)
- fname_
the feature/variable names
- hparam
the hyper-parameters for the model/network
- f
the activation function family for layers 1->2 (input to output)
- itran
the inverse transformation function returns responses to original scale
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
analyze(x_: MatriD = x, y_: VectoD = y, x_e: MatriD = x, y_e: VectoD = y): PredictorMat
Analyze a dataset using this model using ordinary training with the 'train' method.
Analyze a dataset using this model using ordinary training with the 'train' method.
- x_
the training/full data/input matrix
- y_
the training/full response/output vector
- x_e
the test/full data/input matrix
- y_e
the test/full response/output vector
- Definition Classes
- PredictorMat → Predictor
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
var
b: VectoD
- Attributes
- protected
- Definition Classes
- PredictorMat
-
def
backwardElim(cols: Set[Int], index_q: Int = index_rSqBar, first: Int = 1): (Int, PredictorMat)
Perform backward elimination to find the least predictive variable to remove from the existing model, returning the variable to eliminate, the new parameter vector and the new Quality of Fit (QoF).
Perform backward elimination to find the least predictive variable to remove from the existing model, returning the variable to eliminate, the new parameter vector and the new Quality of Fit (QoF). May be called repeatedly.
- cols
the columns of matrix x currently included in the existing model
- index_q
index of Quality of Fit (QoF) to use for comparing quality
- first
first variable to consider for elimination (default (1) assume intercept x_0 will be in any model)
- Definition Classes
- PredictorMat
- See also
Fit
for index of QoF measures.
-
def
backwardElimAll(index_q: Int = index_rSqBar, first: Int = 1, cross: Boolean = true): (Set[Int], MatriD)
Perform backward elimination to find the least predictive variables to remove from the full model, returning the variables left and the new Quality of Fit (QoF) measures for all steps.
Perform backward elimination to find the least predictive variables to remove from the full model, returning the variables left and the new Quality of Fit (QoF) measures for all steps.
- index_q
index of Quality of Fit (QoF) to use for comparing quality
- first
first variable to consider for elimination
- cross
whether to include the cross-validation QoF measure
- Definition Classes
- PredictorMat
- See also
Fit
for index of QoF measures.
-
def
buildModel(x_cols: MatriD): Perceptron
Build a sub-model that is restricted to the given columns of the data matrix.
Build a sub-model that is restricted to the given columns of the data matrix.
- x_cols
the columns that the new model is restricted to
- Definition Classes
- Perceptron → PredictorMat
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
def
corrMatrix(xx: MatriD = x): MatriD
Return the correlation matrix for the columns in data matrix 'xx'.
Return the correlation matrix for the columns in data matrix 'xx'.
- xx
the data matrix shose correlation matrix is sought
- Definition Classes
- PredictorMat → Predictor
-
def
crossValidate(k: Int = 10, rando: Boolean = true): Array[Statistic]
- Definition Classes
- PredictorMat
-
def
diagnose(e: VectoD, yy: VectoD, yp: VectoD, w: VectoD = null, ym_: Double = noDouble): Unit
Diagnose the health of the model by computing the Quality of Fit (QoF) measures, from the error/residual vector and the predicted & actual responses.
Diagnose the health of the model by computing the Quality of Fit (QoF) measures, from the error/residual vector and the predicted & actual responses. For some models the instances may be weighted.
- e
the m-dimensional error/residual vector (yy - yp)
- yy
the actual response/output vector to use (test/full)
- yp
the predicted response/output vector (test/full)
- w
the weights on the instances (defaults to null)
- ym_
the mean of the actual response/output vector to use (training/full)
-
var
e: VectoD
- Attributes
- protected
- Definition Classes
- PredictorMat
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
eval(ym: Double, y_e: VectoD, yp: VectoD): PredictorMat
Compute the error (difference between actual and predicted) and useful diagnostics for the test dataset.
Compute the error (difference between actual and predicted) and useful diagnostics for the test dataset. Requires predicted responses to be passed in.
- ym
the training/full mean actual response/output vector
- y_e
the test/full actual response/output vector
- yp
the test/full predicted response/output vector
- Definition Classes
- PredictorMat
-
def
eval(x_e: MatriD = x, y_e: VectoD = y): PredictorMat
Compute the error (difference between actual and predicted) and useful diagnostics for the test dataset.
Compute the error (difference between actual and predicted) and useful diagnostics for the test dataset.
- x_e
the test/full data/input matrix (defualts to full x)
- y_e
the test/full response/output vector (defualts to full y)
- Definition Classes
- PredictorMat → Model
-
def
f_(z: Double): String
Format a double value.
-
def
fit: VectoD
Return the Quality of Fit (QoF) measures corresponding to the labels given above in the 'fitLabel' method.
Return the Quality of Fit (QoF) measures corresponding to the labels given above in the 'fitLabel' method. Note, if 'sse > sst', the model introduces errors and the 'rSq' may be negative, otherwise, R^2 ('rSq') ranges from 0 (weak) to 1 (strong). Override to add more quality of fit measures.
-
def
fitLabel: Seq[String]
Return the labels for the Quality of Fit (QoF) measures.
-
def
fitMap: Map[String, String]
Build a map of quality of fit measures (use of
LinkedHashMap
makes it ordered).Build a map of quality of fit measures (use of
LinkedHashMap
makes it ordered).- Definition Classes
- QoF
-
final
def
flaw(method: String, message: String): Unit
- Definition Classes
- Error
-
var
fname: Strings
- Attributes
- protected
- Definition Classes
- PredictorMat
-
def
forwardSel(cols: Set[Int], index_q: Int = index_rSqBar): (Int, PredictorMat)
Perform forward selection to find the most predictive variable to add the existing model, returning the variable to add and the new model.
Perform forward selection to find the most predictive variable to add the existing model, returning the variable to add and the new model. May be called repeatedly.
- cols
the columns of matrix x currently included in the existing model
- index_q
index of Quality of Fit (QoF) to use for comparing quality
- Definition Classes
- PredictorMat → Predictor
- See also
Fit
for index of QoF measures.
-
def
forwardSelAll(index_q: Int = index_rSqBar, cross: Boolean = true): (Set[Int], MatriD)
Perform forward selection to find the most predictive variables to have in the model, returning the variables added and the new Quality of Fit (QoF) measures for all steps.
Perform forward selection to find the most predictive variables to have in the model, returning the variables added and the new Quality of Fit (QoF) measures for all steps.
- index_q
index of Quality of Fit (QoF) to use for comparing quality
- cross
whether to include the cross-validation QoF measure
- Definition Classes
- PredictorMat
- See also
Fit
for index of QoF measures.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
getX: MatriD
Return the 'used' data matrix 'x'.
Return the 'used' data matrix 'x'. Mainly for derived classes where 'x' is expanded from the given columns in 'x_', e.g.,
QuadRegression
add squared columns.- Definition Classes
- PredictorMat → Predictor
-
def
getY: VectoD
Return the 'used' response vector 'y'.
Return the 'used' response vector 'y'. Mainly for derived classes where 'y' is transformed, e.g.,
TranRegression
,Regression4TS
.- Definition Classes
- PredictorMat → Predictor
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
help: String
Return the help string that describes the Quality of Fit (QoF) measures provided by the
Fit
class. -
def
hparameter: HyperParameter
Return the hyper-parameters.
Return the hyper-parameters.
- Definition Classes
- PredictorMat → Model
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val itran: FunctionV_2V
-
val
k: Int
- Attributes
- protected
- Definition Classes
- PredictorMat
-
def
ll(ms: Double = mse0, s2: Double = sig2e, m2: Int = m): Double
The log-likelihood function times -2.
The log-likelihood function times -2. Override as needed.
- ms
raw Mean Squared Error
- s2
MLE estimate of the population variance of the residuals
- Definition Classes
- Fit
- See also
www.stat.cmu.edu/~cshalizi/mreg/15/lectures/06/lecture-06.pdf
www.wiley.com/en-us/Introduction+to+Linear+Regression+Analysis%2C+5th+Edition-p-9780470542811 Section 2.11
-
val
m: Int
- Attributes
- protected
- Definition Classes
- PredictorMat
-
val
modelConcept: URI
An optional reference to an ontological concept
An optional reference to an ontological concept
- Definition Classes
- Model
-
def
modelName: String
An optional name for the model (or modeling technique)
An optional name for the model (or modeling technique)
- Definition Classes
- Model
-
def
mse_: Double
Return the mean of squares for error (sse / df._2).
Return the mean of squares for error (sse / df._2). Must call diagnose first.
- Definition Classes
- Fit
-
val
n: Int
- Attributes
- protected
- Definition Classes
- PredictorMat
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
parameter: VectoD
Return the vector of parameter/coefficient values.
Return the vector of parameter/coefficient values.
- Definition Classes
- PredictorMat → Model
-
def
predict(z: MatriD = x): VectoD
Given a new input matrix 'z', predict the output/response value 'f(z)'.
Given a new input matrix 'z', predict the output/response value 'f(z)'.
- z
the new input matrix
- Definition Classes
- Perceptron → PredictorMat → Predictor
-
def
predict(z: VectoD): Double
Given a new input vector 'z', predict the output/response value 'f(z)'.
Given a new input vector 'z', predict the output/response value 'f(z)'.
- z
the new input vector
- Definition Classes
- Perceptron → PredictorMat → Predictor
-
def
predict(z: VectoI): Double
Given a new discrete data/input vector 'z', predict the 'y'-value of 'f(z)'.
Given a new discrete data/input vector 'z', predict the 'y'-value of 'f(z)'.
- z
the vector to use for prediction
- Definition Classes
- Predictor
-
def
report: String
Return a basic report on the trained model.
Return a basic report on the trained model.
- Definition Classes
- PredictorMat → Model
- See also
'summary' method for more details
-
def
reset(eta_: Double): Unit
Reset the learning rate 'eta'.
-
def
resetDF(df_update: PairD): Unit
Reset the degrees of freedom to the new updated values.
Reset the degrees of freedom to the new updated values. For some models, the degrees of freedom is not known until after the model is built.
- df_update
the updated degrees of freedom (model, error)
- Definition Classes
- Fit
-
def
residual: VectoD
Return the vector of residuals/errors.
Return the vector of residuals/errors.
- Definition Classes
- PredictorMat → Predictor
-
def
reverse(a: MatriD): MatriD
Return a matrix that is in reverse row order of the given matrix 'a'.
Return a matrix that is in reverse row order of the given matrix 'a'.
- a
the given matrix
- Definition Classes
- PredictorMat
-
def
setWeights(w0: VectoD): Unit
Set the initial parameter/weight vector 'b' manually before training.
Set the initial parameter/weight vector 'b' manually before training. This is mainly for testing purposes.
- w0
the initial weights for b
-
var
sig2e: Double
- Attributes
- protected
- Definition Classes
- Fit
-
def
stepRegressionAll(index_q: Int = index_rSqBar, cross: Boolean = true): (Set[Int], MatriD)
Perform stepwise regression to find the most predictive variables to have in the model, returning the variables left and the new Quality of Fit (QoF) measures for all steps.
Perform stepwise regression to find the most predictive variables to have in the model, returning the variables left and the new Quality of Fit (QoF) measures for all steps. At each step it calls 'forwardSel' and 'backwardElim' and takes the best of the two actions. Stops when neither action yields improvement.
- index_q
index of Quality of Fit (QoF) to use for comparing quality
- cross
whether to include the cross-validation QoF measure
- Definition Classes
- PredictorMat
- See also
Fit
for index of QoF measures.
-
def
summary: String
Compute and return summary diagostics for the regression model.
Compute and return summary diagostics for the regression model.
- Definition Classes
- PredictorMat
-
def
summary(b: VectoD, stdErr: VectoD, vf: VectoD, show: Boolean = false): String
Produce a summary report with diagnostics for each predictor 'x_j' and the overall quality of fit.
Produce a summary report with diagnostics for each predictor 'x_j' and the overall quality of fit.
- b
the parameters/coefficients for the model
- vf
the Variance Inflation Factors (VIFs)
- show
flag indicating whether to print the summary
- Definition Classes
- Fit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
test(modelName: String, doPlot: Boolean = true): Unit
Test the model on the full dataset (i.e., train and evaluate on full dataset).
Test the model on the full dataset (i.e., train and evaluate on full dataset).
- modelName
the name of the model being tested
- doPlot
whether to plot the actual vs. predicted response
- Definition Classes
- Predictor
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
train(x_: MatriD = x, y_: VectoD = y): Perceptron
Given training data 'x_' and 'y_', fit the parameter/weight vector 'b'.
Given training data 'x_' and 'y_', fit the parameter/weight vector 'b'. Minimize the error in the prediction by adjusting the weight vector 'b'. Iterate over several epochs, where each epoch divides the training set into 'nbat' batches. Each batch is used to update the weights.
- x_
the training/full data/input matrix
- y_
the training/full response/output vector
- Definition Classes
- Perceptron → PredictorMat → Model
-
def
train0(x_: MatriD = x, y_: VectoD = y): Perceptron
Given training data 'x_' and 'y_', fit the parameter/weight vector 'b'.
Given training data 'x_' and 'y_', fit the parameter/weight vector 'b'. Minimize the error in the prediction by adjusting the weight vector 'b'. The error 'e' is simply the difference between the target value 'y_' and the predicted value 'yp'. Minimize the dot product of error with itself using gradient-descent (move in the opposite direction of the gradient). Iterate over several epochs (no batching). Use val d = yp * (_1 - yp) * e // delta y (for sigmoid only)
- x_
the training/full data/input matrix
- y_
the training/full response/output vector
-
def
train2(x_: MatriD = x, y_: VectoD = y): Perceptron
Given training data 'x_' and 'y_', fit the parameter/weight vector 'b'.
Given training data 'x_' and 'y_', fit the parameter/weight vector 'b'. Minimize the error in the prediction by adjusting the weight vector 'b'. Iterate over several epochs, where each epoch divides the training set into 'nbat' batches. Each batch is used to update the weights. This version preforms an interval search for the best 'eta' value.
- x_
the training/full data/input matrix
- y_
the training/full response/output vector
- Definition Classes
- Perceptron → PredictorMat
-
def
trainSwitch(which: Int, x_: MatriD = x, y_: VectoD = y): Perceptron
Switch between 'train' methods: simple (0), regular (1) and hyper-parameter optimizing (2).
Switch between 'train' methods: simple (0), regular (1) and hyper-parameter optimizing (2).
- which
the kind of 'train' method to use
- x_
the training/full data/input matrix
- y_
the training/full response/output vector
-
def
vif(skip: Int = 1): VectoD
Compute the Variance Inflation Factor 'VIF' for each variable to test for multi-collinearity by regressing 'x_j' against the rest of the variables.
Compute the Variance Inflation Factor 'VIF' for each variable to test for multi-collinearity by regressing 'x_j' against the rest of the variables. A VIF over 10 indicates that over 90% of the variance of 'x_j' can be predicted from the other variables, so 'x_j' may be a candidate for removal from the model. Note: override this method to use a superior regression technique.
- skip
the number of columns of x at the beginning to skip in computing VIF
- Definition Classes
- PredictorMat
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
val
x: MatriD
- Attributes
- protected
- Definition Classes
- PredictorMat
-
val
y: VectoD
- Attributes
- protected
- Definition Classes
- PredictorMat
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated