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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations