Search in sources :

Example 16 with RealVector

use of org.apache.commons.math3.linear.RealVector in project FSensor by KalebKE.

the class FitPoints method translateToCenter.

/**
 * Translate the algebraic form of the ellipsoid to the offset.
 *
 * @param center vector containing the offset of the ellipsoid.
 * @param a      the algebraic form of the polynomial.
 * @return the offset translated form of the algebraic ellipsoid.
 */
private RealMatrix translateToCenter(RealVector center, RealMatrix a) {
    // Form the corresponding translation matrix.
    RealMatrix t = MatrixUtils.createRealIdentityMatrix(4);
    RealMatrix centerMatrix = new Array2DRowRealMatrix(1, 3);
    centerMatrix.setRowVector(0, center);
    t.setSubMatrix(centerMatrix.getData(), 3, 0);
    // Translate to the offset.
    RealMatrix r = t.multiply(a).multiply(t.transpose());
    return r;
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix)

Example 17 with RealVector

use of org.apache.commons.math3.linear.RealVector in project narchy by automenta.

the class HordeTest method testPredictionDemonGamma09MultipleState.

@Test
public void testPredictionDemonGamma09MultipleState() {
    final int bufferSize = 50;
    double gamma = 0.9;
    TD td = new TD(gamma, 0.1, bufferSize);
    CustomRewardFunction rewardFunction = new CustomRewardFunction(bufferSize);
    PredictionDemon predictionDemon = new PredictionDemon(rewardFunction, td);
    PredictionDemonVerifier verifier = new PredictionDemonVerifier(td.gamma(), predictionDemon);
    TimeToState timeToState = new TimeToState() {

        @Override
        public RealVector get(int time) {
            RealVector r = new ArrayRealVector(bufferSize);
            r.setEntry(time % bufferSize, 1);
            return r;
        }
    };
    runExperiment(predictionDemon, verifier, timeToState, 1000 * bufferSize);
}
Also used : TD(nars.rl.horde.functions.TD) PredictionDemonVerifier(nars.rl.horde.demons.PredictionDemonVerifier) RealVector(org.apache.commons.math3.linear.RealVector) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector) PredictionDemon(nars.rl.horde.demons.PredictionDemon) Test(org.junit.jupiter.api.Test)

Example 18 with RealVector

use of org.apache.commons.math3.linear.RealVector in project narchy by automenta.

the class TabularAction method stateAction.

private RealVector stateAction(ArrayRealVector s, int offset) {
    ArrayRealVector phi_sa = (ArrayRealVector) buffer;
    phi_sa.set(0.0);
    phi_sa.setSubVector(offset, s);
    if (includeActiveFeature)
        phi_sa.setEntry(phi_sa.getDimension() - 1, 1);
    return phi_sa;
}
Also used : ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector)

Example 19 with RealVector

use of org.apache.commons.math3.linear.RealVector in project narchy by automenta.

the class TabularAction method stateAction.

@Override
public RealVector stateAction(RealVector s, A a) {
    if (s == null)
        return nullVector;
    if (buffer == null)
        buffer = new ArrayRealVector(vectorSize());
    int offset = atoi(a) * stateVectorSize;
    // if (s instanceof BinaryVector)
    // return stateAction(s, offset);
    RealVector phi_sa = buffer;
    phi_sa.set(0.0);
    if (includeActiveFeature)
        phi_sa.setEntry(vectorSize() - 1, 1);
    for (int s_i = 0; s_i < s.getDimension(); s_i++) phi_sa.setEntry(s_i + offset, s.getEntry(s_i));
    return phi_sa;
}
Also used : RealVector(org.apache.commons.math3.linear.RealVector) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector)

Example 20 with RealVector

use of org.apache.commons.math3.linear.RealVector in project narchy by automenta.

the class GQ method update.

public double update(RealVector x_t, double rho_t, double r_tp1, RealVector x_bar_tp1, double z_tp1) {
    if (x_t == null)
        return initEpisode();
    VectorPool pool = VectorPools.pool(x_t);
    delta_t = r_tp1 + beta_tp1 * z_tp1 + (1 - beta_tp1) * v.dotProduct(x_bar_tp1) - v.dotProduct(x_t);
    e.update((1 - beta_tp1) * lambda_t * rho_t, x_t);
    RealVector delta_e = pool.newVector(e.vect()).mapMultiplyToSelf(delta_t);
    ArrayRealVector tdCorrection = pool.newVector();
    if (x_bar_tp1 != null)
        tdCorrection.combineToSelf(0, 1, x_bar_tp1).mapMultiplyToSelf((1 - beta_tp1) * (1 - lambda_t) * e.vect().dotProduct(w));
    v.combineToSelf(1, alpha_v, pool.newVector(delta_e).combineToSelf(1, -1, tdCorrection));
    w.combineToSelf(1, alpha_w, delta_e.combineToSelf(1, -1, pool.newVector(x_t).mapMultiplyToSelf(w.dotProduct(x_t))));
    delta_e = null;
    pool.releaseAll();
    return delta_t;
}
Also used : VectorPool(nars.rl.horde.math.VectorPool) RealVector(org.apache.commons.math3.linear.RealVector) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector)

Aggregations

RealVector (org.apache.commons.math3.linear.RealVector)41 ArrayRealVector (org.apache.commons.math3.linear.ArrayRealVector)30 RealMatrix (org.apache.commons.math3.linear.RealMatrix)22 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)10 Test (org.junit.jupiter.api.Test)5 ConvergenceException (org.apache.commons.math3.exception.ConvergenceException)4 TooManyIterationsException (org.apache.commons.math3.exception.TooManyIterationsException)4 VectorPool (nars.rl.horde.math.VectorPool)3 LeastSquaresBuilder (org.apache.commons.math3.fitting.leastsquares.LeastSquaresBuilder)3 Optimum (org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum)3 LeastSquaresProblem (org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem)3 LevenbergMarquardtOptimizer (org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer)3 DecompositionSolver (org.apache.commons.math3.linear.DecompositionSolver)3 SingularValueDecomposition (org.apache.commons.math3.linear.SingularValueDecomposition)3 CombinedAttributeValues (org.knime.base.node.mine.treeensemble2.data.BinaryNominalSplitsPCA.CombinedAttributeValues)3 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)3 File (java.io.File)2 Comparator (java.util.Comparator)2 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)2 ValueAndJacobianFunction (org.apache.commons.math3.fitting.leastsquares.ValueAndJacobianFunction)2