sciencegym.simulations.InclinedPlane module

class sciencegym.simulations.InclinedPlane.InclinePlaneCoordinates(angle: float, l: float = 20)

Bases: object

abs_ball_distance_form_initial_positione(ball_coords)
get_coordinates()
is_ball_in_plane_bounds(coordinates)
is_x_coordinate_inside_plane_bounds(x)
is_y_coordinate_inside_plane_bounds(y)
rel_ball_distance_form_initial_positione(ball_coords)
class sciencegym.simulations.InclinedPlane.InclinedPlane(*args: Any, **kwargs: Any)

Bases: Env

close()

Close the pygame window and terminate the program.

convertDensityToGrayscale(density, low=4.0, high=6.0)

Gets a value for the density of one box and returns the corresponding grayscale value

Parameters:
  • density (float) – density of the box (should be in range of the interval)

  • low (float) – the minimum value for the density

  • high (float) – the maximum value for the density

Returns:

a RGB color

Return type:

(int, int, int)

convertDensityToRGB(density, low=4.0, high=6.0, channels=[True, True, True])

Gets a value for the density of one box and returns the corresponding color

Parameters:
  • density (float) – density of the box (should be in range of the interval)

  • low (float) – the minimum value for the d ensity

  • high (float) – the maximum value for the density

  • channels – an array with 3 entries, where each entry says if the color channel should be used or not.

e.g. if it’s [True, False, True], we want to use the Red and Blue channel, but not the Green channel. :type channels: list[bool, bool, bool] :return: a RGB color :rtype: (int, int, int)

convertGrayscaleToDensity(RGB, low=4.0, high=6.0)

Gets a Grayscale value of an box and returns the corresponding density of the box

Parameters:
  • RGB ((int, int, int)) – (red, green, blue) values

  • low (float) – the minimum value for the density

  • high (float) – the maximum value for the density

Returns:

density value

Return type:

float

convertRGBToDensity(RGB, low=4.0, high=6.0, channels=[True, True, True])

Gets a RGB value of an box and returns the corresponding density of the box

Parameters:
  • RGB ((int, int, int)) – (red, green, blue) values

  • low (float) – the minimum value for the density

  • high (float) – the maximum value for the density

Returns:

density value

Return type:

float

createNewExperiment()
getState()

Resets and returns the current values of the state

get current

Returns:

the new state

Return type:

np.ndarray

internal_step(action=None)

Simulates the program with the given action and returns the observations

Parameters:

action (list[float]) – the action(s) the agent chooses as an array of each new positions for each box that should be moved

Returns:

new state after step, the reward, done, info

Return type:

tuple[np.ndarray, float, bool, dict]

name = 'InclinedPlane-v1'
performAction(action)
render(mode='human')

Render function, which runs the simulation and render it (if wished)

Parameters:

mode (str) – “human” for rendering, “state_pixels” for returning the pixel array

Returns:

nothing if mode is human, if mode is “state_pixels”, we return the array of the screen

Return type:

np.array

rescaleState(state=None)

Returns normalized version of the state

Parameters:

state (np.ndarray) – the normal state, which is not normalized yet

Returns:

the new normalized state

Return type:

np.ndarray

reset()

Reset function for the whole environment. Inside of it, we reset every counter/reward, we reset the boxes, the state and all other necessary things.

Returns:

the new state (normalized, if wished)

Return type:

np.ndarray

seed(seed=None)

Seed function for the random number calculation

Parameters:

seed (int) – if None: cannot recreate the same results afterwards

Returns:

the seed

Return type:

list[int]

simulated_step(action)

Actual step function called by the agent when box2d simulation is used

Parameters:

action (list[float]) – the action(s) the agent chooses as an array of each new positions for each box that should be moved

Returns:

new state after step, the reward, done, info

Return type:

tuple[np.ndarray, float, bool, dict]

step(action)

here you can exchange the step function very simple from simulated to synthetic step functions options: 1) simulated steps - simulated_step (here you can exchange the reward function in the internal step function) 2) synthetic steps - synthetic_step_percentual_difference_between_forces - synthetic_step_percentual_change_position_or_velocity - step_without_physics_constant - step_without_physics_angle_dependant :param action: :return:

step_without_physics_angle_dependant(action)

try to learn small angles as good as bigger angles by decreasing the allowed change in position of the ball the smaller the angle is :param action: :return:

step_without_physics_constant(action)

like synthetic_step_percentual_change_position_or_velocity to play around with the constants and parameters here the gravity is set constant :param action: :return:

synthetic_step_percentual_change_position_or_velocity(action)

gets reward dependant on how much percentual difference is between the observed movement or velocity of the ball to the movement or velocity you would expect if the force was predicted correctly with a percentual difference of delta_percent :param action: :return:

synthetic_step_percentual_difference_between_forces(action)

gets reward dependant on how much percentual difference is between the force applied by the agent and the actual force needed :param action: :return:

sciencegym.simulations.InclinedPlane.degreeToRad(angle)
Parameters:

angle

Returns:

sciencegym.simulations.InclinedPlane.normal_vector(p1, p2)
sciencegym.simulations.InclinedPlane.radToDegree(rad)
Parameters:

rad

Returns:

sciencegym.simulations.InclinedPlane.rescale_movement(original_interval, value, to_interval=(-15, 15))

Help function to do and to undo the normalization of the action and observation space :param original_interval: Original interval, in which we observe the value. :type original_interval: list[float, float] :param value: Number that should be rescaled. :type value: float :param to_interval: New interval, in which we want to rescale the value. :type to_interval: list[float, float] :return: Rescaled value :rtype: float