/** * Computes the stochastic transition-probability matrix from the * given probabilities. * @param alphan * Result of the forward pass through the HMM at time n * @param betanp1 * Result of the backward pass through the HMM at time n+1 * @param bnp1 * Conditionally independent likelihoods of each observation at time n+1 * @return * Transition probabilities at time n */ protected static Matrix computeTransitions( Vector alphan, Vector betanp1, Vector bnp1 ) { Vector bnext = bnp1.dotTimes(betanp1); return bnext.outerProduct(alphan); }
/** * Computes the stochastic transition-probability matrix from the * given probabilities. * @param alphan * Result of the forward pass through the HMM at time n * @param betanp1 * Result of the backward pass through the HMM at time n+1 * @param bnp1 * Conditionally independent likelihoods of each observation at time n+1 * @return * Transition probabilities at time n */ protected static Matrix computeTransitions( Vector alphan, Vector betanp1, Vector bnp1 ) { Vector bnext = bnp1.dotTimes(betanp1); return bnext.outerProduct(alphan); }
/** * Computes the stochastic transition-probability matrix from the * given probabilities. * @param alphan * Result of the forward pass through the HMM at time n * @param betanp1 * Result of the backward pass through the HMM at time n+1 * @param bnp1 * Conditionally independent likelihoods of each observation at time n+1 * @return * Transition probabilities at time n */ protected static Matrix computeTransitions( Vector alphan, Vector betanp1, Vector bnp1 ) { Vector bnext = bnp1.dotTimes(betanp1); return bnext.outerProduct(alphan); }
/** * Computes the probability of the various states at a time instance given * the observation sequence. Rabiner calls this the "gamma". * @param alpha * Forward probability at time n. * @param beta * Backward probability at time n. * @param scaleFactor * Amount to scale the gamma by * @return * Gamma at time n. */ protected static Vector computeStateObservationLikelihood( Vector alpha, Vector beta, double scaleFactor ) { Vector gamma = alpha.dotTimes(beta); gamma.scaleEquals(scaleFactor/gamma.norm1()); return gamma; }
/** * Computes the probability of the various states at a time instance given * the observation sequence. Rabiner calls this the "gamma". * @param alpha * Forward probability at time n. * @param beta * Backward probability at time n. * @param scaleFactor * Amount to scale the gamma by * @return * Gamma at time n. */ protected static Vector computeStateObservationLikelihood( Vector alpha, Vector beta, double scaleFactor ) { Vector gamma = alpha.dotTimes(beta); gamma.scaleEquals(scaleFactor/gamma.norm1()); return gamma; }
/** * Computes the probability of the various states at a time instance given * the observation sequence. Rabiner calls this the "gamma". * @param alpha * Forward probability at time n. * @param beta * Backward probability at time n. * @param scaleFactor * Amount to scale the gamma by * @return * Gamma at time n. */ protected static Vector computeStateObservationLikelihood( Vector alpha, Vector beta, double scaleFactor ) { Vector gamma = alpha.dotTimes(beta); gamma.scaleEquals(scaleFactor/gamma.norm1()); return gamma; }
ArrayList<WeightedValue<Vector>> weightedAlphas = new ArrayList<WeightedValue<Vector>>( N ); Vector alpha = b.get(0).dotTimes( this.getInitialProbability() ); double weight; if( normalize )
ArrayList<WeightedValue<Vector>> weightedAlphas = new ArrayList<WeightedValue<Vector>>( N ); Vector alpha = b.get(0).dotTimes( this.getInitialProbability() ); double weight; if( normalize )
final int k = this.getNumStates(); ArrayList<Vector> bs = this.computeObservationLikelihoods(observations); Vector delta = this.getInitialProbability().dotTimes( bs.get(0) ); ArrayList<int[]> psis = new ArrayList<int[]>( N ); int[] psi = new int[ k ];
ArrayList<WeightedValue<Vector>> weightedAlphas = new ArrayList<WeightedValue<Vector>>( N ); Vector alpha = b.get(0).dotTimes( this.getInitialProbability() ); double weight; if( normalize )
final int k = this.getNumStates(); ArrayList<Vector> bs = this.computeObservationLikelihoods(observations); Vector delta = this.getInitialProbability().dotTimes( bs.get(0) ); ArrayList<int[]> psis = new ArrayList<int[]>( N ); int[] psi = new int[ k ];
final int k = this.getNumStates(); ArrayList<Vector> bs = this.computeObservationLikelihoods(observations); Vector delta = this.getInitialProbability().dotTimes( bs.get(0) ); ArrayList<int[]> psis = new ArrayList<int[]>( N ); int[] psi = new int[ k ];
/** * Computes the backward probability recursion. * @param beta * Beta from the "next" time step. * @param b * Observation likelihood from the "next" time step. * @param weight * Weight to use for the current time step. * @return * Beta for the previous time step, weighted by "weight". */ protected WeightedValue<Vector> computeBackwardProbabilities( Vector beta, Vector b, double weight ) { Vector betaPrevious = b.dotTimes(beta); betaPrevious = betaPrevious.times( this.getTransitionProbability() ); if( weight != 1.0 ) { betaPrevious.scaleEquals(weight); } return new DefaultWeightedValue<Vector>( betaPrevious, weight ); }
/** * Computes the backward probability recursion. * @param beta * Beta from the "next" time step. * @param b * Observation likelihood from the "next" time step. * @param weight * Weight to use for the current time step. * @return * Beta for the previous time step, weighted by "weight". */ protected WeightedValue<Vector> computeBackwardProbabilities( Vector beta, Vector b, double weight ) { Vector betaPrevious = b.dotTimes(beta); betaPrevious = betaPrevious.times( this.getTransitionProbability() ); if( weight != 1.0 ) { betaPrevious.scaleEquals(weight); } return new DefaultWeightedValue<Vector>( betaPrevious, weight ); }
/** * Computes the backward probability recursion. * @param beta * Beta from the "next" time step. * @param b * Observation likelihood from the "next" time step. * @param weight * Weight to use for the current time step. * @return * Beta for the previous time step, weighted by "weight". */ protected WeightedValue<Vector> computeBackwardProbabilities( Vector beta, Vector b, double weight ) { Vector betaPrevious = b.dotTimes(beta); betaPrevious = betaPrevious.times( this.getTransitionProbability() ); if( weight != 1.0 ) { betaPrevious.scaleEquals(weight); } return new DefaultWeightedValue<Vector>( betaPrevious, weight ); }
@Override public UnivariateGaussian evaluateAsGaussian( final Vectorizable input) { if (!this.isInitialized()) { // Variance is not yet initialized. return new UnivariateGaussian(); } else { final Vector x = input.convertToVector(); return new UnivariateGaussian( this.evaluateAsDouble(x), x.dotProduct(x.dotTimes(this.getVariance()))); } }
sumsOfSquaresAccumulator.accumulate(vector.dotTimes(vector));
sumsOfSquaresAccumulator.accumulate(vector.dotTimes(vector));
@Override public UnivariateGaussian evaluateAsGaussian( final Vectorizable input) { if (!this.isInitialized()) { // Variance is not yet initialized. return new UnivariateGaussian(); } else { final Vector x = input.convertToVector(); return new UnivariateGaussian( this.evaluateAsDouble(x), x.dotProduct(x.dotTimes(this.getVariance()))); } }
@Override public UnivariateGaussian evaluateAsGaussian( final Vectorizable input) { if (!this.isInitialized()) { // Variance is not yet initialized. return new UnivariateGaussian(); } else { final Vector x = input.convertToVector(); return new UnivariateGaussian( this.evaluateAsDouble(x), x.dotProduct(x.dotTimes(this.getVariance()))); } }