Package aima.core.util.math

Examples of aima.core.util.math.Matrix


  public List<CategoricalDistribution> forwardBackward(
      List<List<AssignmentProposition>> ev, CategoricalDistribution prior) {
    // local variables: fv, a vector of forward messages for steps 0,...,t
    List<Matrix> fv = new ArrayList<Matrix>(ev.size() + 1);
    // b, a representation of the backward message, initially all 1s
    Matrix b = hmm.createUnitMessage();
    // sv, a vector of smoothed estimates for steps 1,...,t
    List<Matrix> sv = new ArrayList<Matrix>(ev.size());

    // fv[0] <- prior
    fv.add(hmm.convert(prior));
View Full Code Here


  public Matrix getEvidence(List<AssignmentProposition> evidence) {
    if (evidence.size() != 1) {
      throw new IllegalArgumentException(
          "Only a single evidence observation value should be provided.");
    }
    Matrix e = sensorModel.get(evidence.get(0).getValue());
    if (null == e) {
      throw new IllegalArgumentException(
          "Evidence does not map to sensor model.");
    }
    return e;
View Full Code Here

  @Override
  public Matrix createUnitMessage() {
    double[] values = new double[stateVariableDomain.size()];
    Arrays.fill(values, 1.0);
    return new Matrix(values, values.length);
  }
View Full Code Here

  }

  @Override
  public Matrix convert(CategoricalDistribution fromCD) {
    double[] values = fromCD.getValues();
    return new Matrix(values, values.length);
  }
View Full Code Here

  }

  @Override
  public Matrix normalize(Matrix m) {
    double[] values = m.getRowPackedCopy();
    return new Matrix(Util.normalize(values), values.length);
  }
View Full Code Here

  // START-ForwardBackwardInference
  @Override
  public List<CategoricalDistribution> forwardBackward(
      List<List<AssignmentProposition>> ev, CategoricalDistribution prior) {
    // local variables: f, the forward message <- prior
    Matrix f = hmm.convert(prior);
    // b, a representation of the backward message, initially all 1s
    Matrix b = hmm.createUnitMessage();
    // sv, a vector of smoothed estimates for steps 1,...,t
    List<Matrix> sv = new ArrayList<Matrix>(ev.size());

    // for i = 1 to t do
    for (int i = 0; i < ev.size(); i++) {
      // fv[i] <- FORWARD(fv[i-1], ev[i])
      f = forward(f, hmm.getEvidence(ev.get(i)));
    }
    // for i = t downto 1 do
    for (int i = ev.size() - 1; i >= 0; i--) {
      // sv[i] <- NORMALIZE(fv[i] * b)
      sv.add(0, hmm.normalize(f.arrayTimes(b)));
      Matrix e = hmm.getEvidence(ev.get(i));
      // b <- BACKWARD(b, ev[i])
      b = backward(b, e);
      // f1:t <-
      // NORMALIZE((T<sup>T<sup>)<sup>-1</sup>O<sup>-1</sup><sub>t+1</sub>f<sub>1:t+1</sub>)
      f = forwardRecover(e, f);
View Full Code Here

   */
  public CategoricalDistribution fixedLagSmoothing(
      List<AssignmentProposition> et) {
    // local variables: <b>O</b><sub>t-d</sub>, <b>O</b><sub>t</sub>,
    // diagonal matrices containing the sensor model information
    Matrix O_tmd, O_t;

    // add e<sub>t</sub> to the end of e<sub>t-d:t</sub>
    e_tmd_to_t.add(hmm.getEvidence(et));
    // <b>O</b><sub>t</sub> <- diagonal matrix containing
    // <b>P</b>(e<sub>t</sub> | X<sub>t</sub>)
    O_t = e_tmd_to_t.get(e_tmd_to_t.size() - 1);
    // if t > d then
    if (t > d) {
      // remove e<sub>t-d-1</sub> from the beginning of e<sub>t-d:t</sub>
      e_tmd_to_t.remove(0);
      // <b>O</b><sub>t-d</sub> <- diagonal matrix containing
      // <b>P</b>(e<sub>t-d</sub> | X<sub>t-d</sub>)
      O_tmd = e_tmd_to_t.get(0);
      // <b>f</b> <- FORWARD(<b>f</b>, e<sub>t-d</sub>)
      f = forward(f, O_tmd);
      // <b>B</b> <-
      // <b>O</b><sup>-1</sup><sub>t-d</sub><b>B</b><b>T</b><b>O</b><sub>t</sub>
      B = O_tmd.inverse().times(hmm.getTransitionModel().inverse())
          .times(B).times(hmm.getTransitionModel()).times(O_t);
    } else {
      // else <b>B</b> <- <b>BTO</b><sub>t</sub>
      B = B.times(hmm.getTransitionModel()).times(O_t);
    }
View Full Code Here

*
*/
public class HMMExampleFactory {

  public static HiddenMarkovModel getUmbrellaWorldModel() {
    Matrix transitionModel = new Matrix(new double[][] { { 0.7, 0.3 },
        { 0.3, 0.7 } });
    Map<Object, Matrix> sensorModel = new HashMap<Object, Matrix>();
    sensorModel.put(Boolean.TRUE, new Matrix(new double[][] { { 0.9, 0.0 },
        { 0.0, 0.2 } }));
    sensorModel.put(Boolean.FALSE, new Matrix(new double[][] {
        { 0.1, 0.0 }, { 0.0, 0.8 } }));
    Matrix prior = new Matrix(new double[] { 0.5, 0.5 }, 2);
    return new HMM(ExampleRV.RAIN_t_RV, transitionModel, sensorModel, prior);
  }
View Full Code Here

    lastInput = input;
    return layer.feedForward(input);
  }

  public void processError(Vector error) {
    Matrix weightUpdate = error.times(lastInput.transpose());
    layer.acceptNewWeightUpdate(weightUpdate);

    Vector biasUpdate = layer.getBiasVector().plus(error);
    layer.acceptNewBiasUpdate(biasUpdate);
View Full Code Here

  public Layer(Matrix weightMatrix, Vector biasVector, ActivationFunction af) {

    activationFunction = af;
    this.weightMatrix = weightMatrix;
    lastWeightUpdateMatrix = new Matrix(weightMatrix.getRowDimension(),
        weightMatrix.getColumnDimension());
    penultimateWeightUpdateMatrix = new Matrix(
        weightMatrix.getRowDimension(),
        weightMatrix.getColumnDimension());

    this.biasVector = biasVector;
    lastBiasUpdateVector = new Vector(biasVector.getRowDimension());
View Full Code Here

TOP

Related Classes of aima.core.util.math.Matrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.