simulate: Start a simulation based on a graph

View source: R/simulate.R

simulateR Documentation

Start a simulation based on a graph

Description

This function initiates a simulation based on the provided graph and parameters. Any graph structure with a tidygraph::as_tbl_graph() method is supported as input. This function does not start the simulation but merely sets it up.

Usage

simulate(
  graph,
  alpha = 1,
  alpha_min = 0.001,
  alpha_decay = 1 - alpha_min^(1/300),
  alpha_target = 0,
  velocity_decay = 0.4,
  setup = phyllotactic_genesis(),
  ...
)

is.simulation(x)

record(simulation, ...)

clear_history(simulation)

get_history(simulation, age = -1)

history_length(simulation)

reheat(simulation, alpha)

particles(simulation)

position(simulation)

velocity(simulation)

evolutions(simulation)

Arguments

graph

A graph in a format supported by tidygraph

alpha

The starting alpha value. See Details.

alpha_min

The minimum alpha value after which the simulation is terminated. See Details.

alpha_decay

The speed at which the alpha value decreases. See Details.

alpha_target

The alpha value that alpha drifts towards. See Details.

velocity_decay

The dampening factor of the system. See Details.

setup

A function that takes the particle graph and returns a start position and velocity to each particle. particles provides a range of genesis functions to choose from.

...

Additional parameters for the simulation (currently ignored)

x, simulation

A simulation object

age

The version to retrieve. Positive numbers count from the beginning, while negative numbers counts backwards from current version. Defaults to -1.

Details

A simulation in the context of the particles package is a series of equidistant steps where the velocity and position of each particle is updated. A few global rules applies to this cycle irrespectively of the forces added to the simulation. Once a simulation is initiated an alpha value is defined (defaults to 1). At each step this alpha value is decreased according to its distance to the alpha_target (defaults to 0) and alpha_decay (defaults to ~0.023). Once the alpha value gets below alpha_min (defaults to 0.001) the simulation seizes to take additional steps. The default values is adapted from the d3-force implementation and corresponds to 300 steps. Conceptually the alpha progression can be seen as a cooling off of the system as the value decreases quickly in the beginning and then slowly reach the target value. If it is not intended to have a system that cools off, simply set the alpha_target value to the same as alpha. At each step, after the new particle velocities has been calculated but before they have been applied to the positions, a dampening factor (velocity_decay) is applied in order to simulate the gradual loss of momentum. If this is not intended for the simulation, simply set the value to 0.

Value

A simulation object

Functions

  • record(): Save the current state in the simulation's history

  • clear_history(): Clear the current history from the simulation

  • get_history(): Retrieve a simulation from the history

  • history_length(): Get the number of versions stored in the history of the simulation

  • reheat(): set the cooling of the simulation to a new value

  • particles(): Extract the particle graph from a simulation

  • position(): Extract the position coordinates from a simulation

  • velocity(): Extract the velocity verlets from a simulation

  • evolutions(): Get the number of generations the simulation has undergone

Examples

graph <- tidygraph::create_notable('folkman')
graph |>
  simulate()


thomasp85/particles documentation built on Sept. 1, 2022, 2:43 p.m.