Package aima.core.util.math

Examples of aima.core.util.math.Matrix


  public Layer(int numberOfNeurons, int numberOfInputs,
      double lowerLimitForWeights, double upperLimitForWeights,
      ActivationFunction af) {

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

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


    initializeVector(biasVector, lowerLimitForWeights, upperLimitForWeights);
  }

  public Vector feedForward(Vector inputVector) {
    lastInput = inputVector;
    Matrix inducedField = weightMatrix.times(inputVector).plus(biasVector);

    Vector inducedFieldVector = new Vector(numberOfNeurons());
    for (int i = 0; i < numberOfNeurons(); i++) {
      inducedFieldVector.setValue(i, inducedField.get(i, 0));
    }

    lastInducedField = inducedFieldVector.copyVector();
    Vector resultVector = new Vector(numberOfNeurons());
    for (int i = 0; i < numberOfNeurons(); i++) {
View Full Code Here

  public void updateWeights() {
    weightMatrix.plusEquals(lastWeightUpdateMatrix);
  }

  public void updateBiases() {
    Matrix biasMatrix = biasVector.plusEquals(lastBiasUpdateVector);
    Vector result = new Vector(biasMatrix.getRowDimension());
    for (int i = 0; i < biasMatrix.getRowDimension(); i++) {
      result.setValue(i, biasMatrix.get(i, 0));
    }
    biasVector = result;
  }
View Full Code Here

    List<Double> values = new ArrayList<Double>();
    // for (String state : aBelief.states()) {
    for (String state : states) {
      values.add(get(state, perception));
    }
    Matrix OMatrix = Matrix.createDiagonalMatrix(values);
    return OMatrix;
  }
View Full Code Here

  }

  public VarDistribution predict(VarDistribution aBelief, String action) {
    VarDistribution newBelief = aBelief.duplicate();

    Matrix beliefMatrix = aBelief.asMatrix();
    Matrix transitionMatrix = transitionModel.asMatrix(action);
    Matrix predicted = transitionMatrix.transpose().times(beliefMatrix);
    newBelief.updateFrom(predicted);
    return newBelief;
  }
View Full Code Here

  public VarDistribution perceptionUpdate(VarDistribution aBelief,
      String perception) {
    VarDistribution newBelief = aBelief.duplicate();

    // one way - use matrices
    Matrix beliefMatrix = aBelief.asMatrix();
    Matrix o_matrix = sensorModel.asMatrix(perception);
    Matrix updated = o_matrix.times(beliefMatrix);
    newBelief.updateFrom(updated);
    newBelief.normalize();
    return newBelief;

    // alternate way of doing this. clearer in intent.
View Full Code Here

  public VarDistribution calculate_next_backward_message(
      VarDistribution present_backward_message, String perception) {
    VarDistribution result = present_backward_message.duplicate();
    // System.out.println("fb :-calculating new backward message");
    // System.out.println("fb :-diagonal matrix from sens model = ");
    Matrix oMatrix = sensorModel.asMatrix(perception);
    // System.out.println(oMatrix);
    Matrix transitionMatrix = transitionModel.asMatrix();// action
    // should
    // be
    // passed
    // in
    // here?
    // System.out.println("fb :-present backward message = "
    // +present_backward_message);
    Matrix backwardMatrix = transitionMatrix.times(oMatrix
        .times(present_backward_message.asMatrix()));

    result.updateFrom(backwardMatrix);
    result.normalize();
    // System.out.println("fb :-normalized new backward message = "
View Full Code Here

      distribution.put(states.get(i), newProbs.get(i));
    }
  }

  public Matrix asMatrix() {
    Matrix m = new Matrix(states.size(), 1);
    for (int i = 0; i < states.size(); i++) {
      m.set(i, 0, distribution.get(states.get(i)));
    }
    return m;

  }
View Full Code Here

  }

  public VarDistribution smooth(String perception) {

    evidenceFromSmoothedStepToPresent.add(perception);
    Matrix O_t = hmm.sensorModel().asMatrix(perception);
    Matrix transitionMatrix = hmm.transitionModel().asMatrix();
    if (time > timelag) {

      forwardMessage = hmm.forward(forwardMessage, perception); // This
      // seems
      // WRONG
      // I think this should be
      // forwardMessage = hmm.forward(forwardMessage,
      // evidenceFromSmoothedStepToPresent.get(0));
      // this the perception at t-d. the book's algorithm
      // uses the latest perception.
      evidenceFromSmoothedStepToPresent.remove(0);
      Matrix O_t_minus_d = hmm.sensorModel().asMatrix(
          evidenceFromSmoothedStepToPresent.get(0));

      B = O_t_minus_d.inverse().times(
          transitionMatrix.inverse().times(
              B.times(transitionMatrix.times(O_t))));

    } else {

      B = B.times(transitionMatrix.times(O_t));

    }
    time += 1;
    if (time > timelag) {

      Matrix one = hmm.prior().createUnitBelief().asMatrix();
      Matrix forwardMatrix = forwardMessage.asMatrix();
      VarDistribution result = hmm.prior().duplicate();
      Matrix backwardMessage = (B.times(one));

      result.updateFrom(forwardMatrix.arrayTimes(backwardMessage));

      result.normalize();
      return result;
View Full Code Here

  public double get(String old_state_action, String newState) {
    return table.get(old_state_action, newState);
  }

  public Matrix asMatrix(String action) {
    Matrix transitionMatrix = new Matrix(states.size(), states.size());
    for (int i = 0; i < states.size(); i++) {
      String oldState = states.get(i);
      String old_state_action = oldState.concat(action);
      for (int j = 0; j < states.size(); j++) {
        String newState = states.get(j);
        double transitionProbability = get(old_state_action, newState);
        transitionMatrix.set(i, j, transitionProbability);
      }
    }
    return transitionMatrix;
  }
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.