dynamicslab / pysindy

A package for the sparse identification of nonlinear dynamical systems from data
https://pysindy.readthedocs.io/en/latest/
Other
1.45k stars 323 forks source link

Applying PySINDy for Identifying Swarm Dynamics with Conditional Interaction Rules #312

Closed bkhaldi closed 1 year ago

bkhaldi commented 1 year ago

My ongoing project involves identifying the dynamics of a swarm of drones that exhibit collective behavior, which includes conditional interaction rules among individual drones. To achieve this, I have been experimenting with PySINDy, but unfortunately, I have not been able to obtain satisfactory results. I believe that I might be missing some essential steps in the process, and I would be grateful for your guidance and assistance in this matter.

My primary concern is that the equations underlying the collective swarm drones' behavior I'm studying incorporate conditional rules, and I'm wondering how the PySINDy model might be applied in such a case.

Jacob-Stevens-Haas commented 1 year ago

Conditional rules could be accomodated with a CustomLibrary, which lets you submit your own functions rather than the polynomials or sinusoids of other libraries.

It also depends on what you're trying to understand of the swarm. Do you already know the equations for the individual dynamics and are looking for a reduced-order-model for the centroid or volume of the swarm?

bkhaldi commented 1 year ago

Conditional rules could be accomodated with a CustomLibrary, which lets you submit your own functions rather than the polynomials or sinusoids of other libraries.

It also depends on what you're trying to understand of the swarm. Do you already know the equations for the individual dynamics and are looking for a reduced-order-model for the centroid or volume of the swarm?

Thanks for your reply. Indeed I already know the equations for the individual dynamics, and I am curious to see if the overall swarm collective behavior uncovered by SINDy will be similar to the original. We are primarily interested in using the swarm SINDy built model as a controller for our drones to achieve the desired collective behaviour.

Individual drone dynamics depends on whether the drone avoids an obstacle or collides with its neighbors. More specifically, the equations include conditional rules implemented as if-else statements dependent on the circumstance that the drone is in. Each conditional rule in the governing equations, however, is the same for all drones.

So, in case of using a CustomLibrary as you suggest, how SINDy will alternate between the conditional rules of the governing equations. I am a little bit confused about that.

Jacob-Stevens-Haas commented 1 year ago

For a basic bang-bang control to keep the objects in the swarm apart, take this function as an example:

def bangbang_control(x, neighbor):
    # push right if neighbor is too close to the left
    if x > neighbor and x < neighbor + margin:
        return 1
    # push left if neighbor is too close to the right
    if x < neighbor and x > neighbor - margin:
        return -1
    return 0

The example here shows how to build a feature library of functions like bangbang_control.

You could consider treating all x, y, z coordinates of each vehicle as a different data coordinates in SINDy, e.g. x1, y1, z1, x2, y2, z2... Thus, hopefully the model would find

$$ \begin{align} \dot x_1 =& bangbang(x_1, x_2) + bangbang(x_1, x_3) +\dots \ \dot y_1 =& bangbang(y_1, y_2) + bangbang(y_1, y_3) +\dots \ \vdots \end{align} $$

bkhaldi commented 1 year ago

Hi Mr. Jacob,

Thanks very much for this clarification. It really helps us a lot.

Jacob-Stevens-Haas commented 1 year ago

Glad it helped :)