class HiddenMarkov extends ClassifierInt
The HiddenMarkov
classes provides Hidden Markov Models (HMM). An HMM model
consists of a probability vector 'pi' and probability matrices 'a' and 'b'.
The discrete-time system is characterized by a hidden state 'x(t)' and an
observed symbol/value 'y(t)' at time 't', which may be viewed as a time series.
pi(i) = P(x(t) = i) a(i, j) = P(x(t+1) = j | x(t) = i) b(i, k) = P(y(t) = k | x(t) = i)
model (pi, a, b)
- Alphabetic
- By Inheritance
- HiddenMarkov
- ClassifierInt
- Classifier
- Model
- ConfusionFit
- Error
- QoF
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
HiddenMarkov(y: VectoI, m: Int, n: Int, cn_: Strings = null, pi: VectoD = null, a: MatriD = null, b: MatriD = null, hp: HyperParameter = null)
- y
the observation vector/observed discrete-valued time series
- m
the number of observation symbols/values {0, 1, ... m-1}
- n
the number of (hidden) states in the model
- cn_
the class names for the states, e.g., ("Hot", "Cold")
- pi
the probabilty vector for the initial state
- a
the state transition probability matrix (n-by-n)
- b
the observation probability matrix (n-by-m)
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
accuracy: Double
Compute the accuracy of the classification, i.e., the fraction of correct classifications.
Compute the accuracy of the classification, i.e., the fraction of correct classifications. Note, the correct classifications 'tp_i' are in the main diagonal of the confusion matrix.
- Definition Classes
- ConfusionFit
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
backwardEval(): MatriD
The beta-pass: a backward pass from time 't = tt-1' to 0 that computes beta 'bet' with scaling.
The beta-pass: a backward pass from time 't = tt-1' to 0 that computes beta 'bet' with scaling. Requires: 'alp' the scaled alpha matrix 'c' the vector of scaling factors
-
def
backwardEval0(): MatriD
The beta-pass: a backward pass from time 't = tt-1' to 0 that computes beta 'bet'.
-
def
calcCorrelation: MatriD
Calculate the correlation matrix for the feature vectors 'fea'.
Calculate the correlation matrix for the feature vectors 'fea'. If the correlations are too high, the independence assumption may be dubious.
- Definition Classes
- ClassifierInt
-
def
calcCorrelation2(zrg: Range, xrg: Range): MatriD
Calculate the correlation matrix for the feature vectors of Z (Level 3) and those of X (level 2).
Calculate the correlation matrix for the feature vectors of Z (Level 3) and those of X (level 2). If the correlations are too high, the independence assumption may be dubious.
- zrg
the range of Z-columns
- xrg
the range of X-columns
- Definition Classes
- ClassifierInt
-
def
classify(z: VectoI): (Int, String, Double)
Given a new discrete data vector 'z', determine which class it belongs to, returning the best class, its name and its relative probability.
Given a new discrete data vector 'z', determine which class it belongs to, returning the best class, its name and its relative probability.
- z
the observation vector/time series to classify
- Definition Classes
- HiddenMarkov → Classifier
-
def
classify(xx: MatriI = x): VectoI
Classify all of the row vectors in matrix 'xx'.
Classify all of the row vectors in matrix 'xx'.
- xx
the row vectors to classify (defaults to x)
- Definition Classes
- ClassifierInt
-
def
classify(z: VectoD): (Int, String, Double)
Given a new continuous data vector 'z', determine which class it fits into, returning the best class, its name and its relative probability.
Given a new continuous data vector 'z', determine which class it fits into, returning the best class, its name and its relative probability. Override in classes that require precise real values for classification.
- z
the real vector to classify
- Definition Classes
- ClassifierInt → Classifier
-
def
clearConfusion(): Unit
Clear the total cummulative confusion matrix.
Clear the total cummulative confusion matrix.
- Definition Classes
- ConfusionFit
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
var
cn: Strings
- Attributes
- protected
- Definition Classes
- ClassifierInt
-
def
confusion(yp: VectoI, yy: VectoI = y): MatriI
Compare the actual class 'y' vector versus the predicted class 'yp' vector, returning the confusion matrix 'cmat', which for 'k = 2' is
Compare the actual class 'y' vector versus the predicted class 'yp' vector, returning the confusion matrix 'cmat', which for 'k = 2' is
yp 0 1 ---------- y 0 | tn fp | 1 | fn tp | ----------
Note: ScalaTion's confusion matrix is Actual × Predicted, but to swap the position of actual 'y' (rows) with predicted 'yp' (columns) simply use 'cmat.t', the transpose of 'cmat'.
- yp
the precicted class values/labels
- yy
the actual class values/labels for full (y) or test (y_e) dataset
- Definition Classes
- ConfusionFit
- See also
www.dataschool.io/simple-guide-to-confusion-matrix-terminology
-
def
contrast(yp: VectoI, yy: VectoI = y): Unit
Contract the actual class 'yy' vector versus the predicted class 'yp' vector.
Contract the actual class 'yy' vector versus the predicted class 'yp' vector.
- yp
the predicted class values/labels
- yy
the actual class values/labels for full (y) or test (y_e) dataset
- Definition Classes
- ConfusionFit
-
def
crossValidate(nx: Int = 10, show: Boolean = false): Array[Statistic]
Test the accuracy of the classified results by cross-validation, returning the Quality of Fit (QoF) measures such as accuracy.
Test the accuracy of the classified results by cross-validation, returning the Quality of Fit (QoF) measures such as accuracy. This method slices out instances/rows to form the test dataset.
- nx
number of crosses and cross-validations (defaults to 10x).
- show
the show flag (show result from each iteration)
- Definition Classes
- ClassifierInt → Classifier
-
def
crossValidateRand(nx: Int = 10, show: Boolean = false): Array[Statistic]
Test the accuracy of the classified results by cross-validation, returning the Quality of Fit (QoF) measures such as accuracy.
Test the accuracy of the classified results by cross-validation, returning the Quality of Fit (QoF) measures such as accuracy. This method randomizes the instances/rows selected for the test dataset.
- nx
number of crosses and cross-validations (defaults to 10x).
- show
the show flag (show result from each iteration)
- Definition Classes
- ClassifierInt → Classifier
-
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 vector to use (test/full)
- yp
the predicted response vector (test/full)
- w
the weights on the instances (defaults to null)
- ym
the mean of the actual response vector to use (test/full)
- Definition Classes
- ConfusionFit → QoF
- See also
Regression_WLS
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
eval(xx: MatriD, yy: VectoD = null): ClassifierInt
Test the quality of the training with a test dataset and return the fraction of correct classifications.
Test the quality of the training with a test dataset and return the fraction of correct classifications.
- xx
the integer-valued test vectors stored as rows of a matrix
- yy
the classification vector (impl. classes should ignore or default yy to y)
- Definition Classes
- ClassifierInt → Model
-
def
f1_measure(p: Double, r: Double): Double
Compute the F1-measure, i.e., the harmonic mean of the precision and recall.
Compute the F1-measure, i.e., the harmonic mean of the precision and recall.
- p
the precision
- r
the recall
- Definition Classes
- ConfusionFit
-
def
f1v: VectoD
Compute the micro-F1-measure vector, i.e., the harmonic mean of the precision and recall.
Compute the micro-F1-measure vector, i.e., the harmonic mean of the precision and recall.
- Definition Classes
- ConfusionFit
-
def
f_(z: Double): String
Format a double value.
-
def
featureSelection(TOL: Double = 0.01): Unit
Perform feature selection on the classifier.
Perform feature selection on the classifier. Use backward elimination technique, that is, remove the least significant feature, in terms of cross- validation accuracy, in each round.
- TOL
tolerance indicating negligible accuracy loss when removing features
- Definition Classes
- ClassifierInt
-
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.
- Definition Classes
- ConfusionFit → QoF
-
def
fitLabel: Seq[String]
Return the labels for the Quality of Fit (QoF) measures.
Return the labels for the Quality of Fit (QoF) measures. Override to add additional QoF measures.
- Definition Classes
- ConfusionFit → QoF
-
def
fitLabel_v: Seq[String]
Return the labels for the Quality of Fit (QoF) measures.
Return the labels for the Quality of Fit (QoF) measures. Override to add additional QoF measures.
- Definition Classes
- ConfusionFit
-
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
-
def
fitMicroMap: Map[String, VectoD]
Return the Quality of Fit (QoF) vector micor-measures, i.e., measures for each class.
Return the Quality of Fit (QoF) vector micor-measures, i.e., measures for each class.
- Definition Classes
- ConfusionFit
-
final
def
flaw(method: String, message: String): Unit
- Definition Classes
- Error
-
var
fn: Strings
- Attributes
- protected
- Definition Classes
- ClassifierInt
-
def
forwardEval(): MatriD
The alpha-pass: a forward pass from time 't = 0' to 'tt-1' that computes alpha 'alp' with scaling.
-
def
forwardEval0(): MatriD
The alpha-pass: a forward pass from time 't = 0' to 'tt-1' that computes alpha 'alp'.
-
val
fset: Array[Boolean]
the set of features to turn on or off.
the set of features to turn on or off. All features are on by default. Used for feature selection.
- Attributes
- protected
- Definition Classes
- ClassifierInt
-
def
gamma(): MatriD
The gamma-pass: a forward pass from time 't = 0' to 'tt-2' that computes gamma 'gam'.
The gamma-pass: a forward pass from time 't = 0' to 'tt-2' that computes gamma 'gam'. Given the observation vector 'y', find the most probable sequence of states. Requires: 'alp' the unscaled alpha matrix 'bet' the unscaled beta matrix
-
def
getC: VectoD
Return the vector of scaling factors 'c'.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
getY: VectoI
Return the response (class label) vector.
Return the response (class label) vector.
- Definition Classes
- ClassifierInt
-
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
ConfusionFit
class.Return the help string that describes the Quality of Fit (QoF) measures provided by the
ConfusionFit
class. Override to correspond to 'fitLabel'.- Definition Classes
- ConfusionFit → QoF
-
def
hparameter: HyperParameter
Return the model hyper-parameters (if none, return null).
Return the model hyper-parameters (if none, return null). Hyper-parameters may be used to regularize parameters or tune the optimizer.
- Definition Classes
- ClassifierInt → Model
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
jointProb(x: VectoI): Double
Compute the joint probability P(x, y).
Compute the joint probability P(x, y).
- x
the state vector
-
def
kappa: Double
Compute Cohen's 'kappa' coefficient that measures agreement between actual 'y' and predicted 'yp' classifications.
Compute Cohen's 'kappa' coefficient that measures agreement between actual 'y' and predicted 'yp' classifications.
- Definition Classes
- ConfusionFit
- See also
en.wikipedia.org/wiki/Cohen%27s_kappa
-
def
logProbY(scaled: Boolean = false): Double
Compute the -log of the probability of seeing observation vector 'y', given the model 'pi, 'a' and 'b'.
Compute the -log of the probability of seeing observation vector 'y', given the model 'pi, 'a' and 'b'.
- scaled
whether the alpha matrix is scaled Requires: 'alp' the unscaled alpha matrix or 'c' the vector of scaling factors
-
val
m: Int
the number of data vectors in training/test-set (# rows)
the number of data vectors in training/test-set (# rows)
- Attributes
- protected
- Definition Classes
- ClassifierInt
-
val
md: Double
the training-set size as a Double
the training-set size as a Double
- Attributes
- protected
- Definition Classes
- ClassifierInt
-
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
-
val
n: Int
the number of features/variables (# columns)
the number of features/variables (# columns)
- Attributes
- protected
- Definition Classes
- ClassifierInt
-
val
nd: Double
the feature-set size as a Double
the feature-set size as a Double
- Attributes
- protected
- Definition Classes
- ClassifierInt
-
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
p_r_s(): Unit
Compute the micro-precision, micro-recall and micro-specificity vectors which have elements for each class i in {0, 1, ...
Compute the micro-precision, micro-recall and micro-specificity vectors which have elements for each class i in {0, 1, ... k-1}. -------------------------------------------------------------------------- Precision is the fraction classified as true that are actually true. Recall (sensitivity) is the fraction of the actually true that are classified as true. Specificity is the fraction of the actually false that are classified as false. -------------------------------------------------------------------------- Note, for 'k = 2', ordinary precision 'p', recall 'r' and specificity 's' will correspond to the last elements in the 'pv', 'rv' and 'sv' micro vectors.
- Definition Classes
- ConfusionFit
-
def
parameter: VectoD
Return the parameter vector 'pi'.
Return the parameter vector 'pi'.
- Definition Classes
- HiddenMarkov → Model
-
def
parameters: (MatriD, MatriD)
Return the parameter matrices 'a' and 'b'.
-
def
probY(scaled: Boolean = false): Double
Compute the probability of seeing observation vector 'y', given the model 'pi, 'a' and 'b'.
Compute the probability of seeing observation vector 'y', given the model 'pi, 'a' and 'b'.
- scaled
whether the alpha matrix is scaled Requires: 'alp' the unscaled alpha matrix or 'c' the vector of scaling factors
-
def
pseudo_rSq: Double
Compute the Efron's pseudo R-squared value.
Compute the Efron's pseudo R-squared value. Override to McFadden's, etc.
- Definition Classes
- ConfusionFit
-
def
reestimate(): Unit
Re-estimate the probability vector 'pi' and the probability matrices 'a' and 'b'.
Re-estimate the probability vector 'pi' and the probability matrices 'a' and 'b'. Requires: 'gam' the gamma matrix 'gat' the gamma tensor
-
def
report: String
Return a basic report on the trained model.
Return a basic report on the trained model.
- Definition Classes
- HiddenMarkov → ClassifierInt → Model
-
def
reset(): Unit
Reset global variables.
Reset global variables. So far, not needed.
- Definition Classes
- HiddenMarkov → Classifier
-
def
setStream(str: Int = 0): Unit
Set the random number 'stream' to 'str'.
Set the random number 'stream' to 'str'. This is useful for testing purposes, since a fixed stream will follow the same sequence each time.
- str
the new fixed random number stream
- Definition Classes
- Classifier
-
def
shiftToZero(): Unit
Shift the 'x' Matrix so that the minimum value for each column equals zero.
Shift the 'x' Matrix so that the minimum value for each column equals zero.
- Definition Classes
- ClassifierInt
-
def
size: Int
Return the size of the (hidden) state space.
Return the size of the (hidden) state space.
- Definition Classes
- HiddenMarkov → ClassifierInt → Classifier
-
val
stream: Int
the random number stream {0, 1, ..., 999} to be used
the random number stream {0, 1, ..., 999} to be used
- Attributes
- protected
- Definition Classes
- Classifier
-
def
summary(b: VectoD = null, show: Boolean = false): String
Produce a summary report with diagnostics and the overall quality of fit.
Produce a summary report with diagnostics and the overall quality of fit.
- b
the parameters of the model
- show
flag indicating whether to print the summary
- Definition Classes
- ConfusionFit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
test(xx: MatriI, yy: VectoI): Double
Test the quality of the training with a test-set and return the fraction of correct classifications.
Test the quality of the training with a test-set and return the fraction of correct classifications.
- xx
the integer-valued test vectors stored as rows of a matrix
- yy
the test classification vector, where 'yy_i = class' for row 'i' of 'xx'
- Definition Classes
- ClassifierInt
-
def
test(itest: Ints): Double
Test the quality of the training with a test-set and return the fraction of correct classifications.
Test the quality of the training with a test-set and return the fraction of correct classifications.
- itest
indices of the instances considered test data
- Definition Classes
- ClassifierInt → Classifier
-
def
test(testStart: Int, testEnd: Int): Double
Test the quality of the training with a test dataset and return the fraction of correct classifications.
Test the quality of the training with a test dataset and return the fraction of correct classifications. Can be used when the dataset is randomized so that the testing/training part of a dataset corresponds to simple slices of vectors and matrices.
- testStart
the beginning of test region (inclusive).
- testEnd
the end of test region (exclusive).
- Definition Classes
- Classifier
-
def
tn_fp_fn_tp(con: MatriI = cmat): (Double, Double, Double, Double)
Return the confusion matrix for 'k = 2' as a tuple (tn, fp, fn, tp).
Return the confusion matrix for 'k = 2' as a tuple (tn, fp, fn, tp).
- con
the confusion matrix (defaults to cmat)
- Definition Classes
- ConfusionFit
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
total_cmat(): MatriI
Return a copy of the total cummulative confusion matrix 'tcmat' and clear 'tcmat'.
Return a copy of the total cummulative confusion matrix 'tcmat' and clear 'tcmat'.
- Definition Classes
- ConfusionFit
-
def
train(itest: Ints): HiddenMarkov
Train the Hidden Markov Model using the observation vector 'y' to determine the model 'pi, 'a' and 'b'.
Train the Hidden Markov Model using the observation vector 'y' to determine the model 'pi, 'a' and 'b'.
- itest
the indices of the test data
- Definition Classes
- HiddenMarkov → Classifier
-
def
train(xx: MatriD = null, yy: VectoD = null): Classifier
Train the classifier by computing the probabilities from a training dataset of data vectors and their classifications.
Train the classifier by computing the probabilities from a training dataset of data vectors and their classifications. Must be implemented in any extending class. Can be used when the whole dataset is used for training.
- xx
the data/input matrix (impl. classes should ignore or default xx to x)
- yy
the response/classification vector (impl. classes should ignore or default yy to y)
- Definition Classes
- Classifier → Model
-
def
train(testStart: Int, testEnd: Int): Classifier
Train the classifier by computing the probabilities from a training dataset of data vectors and their classifications.
Train the classifier by computing the probabilities from a training dataset of data vectors and their classifications. Must be implemented in any extending class. Can be used when the dataset is randomized so that the training part of a dataset corresponds to simple slices of vectors and matrices.
- testStart
starting index of test region (inclusive) used in cross-validation
- testEnd
ending index of test region (exclusive) used in cross-validation
- Definition Classes
- Classifier
-
def
vc_default: Array[Int]
Return default values for binary input data (value count 'vc' set to 2).
Return default values for binary input data (value count 'vc' set to 2).
- Definition Classes
- ClassifierInt
-
def
vc_fromData: Array[Int]
Return value counts calculated from the input data.
Return value counts calculated from the input data. May wish to call 'shiftToZero' before calling this method.
- Definition Classes
- ClassifierInt
-
def
vc_fromData2(rg: Range): Array[Int]
Return value counts calculated from the input data.
Return value counts calculated from the input data. May wish to call 'shiftToZero' before calling this method.
- rg
the range of columns to be considered
- Definition Classes
- ClassifierInt
-
def
viterbiDecode(): MatriD
The gamma-pass: a forward pass from time 't = 0' to 'tt-2' that computes gamma 'gam' and 'gat'.
The gamma-pass: a forward pass from time 't = 0' to 'tt-2' that computes gamma 'gam' and 'gat'. Given the observation vector 'y', find the most probable sequence of states. Note: 'gat' is computed as a side-effect. Requires: 'alp' the scaled alpha matrix 'bet' the scaled beta matrix
-
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( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated