@Test public void testRungeKutta4() throws Exception { double[] dy = new double[6]; double[] expected = new double[] { 4.6150293059333864E-5, 0.009230155470065143, 0.06998234991908409, -0.003530594904452524, -6.929639567933079E-4, -0.13874989599620138 }; CartPoleState state = environment.sampleInitialStateDistribution(random); environment.motionEquations(1.0, state.getFeatures(), dy); double[] variables = state.getFeatures(); environment.RungeKutta4(1.0, variables, dy, variables); Assert.assertArrayEquals(expected, variables, 10e-9); }
public void RungeKutta4(double force, double[] y, double[] dydx, double[] yout) { double hh = TAU * 0.5; double h6 = TAU / 6.0; double[] dym = new double[6]; double[] dyt = new double[6]; double[] yt = new double[6]; for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dydx[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dyt[i]; } step(force, yt, dym); for (int pole = 0; pole <= numPoles; pole++) { dym[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + TAU * dym[i]; dym[i] += dyt[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yout[i] = y[i] + h6 * (dydx[i] + dyt[i] + 2.0 * dym[i]); } }
CartPoleEnvironment implements Environment<CartPoleState, ContinuousAction>,
		EnvironmentEncoder<CartPoleState, ContinuousAction>, Serializable { public void RungeKutta4(double force, double[] y, double[] dydx, double[] yout) { double hh = TAU * 0.5; double h6 = TAU / 6.0; double[] dym = new double[6]; double[] dyt = new double[6]; double[] yt = new double[6]; for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dydx[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dyt[i]; } step(force, yt, dym); for (int pole = 0; pole <= numPoles; pole++) { dym[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + TAU * dym[i]; dym[i] += dyt[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yout[i] = y[i] + h6 * (dydx[i] + dyt[i] + 2.0 * dym[i]); } } }
CartPoleEnvironment implements Environment<CartPoleState, ContinuousAction>,
		EnvironmentEncoder<CartPoleState, ContinuousAction>, Serializable { public void RungeKutta4(double force, double[] y, double[] dydx, double[] yout) { double hh = TAU * 0.5; double h6 = TAU / 6.0; double[] dym = new double[6]; double[] dyt = new double[6]; double[] yt = new double[6]; for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dydx[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dyt[i]; } step(force, yt, dym); for (int pole = 0; pole <= numPoles; pole++) { dym[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + TAU * dym[i]; dym[i] += dyt[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yout[i] = y[i] + h6 * (dydx[i] + dyt[i] + 2.0 * dym[i]); } } CartPoleEnvironment(int numPoles);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass, double gravity); }
CartPoleEnvironment implements Environment<CartPoleState, ContinuousAction>,
		EnvironmentEncoder<CartPoleState, ContinuousAction>, Serializable { public void RungeKutta4(double force, double[] y, double[] dydx, double[] yout) { double hh = TAU * 0.5; double h6 = TAU / 6.0; double[] dym = new double[6]; double[] dyt = new double[6]; double[] yt = new double[6]; for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dydx[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dyt[i]; } step(force, yt, dym); for (int pole = 0; pole <= numPoles; pole++) { dym[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + TAU * dym[i]; dym[i] += dyt[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yout[i] = y[i] + h6 * (dydx[i] + dyt[i] + 2.0 * dym[i]); } } CartPoleEnvironment(int numPoles);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass, double gravity); double[] getPoleMasses(); double[] getPoleLengths(); double getCartMass(); double getGravity(); int getNumPoles(); @Override AgentTransition<CartPoleState, ContinuousAction> getAgentTransition(CartPoleState state,
			ContinuousAction action); void step(double force, double[] variables, double[] derivatives); void motionEquations(double force, double[] variables, double[] derivatives); void RungeKutta4(double force, double[] y, double[] dydx, double[] yout); @Override EnvTransition<CartPoleState> getEnvironmentTransition(CartPoleState afterState,
			RandomDataGenerator random); @Override List<ContinuousAction> getPossibleActions(CartPoleState state); @Override CartPoleState sampleInitialStateDistribution(RandomDataGenerator random); @Override boolean isTerminal(CartPoleState state); @Override double getAgentPerformance(double totalReward, int numSteps, CartPoleState finalState); @Override double[] encode(CartPoleState state); int getNumInputs(); @Override double[] encode(ContinuousAction action); double evaluate(RealFunction controller, int maxNumSteps, RandomDataGenerator random); @Override String toString(); }
CartPoleEnvironment implements Environment<CartPoleState, ContinuousAction>,
		EnvironmentEncoder<CartPoleState, ContinuousAction>, Serializable { public void RungeKutta4(double force, double[] y, double[] dydx, double[] yout) { double hh = TAU * 0.5; double h6 = TAU / 6.0; double[] dym = new double[6]; double[] dyt = new double[6]; double[] yt = new double[6]; for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dydx[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + hh * dyt[i]; } step(force, yt, dym); for (int pole = 0; pole <= numPoles; pole++) { dym[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yt[i] = y[i] + TAU * dym[i]; dym[i] += dyt[i]; } step(force, yt, dyt); for (int pole = 0; pole <= numPoles; pole++) { dyt[2 * pole] = yt[2 * pole + 1]; } for (int i = 0; i < y.length; i++) { yout[i] = y[i] + h6 * (dydx[i] + dyt[i] + 2.0 * dym[i]); } } CartPoleEnvironment(int numPoles);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass, double gravity); double[] getPoleMasses(); double[] getPoleLengths(); double getCartMass(); double getGravity(); int getNumPoles(); @Override AgentTransition<CartPoleState, ContinuousAction> getAgentTransition(CartPoleState state,
			ContinuousAction action); void step(double force, double[] variables, double[] derivatives); void motionEquations(double force, double[] variables, double[] derivatives); void RungeKutta4(double force, double[] y, double[] dydx, double[] yout); @Override EnvTransition<CartPoleState> getEnvironmentTransition(CartPoleState afterState,
			RandomDataGenerator random); @Override List<ContinuousAction> getPossibleActions(CartPoleState state); @Override CartPoleState sampleInitialStateDistribution(RandomDataGenerator random); @Override boolean isTerminal(CartPoleState state); @Override double getAgentPerformance(double totalReward, int numSteps, CartPoleState finalState); @Override double[] encode(CartPoleState state); int getNumInputs(); @Override double[] encode(ContinuousAction action); double evaluate(RealFunction controller, int maxNumSteps, RandomDataGenerator random); @Override String toString(); static final int NUM_INPUTS_ONE_POLE; static final int NUM_INPUTS_TWO_POLES; }