Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of graph data #507

Closed
rijul01 opened this issue May 21, 2024 · 7 comments
Closed

Implementation of graph data #507

rijul01 opened this issue May 21, 2024 · 7 comments

Comments

@rijul01
Copy link

rijul01 commented May 21, 2024

Can we implement SINDy on non-uniform data, similar to how Graph Neural Networks utilize an adjacency matrix? Is there a way to incorporate an adjacency matrix in this context?

@Jacob-Stevens-Haas
Copy link
Collaborator

If the connections are time-varying, sure. Each entry in an adjacency matrix represents an edge weight, so these are your variables.

OTOH, if your variables are note intensities, you can see the fit coefficient matrix as a directed adjacency matrix. For linear SINDy, it's a graph, for quadratic SINDy or higher it's a hypergraph, etc.

@rijul01
Copy link
Author

rijul01 commented Jun 4, 2024

I am dealing with the dataset having 20 station points (have 20 latitudes and longitudes) and each station has CO2 concentration. I wanted to see:

  1. the transportation of CO2 from one station to another. For this I have created the data with shape (time, stations, 1). And have created a custom feature library with d(station1)/d(station2) terms, so as to account for the station transport. I am hoping that after applying L1 loss I will get 20 sparse equations.
  2. a general equation where I want to identify the general trend in the data. In this case, I'll have shape (time *stations, n) where n is the number of features, not stations.

In the first case, the feature library is getting big, around 500 features with 1 degree polynomial and 1st order derivatives. And if I increase the number of stations, let's say 200, then it'll be even bigger. My goal for the first task is to see local transport. So in this case creating spatiotemporal grid is having some issues as the grids are not uniform and all stations are connected to each other. Do I need to provide an adjacency matrix as a spatiotemporal grid in shape (time, 20, 20) with zero when there's no connection (will this even work)? I am thinking SINDy can remove redundant stations, not sure. I don't want each 20 equations to have all the features terms. Moreover, if the number of stations are 200, then creating clusters will help otherwise the feature library would be too big. I am just not sure how the SINDy will work in this case.

For the 2nd task, I don't need to define the spatial grid so this seems pretty doable. Right now I am stuck with task 1.

@Jacob-Stevens-Haas
Copy link
Collaborator

SINDy isn't good at doing things like d(station1)/d(station2). It is better at d(station1)/dt = f(station1, station2). You very keenly pointed out that you can do something like the former in pysindy with spatial derivatives, as d(station1)dx = k * station 2 is equivalent to d(station1)/d(station2) = k. This particular example could potentially be handled by an ODE, however.

For the PDE library, you only need a spatial grid, whereas for the WeakPDELibrary, you need a spatiotemporal grid, but in both, only uniform grids are supported.

For larger numbers of coordinates/stations, yes, clustering could help.

Have you tried just a plain linear library and a (time, stations) data matrix?

Ordering of terms is (*spatial terms, time, coordinate/feature)

@rijul01
Copy link
Author

rijul01 commented Jun 6, 2024

My code:

poly_lib_1 = ps.PolynomialLibrary(
    degree = 1,
    include_interaction =True,
    include_bias=False
).fit(co_2016)

print(poly_lib_1.get_feature_names())

pde_lib_1 = ps.PDELibrary(
    function_library=poly_lib_1,
    include_bias=True,
    derivative_order = 1,
    temporal_grid=t_2016,
    implicit_terms=True,
).fit(co_2016)

print(len(pde_lib_1.get_feature_names()))
print(pde_lib_1.get_feature_names())

# co_2016_dot = np.gradient(co_2016, axis=0)


sindy_opt = ps.SINDyPI(
    model_subset = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
    thresholder='l1',
    threshold=0.01,
    tol=1e-5,
    max_iter=9000,    
)

# optimizer = ps.STLSQ(threshold=1, alpha=1e-5, normalize_columns=True)
model = ps.SINDy(feature_library=pde_lib_1, optimizer = sindy_opt)
model.fit(co_2016, t = t_2016) # , x_dot = co_2016_dot)
model.print()

Output:

Output:
['x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9', 'x10', 'x11', 'x12', 'x13', 'x14', 'x15', 'x16', 'x17', 'x18', 'x19', 'x20', 'x21', 'x22', 'x23', 'x24']
676
['1', 'x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9', 'x10', 'x11', 'x12', 'x13', 'x14', 'x15', 'x16', 'x17', 'x18', 'x19', 'x20', 'x21', 'x22', 'x23', 'x24', 'x0_t', 'x1_t', 'x2_t', 'x3_t', 'x4_t', 'x5_t', 'x6_t', 'x7_t', 'x8_t', 'x9_t', 'x10_t', 'x11_t', 'x12_t', 'x13_t', 'x14_t', 'x15_t', 'x16_t', 'x17_t', 'x18_t', 'x19_t', 'x20_t', 'x21_t', 'x22_t', 'x23_t', 'x24_t', 'x0x0_t', 'x1x0_t', 'x2x0_t', 'x3x0_t', 'x4x0_t', 'x5x0_t', 'x6x0_t', 'x7x0_t', 'x8x0_t', 'x9x0_t', 'x10x0_t', 'x11x0_t', 'x12x0_t', 'x13x0_t', 'x14x0_t', 'x15x0_t', 'x16x0_t', 'x17x0_t', 'x18x0_t', 'x19x0_t', 'x20x0_t', 'x21x0_t', 'x22x0_t', 'x23x0_t', 'x24x0_t', 'x0x1_t', 'x1x1_t', 'x2x1_t', 'x3x1_t', 'x4x1_t', 'x5x1_t', 'x6x1_t', 'x7x1_t', 'x8x1_t', 'x9x1_t', 'x10x1_t', 'x11x1_t', 'x12x1_t', 'x13x1_t', 'x14x1_t', 'x15x1_t', 'x16x1_t', 'x17x1_t', 'x18x1_t', 'x19x1_t', 'x20x1_t', 'x21x1_t', 'x22x1_t', 'x23x1_t', 'x24x1_t', 'x0x2_t', 'x1x2_t', 'x2x2_t', 'x3x2_t', 'x4x2_t', 'x5x2_t', 'x6x2_t', 'x7x2_t', 'x8x2_t', 'x9x2_t', 'x10x2_t', 'x11x2_t', 'x12x2_t', 'x13x2_t', 'x14x2_t', 'x15x2_t', 'x16x2_t', 'x17x2_t', 'x18x2_t', 'x19x2_t', 'x20x2_t', 'x21x2_t', 'x22x2_t', 'x23x2_t', 'x24x2_t', 'x0x3_t', 'x1x3_t', 'x2x3_t', 'x3x3_t', 'x4x3_t', 'x5x3_t', 'x6x3_t', 'x7x3_t', 'x8x3_t', 'x9x3_t', 'x10x3_t', 'x11x3_t', 'x12x3_t', 'x13x3_t', 'x14x3_t', 'x15x3_t', 'x16x3_t', 'x17x3_t', 'x18x3_t', 'x19x3_t', 'x20x3_t', 'x21x3_t', 'x22x3_t', 'x23x3_t', 'x24x3_t', 'x0x4_t', 'x1x4_t', 'x2x4_t', 'x3x4_t', 'x4x4_t', 'x5x4_t', 'x6x4_t', 'x7x4_t', 'x8x4_t', 'x9x4_t', 'x10x4_t', 'x11x4_t', 'x12x4_t', 'x13x4_t', 'x14x4_t', 'x15x4_t', 'x16x4_t', 'x17x4_t', 'x18x4_t', 'x19x4_t', 'x20x4_t', 'x21x4_t', 'x22x4_t', 'x23x4_t', 'x24x4_t', 'x0x5_t', 'x1x5_t', 'x2x5_t', 'x3x5_t', 'x4x5_t', 'x5x5_t', 'x6x5_t', 'x7x5_t', 'x8x5_t', 'x9x5_t', 'x10x5_t', 'x11x5_t', 'x12x5_t', 'x13x5_t', 'x14x5_t', 'x15x5_t', 'x16x5_t', 'x17x5_t', 'x18x5_t', 'x19x5_t', 'x20x5_t', 'x21x5_t', 'x22x5_t', 'x23x5_t', 'x24x5_t', 'x0x6_t', 'x1x6_t', 'x2x6_t', 'x3x6_t', 'x4x6_t', 'x5x6_t', 'x6x6_t', 'x7x6_t', 'x8x6_t', 'x9x6_t', 'x10x6_t', 'x11x6_t', 'x12x6_t', 'x13x6_t', 'x14x6_t', 'x15x6_t', 'x16x6_t', 'x17x6_t', 'x18x6_t', 'x19x6_t', 'x20x6_t', 'x21x6_t', 'x22x6_t', 'x23x6_t', 'x24x6_t', 'x0x7_t', 'x1x7_t', 'x2x7_t', 'x3x7_t', 'x4x7_t', 'x5x7_t', 'x6x7_t', 'x7x7_t', 'x8x7_t', 'x9x7_t', 'x10x7_t', 'x11x7_t', 'x12x7_t', 'x13x7_t', 'x14x7_t', 'x15x7_t', 'x16x7_t', 'x17x7_t', 'x18x7_t', 'x19x7_t', 'x20x7_t', 'x21x7_t', 'x22x7_t', 'x23x7_t', 'x24x7_t', 'x0x8_t', 'x1x8_t', 'x2x8_t', 'x3x8_t', 'x4x8_t', 'x5x8_t', 'x6x8_t', 'x7x8_t', 'x8x8_t', 'x9x8_t', 'x10x8_t', 'x11x8_t', 'x12x8_t', 'x13x8_t', 'x14x8_t', 'x15x8_t', 'x16x8_t', 'x17x8_t', 'x18x8_t', 'x19x8_t', 'x20x8_t', 'x21x8_t', 'x22x8_t', 'x23x8_t', 'x24x8_t', 'x0x9_t', 'x1x9_t', 'x2x9_t', 'x3x9_t', 'x4x9_t', 'x5x9_t', 'x6x9_t', 'x7x9_t', 'x8x9_t', 'x9x9_t', 'x10x9_t', 'x11x9_t', 'x12x9_t', 'x13x9_t', 'x14x9_t', 'x15x9_t', 'x16x9_t', 'x17x9_t', 'x18x9_t', 'x19x9_t', 'x20x9_t', 'x21x9_t', 'x22x9_t', 'x23x9_t', 'x24x9_t', 'x0x10_t', 'x1x10_t', 'x2x10_t', 'x3x10_t', 'x4x10_t', 'x5x10_t', 'x6x10_t', 'x7x10_t', 'x8x10_t', 'x9x10_t', 'x10x10_t', 'x11x10_t', 'x12x10_t', 'x13x10_t', 'x14x10_t', 'x15x10_t', 'x16x10_t', 'x17x10_t', 'x18x10_t', 'x19x10_t', 'x20x10_t', 'x21x10_t', 'x22x10_t', 'x23x10_t', 'x24x10_t', 'x0x11_t', 'x1x11_t', 'x2x11_t', 'x3x11_t', 'x4x11_t', 'x5x11_t', 'x6x11_t', 'x7x11_t', 'x8x11_t', 'x9x11_t', 'x10x11_t', 'x11x11_t', 'x12x11_t', 'x13x11_t', 'x14x11_t', 'x15x11_t', 'x16x11_t', 'x17x11_t', 'x18x11_t', 'x19x11_t', 'x20x11_t', 'x21x11_t', 'x22x11_t', 'x23x11_t', 'x24x11_t', 'x0x12_t', 'x1x12_t', 'x2x12_t', 'x3x12_t', 'x4x12_t', 'x5x12_t', 'x6x12_t', 'x7x12_t', 'x8x12_t', 'x9x12_t', 'x10x12_t', 'x11x12_t', 'x12x12_t', 'x13x12_t', 'x14x12_t', 'x15x12_t', 'x16x12_t', 'x17x12_t', 'x18x12_t', 'x19x12_t', 'x20x12_t', 'x21x12_t', 'x22x12_t', 'x23x12_t', 'x24x12_t', 'x0x13_t', 'x1x13_t', 'x2x13_t', 'x3x13_t', 'x4x13_t', 'x5x13_t', 'x6x13_t', 'x7x13_t', 'x8x13_t', 'x9x13_t', 'x10x13_t', 'x11x13_t', 'x12x13_t', 'x13x13_t', 'x14x13_t', 'x15x13_t', 'x16x13_t', 'x17x13_t', 'x18x13_t', 'x19x13_t', 'x20x13_t', 'x21x13_t', 'x22x13_t', 'x23x13_t', 'x24x13_t', 'x0x14_t', 'x1x14_t', 'x2x14_t', 'x3x14_t', 'x4x14_t', 'x5x14_t', 'x6x14_t', 'x7x14_t', 'x8x14_t', 'x9x14_t', 'x10x14_t', 'x11x14_t', 'x12x14_t', 'x13x14_t', 'x14x14_t', 'x15x14_t', 'x16x14_t', 'x17x14_t', 'x18x14_t', 'x19x14_t', 'x20x14_t', 'x21x14_t', 'x22x14_t', 'x23x14_t', 'x24x14_t', 'x0x15_t', 'x1x15_t', 'x2x15_t', 'x3x15_t', 'x4x15_t', 'x5x15_t', 'x6x15_t', 'x7x15_t', 'x8x15_t', 'x9x15_t', 'x10x15_t', 'x11x15_t', 'x12x15_t', 'x13x15_t', 'x14x15_t', 'x15x15_t', 'x16x15_t', 'x17x15_t', 'x18x15_t', 'x19x15_t', 'x20x15_t', 'x21x15_t', 'x22x15_t', 'x23x15_t', 'x24x15_t', 'x0x16_t', 'x1x16_t', 'x2x16_t', 'x3x16_t', 'x4x16_t', 'x5x16_t', 'x6x16_t', 'x7x16_t', 'x8x16_t', 'x9x16_t', 'x10x16_t', 'x11x16_t', 'x12x16_t', 'x13x16_t', 'x14x16_t', 'x15x16_t', 'x16x16_t', 'x17x16_t', 'x18x16_t', 'x19x16_t', 'x20x16_t', 'x21x16_t', 'x22x16_t', 'x23x16_t', 'x24x16_t', 'x0x17_t', 'x1x17_t', 'x2x17_t', 'x3x17_t', 'x4x17_t', 'x5x17_t', 'x6x17_t', 'x7x17_t', 'x8x17_t', 'x9x17_t', 'x10x17_t', 'x11x17_t', 'x12x17_t', 'x13x17_t', 'x14x17_t', 'x15x17_t', 'x16x17_t', 'x17x17_t', 'x18x17_t', 'x19x17_t', 'x20x17_t', 'x21x17_t', 'x22x17_t', 'x23x17_t', 'x24x17_t', 'x0x18_t', 'x1x18_t', 'x2x18_t', 'x3x18_t', 'x4x18_t', 'x5x18_t', 'x6x18_t', 'x7x18_t', 'x8x18_t', 'x9x18_t', 'x10x18_t', 'x11x18_t', 'x12x18_t', 'x13x18_t', 'x14x18_t', 'x15x18_t', 'x16x18_t', 'x17x18_t', 'x18x18_t', 'x19x18_t', 'x20x18_t', 'x21x18_t', 'x22x18_t', 'x23x18_t', 'x24x18_t', 'x0x19_t', 'x1x19_t', 'x2x19_t', 'x3x19_t', 'x4x19_t', 'x5x19_t', 'x6x19_t', 'x7x19_t', 'x8x19_t', 'x9x19_t', 'x10x19_t', 'x11x19_t', 'x12x19_t', 'x13x19_t', 'x14x19_t', 'x15x19_t', 'x16x19_t', 'x17x19_t', 'x18x19_t', 'x19x19_t', 'x20x19_t', 'x21x19_t', 'x22x19_t', 'x23x19_t', 'x24x19_t', 'x0x20_t', 'x1x20_t', 'x2x20_t', 'x3x20_t', 'x4x20_t', 'x5x20_t', 'x6x20_t', 'x7x20_t', 'x8x20_t', 'x9x20_t', 'x10x20_t', 'x11x20_t', 'x12x20_t', 'x13x20_t', 'x14x20_t', 'x15x20_t', 'x16x20_t', 'x17x20_t', 'x18x20_t', 'x19x20_t', 'x20x20_t', 'x21x20_t', 'x22x20_t', 'x23x20_t', 'x24x20_t', 'x0x21_t', 'x1x21_t', 'x2x21_t', 'x3x21_t', 'x4x21_t', 'x5x21_t', 'x6x21_t', 'x7x21_t', 'x8x21_t', 'x9x21_t', 'x10x21_t', 'x11x21_t', 'x12x21_t', 'x13x21_t', 'x14x21_t', 'x15x21_t', 'x16x21_t', 'x17x21_t', 'x18x21_t', 'x19x21_t', 'x20x21_t', 'x21x21_t', 'x22x21_t', 'x23x21_t', 'x24x21_t', 'x0x22_t', 'x1x22_t', 'x2x22_t', 'x3x22_t', 'x4x22_t', 'x5x22_t', 'x6x22_t', 'x7x22_t', 'x8x22_t', 'x9x22_t', 'x10x22_t', 'x11x22_t', 'x12x22_t', 'x13x22_t', 'x14x22_t', 'x15x22_t', 'x16x22_t', 'x17x22_t', 'x18x22_t', 'x19x22_t', 'x20x22_t', 'x21x22_t', 'x22x22_t', 'x23x22_t', 'x24x22_t', 'x0x23_t', 'x1x23_t', 'x2x23_t', 'x3x23_t', 'x4x23_t', 'x5x23_t', 'x6x23_t', 'x7x23_t', 'x8x23_t', 'x9x23_t', 'x10x23_t', 'x11x23_t', 'x12x23_t', 'x13x23_t', 'x14x23_t', 'x15x23_t', 'x16x23_t', 'x17x23_t', 'x18x23_t', 'x19x23_t', 'x20x23_t', 'x21x23_t', 'x22x23_t', 'x23x23_t', 'x24x23_t', 'x0x24_t', 'x1x24_t', 'x2x24_t', 'x3x24_t', 'x4x24_t', 'x5x24_t', 'x6x24_t', 'x7x24_t', 'x8x24_t', 'x9x24_t', 'x10x24_t', 'x11x24_t', 'x12x24_t', 'x13x24_t', 'x14x24_t', 'x15x24_t', 'x16x24_t', 'x17x24_t', 'x18x24_t', 'x19x24_t', 'x20x24_t', 'x21x24_t', 'x22x24_t', 'x23x24_t', 'x24x24_t']
Model 1
1 = 0.000
x0 = -0.030 1 + 0.098 x1 + 0.222 x2 + -0.135 x3 + 0.129 x4 + 0.001 x5 + 0.171 x6 + -0.061 x7 + 0.079 x8 + 0.088 x9 + -0.001 x10 + 0.018 x11 + 0.086 x12 + 0.051 x13 + -0.021 x14 + -0.007 x15 + 0.097 x16 + 0.062 x17 + 0.094 x18 + 0.108 x19 + -0.020 x20 + -0.077 x21 + -0.029 x22 + -0.060 x23 + 0.038 x24 + 0.010 x0_t + 0.064 x1_t + 0.003 x2_t + -0.014 x3_t + -0.035 x4_t + 0.005 x5_t + 0.058 x6_t + -0.022 x7_t + -0.013 x8_t + 0.006 x9_t + 0.022 x10_t + 0.015 x11_t + -0.017 x12_t + -0.019 x13_t + -0.042 x14_t + -0.088 x15_t + -0.070 x16_t + 0.007 x17_t + 0.036 x18_t + 0.029 x19_t + -0.059 x20_t + 0.026 x21_t + 0.039 x22_t + 0.006 x23_t + -0.020 x24_t + 0.098 x0x0_t + 0.034 x1x0_t + 0.136 x2x0_t + -0.106 x3x0_t + 0.180 x4x0_t + 0.018 x5x0_t + -0.117 x6x0_t + 0.043 x7x0_t + 0.017 x8x0_t + 0.009 x9x0_t + 0.077 x10x0_t + -0.040 x11x0_t + -0.098 x12x0_t + 0.062 x13x0_t + -0.064 x14x0_t + 0.046 x15x0_t + 0.101 x16x0_t + -0.150 x17x0_t + -0.189 x18x0_t + -0.027 x19x0_t + 0.082 x20x0_t + -0.015 x21x0_t + -0.058 x22x0_t + 0.061 x23x0_t + -0.094 x24x0_t + -0.048 x0x1_t + -0.059 x1x1_t + -0.155 x2x1_t + 0.282 x3x1_t + 0.063 x4x1_t + 0.016 x5x1_t + -0.017 x6x1_t + 0.026 x7x1_t + 0.153 x8x1_t + 0.034 x9x1_t + -0.067 x10x1_t + -0.085 x11x1_t + 0.077 x12x1_t + 0.010 x13x1_t + -0.145 x14x1_t + -0.030 x15x1_t + 0.153 x16x1_t + 0.257 x17x1_t + 0.155 x18x1_t + 0.082 x19x1_t + -0.406 x20x1_t + -0.033 x21x1_t + -0.099 x22x1_t + -0.181 x23x1_t + 0.045 x24x1_t + -0.033 x0x2_t + -0.038 x1x2_t + 0.071 x2x2_t + -0.152 x3x2_t + -0.084 x4x2_t + 0.088 x5x2_t + 0.077 x6x2_t + 0.058 x7x2_t + 0.053 x8x2_t + 0.113 x9x2_t + -0.084 x10x2_t + 0.220 x11x2_t + -0.193 x12x2_t + -0.015 x13x2_t + 0.048 x14x2_t + 0.075 x15x2_t + 0.002 x16x2_t + 0.100 x17x2_t + -0.287 x18x2_t + -0.004 x19x2_t + -0.021 x20x2_t + 0.090 x21x2_t + 0.029 x22x2_t + -0.031 x23x2_t + -0.017 x24x2_t + -0.036 x0x3_t + -0.206 x1x3_t + 0.216 x2x3_t + 0.110 x3x3_t + -0.081 x4x3_t + 0.156 x5x3_t + -0.112 x6x3_t + -0.072 x7x3_t + 0.109 x8x3_t + -0.214 x9x3_t + 0.139 x10x3_t + -0.120 x11x3_t + 0.067 x12x3_t + 0.301 x13x3_t + -0.247 x14x3_t + 0.030 x15x3_t + 0.028 x16x3_t + -0.221 x17x3_t + 0.146 x18x3_t + 0.115 x19x3_t + -0.090 x20x3_t + 0.034 x21x3_t + 0.149 x22x3_t + -0.061 x23x3_t + -0.140 x24x3_t + 0.026 x0x4_t + 0.049 x1x4_t + 0.158 x2x4_t + -0.045 x3x4_t + -0.015 x4x4_t + 0.075 x5x4_t + -0.031 x6x4_t + 0.029 x7x4_t + 0.088 x8x4_t + -0.043 x9x4_t + 0.037 x10x4_t + -0.178 x11x4_t + -0.007 x12x4_t + 0.060 x13x4_t + -0.015 x14x4_t + -0.023 x15x4_t + 0.112 x16x4_t + -0.026 x17x4_t + -0.102 x18x4_t + 0.135 x19x4_t + -0.032 x20x4_t + 0.037 x21x4_t + -0.253 x22x4_t + -0.171 x23x4_t + 0.115 x24x4_t + 0.018 x0x5_t + -0.044 x1x5_t + -0.129 x2x5_t + -0.060 x3x5_t + -0.051 x4x5_t + 0.059 x5x5_t + -0.099 x6x5_t + -0.043 x7x5_t + 0.003 x8x5_t + -0.021 x9x5_t + 0.147 x11x5_t + -0.017 x12x5_t + -0.101 x13x5_t + 0.079 x14x5_t + 0.002 x15x5_t + 0.075 x16x5_t + 0.039 x17x5_t + 0.027 x18x5_t + 0.108 x20x5_t + -0.074 x21x5_t + -0.027 x22x5_t + 0.060 x23x5_t + 0.056 x24x5_t + 0.095 x0x6_t + 0.024 x1x6_t + -0.062 x2x6_t + -0.003 x3x6_t + -0.085 x4x6_t + 0.078 x5x6_t + -0.095 x6x6_t + -0.040 x7x6_t + -0.072 x8x6_t + 0.082 x9x6_t + -0.076 x10x6_t + 0.016 x11x6_t + 0.123 x12x6_t + -0.170 x13x6_t + 0.064 x14x6_t + 0.003 x15x6_t + -0.089 x16x6_t + -0.033 x17x6_t + 0.236 x18x6_t + -0.150 x19x6_t + -0.004 x20x6_t + 0.126 x21x6_t + -0.045 x22x6_t + 0.082 x23x6_t + 0.018 x24x6_t + -0.063 x0x7_t + -0.042 x1x7_t + -0.081 x2x7_t + 0.061 x3x7_t + -0.030 x4x7_t + 0.050 x5x7_t + 0.115 x6x7_t + -0.026 x7x7_t + -0.041 x8x7_t + 0.010 x9x7_t + 0.016 x10x7_t + -0.008 x11x7_t + -0.028 x12x7_t + 0.061 x13x7_t + 0.013 x14x7_t + 0.066 x15x7_t + 0.047 x16x7_t + -0.036 x17x7_t + -0.024 x18x7_t + 0.066 x19x7_t + -0.065 x20x7_t + 0.034 x21x7_t + 0.117 x22x7_t + -0.161 x23x7_t + -0.034 x24x7_t + -0.075 x0x8_t + -0.057 x1x8_t + 0.052 x2x8_t + -0.162 x3x8_t + -0.095 x4x8_t + -0.063 x5x8_t + 0.170 x6x8_t + -0.019 x7x8_t + 0.004 x8x8_t + 0.030 x9x8_t + -0.021 x10x8_t + 0.116 x11x8_t + -0.088 x12x8_t + 0.029 x13x8_t + 0.046 x14x8_t + 0.040 x15x8_t + 0.071 x16x8_t + 0.031 x17x8_t + -0.012 x18x8_t + 0.016 x19x8_t + 0.014 x20x8_t + -0.147 x21x8_t + 0.082 x22x8_t + 0.004 x23x8_t + 0.045 x24x8_t + -0.040 x0x9_t + 0.041 x1x9_t + -0.040 x2x9_t + 0.126 x3x9_t + -0.057 x4x9_t + 0.003 x5x9_t + 0.037 x6x9_t + -0.053 x7x9_t + 0.081 x8x9_t + -0.049 x9x9_t + -0.046 x10x9_t + 0.091 x11x9_t + -0.018 x12x9_t + 0.055 x14x9_t + 0.017 x15x9_t + 0.006 x16x9_t + 0.018 x17x9_t + -0.078 x18x9_t + 0.042 x19x9_t + -0.034 x20x9_t + -0.005 x21x9_t + -0.076 x22x9_t + -0.001 x23x9_t + -0.052 x24x9_t + -0.052 x0x10_t + 0.019 x1x10_t + -0.004 x2x10_t + -0.072 x3x10_t + -0.057 x4x10_t + -0.043 x5x10_t + 0.052 x6x10_t + -0.129 x7x10_t + 0.009 x8x10_t + 0.039 x9x10_t + 0.025 x10x10_t + 0.129 x11x10_t + 0.062 x12x10_t + -0.072 x13x10_t + -0.034 x14x10_t + 0.042 x15x10_t + -0.062 x16x10_t + 0.057 x17x10_t + 0.121 x18x10_t + 0.037 x19x10_t + -0.001 x20x10_t + -0.167 x21x10_t + -0.019 x22x10_t + -0.006 x23x10_t + 0.101 x24x10_t + -0.191 x0x11_t + 0.108 x1x11_t + -0.309 x2x11_t + 0.029 x3x11_t + 0.194 x4x11_t + 0.044 x5x11_t + 0.078 x7x11_t + -0.164 x8x11_t + -0.042 x9x11_t + -0.058 x10x11_t + -0.083 x11x11_t + -0.001 x12x11_t + 0.091 x13x11_t + -0.032 x14x11_t + -0.052 x15x11_t + 0.122 x16x11_t + -0.170 x17x11_t + 0.201 x18x11_t + 0.092 x19x11_t + 0.062 x20x11_t + -0.067 x21x11_t + -0.033 x22x11_t + 0.140 x23x11_t + 0.004 x24x11_t + 0.020 x0x12_t + -0.046 x1x12_t + 0.140 x2x12_t + -0.052 x3x12_t + 0.002 x4x12_t + 0.038 x5x12_t + -0.080 x6x12_t + 0.005 x7x12_t + 0.040 x8x12_t + -0.023 x9x12_t + 0.018 x10x12_t + -0.014 x11x12_t + 0.047 x12x12_t + -0.021 x13x12_t + -0.027 x14x12_t + -0.039 x15x12_t + -0.157 x16x12_t + 0.090 x17x12_t + 0.133 x18x12_t + -0.180 x19x12_t + 0.049 x20x12_t + -0.012 x21x12_t + -0.003 x22x12_t + 0.057 x23x12_t + 0.029 x24x12_t + -0.006 x0x13_t + -0.072 x1x13_t + 0.013 x2x13_t + -0.047 x3x13_t + -0.150 x4x13_t + 0.004 x5x13_t + 0.037 x6x13_t + 0.048 x7x13_t + 0.049 x8x13_t + 0.003 x9x13_t + 0.050 x10x13_t + -0.076 x11x13_t + 0.022 x12x13_t + -0.063 x13x13_t + 0.014 x14x13_t + 0.070 x15x13_t + -0.044 x16x13_t + -0.077 x17x13_t + 0.054 x18x13_t + 0.020 x19x13_t + 0.145 x20x13_t + 0.023 x21x13_t + 0.076 x22x13_t + -0.078 x23x13_t + -0.020 x24x13_t + 0.155 x0x14_t + 0.209 x1x14_t + -0.057 x2x14_t + 0.046 x3x14_t + -0.103 x4x14_t + 0.021 x5x14_t + 0.006 x6x14_t + -0.060 x7x14_t + 0.013 x8x14_t + -0.079 x9x14_t + -0.055 x10x14_t + -0.065 x11x14_t + 0.013 x12x14_t + -0.006 x13x14_t + -0.016 x14x14_t + -0.153 x15x14_t + 0.108 x16x14_t + -0.004 x17x14_t + 0.024 x18x14_t + 0.084 x19x14_t + -0.158 x20x14_t + 0.034 x21x14_t + -0.138 x22x14_t + -0.094 x23x14_t + 0.214 x24x14_t + 0.115 x0x15_t + 0.067 x1x15_t + 0.037 x2x15_t + -0.012 x3x15_t + -0.183 x4x15_t + -0.066 x5x15_t + -0.236 x6x15_t + -0.079 x7x15_t + 0.033 x8x15_t + 0.076 x9x15_t + -0.048 x10x15_t + 0.009 x11x15_t + -0.028 x12x15_t + -0.288 x13x15_t + 0.082 x14x15_t + 0.038 x15x15_t + -0.032 x16x15_t + 0.196 x17x15_t + -0.069 x18x15_t + -0.024 x19x15_t + 0.277 x20x15_t + 0.110 x21x15_t + 0.068 x22x15_t + 0.025 x23x15_t + -0.073 x24x15_t + -0.293 x0x16_t + 0.096 x1x16_t + 0.159 x2x16_t + -0.189 x3x16_t + 0.007 x4x16_t + 0.092 x5x16_t + 0.292 x6x16_t + -0.097 x7x16_t + -0.208 x8x16_t + -0.206 x9x16_t + 0.068 x10x16_t + -0.130 x11x16_t + 0.145 x12x16_t + -0.001 x13x16_t + -0.009 x14x16_t + -0.046 x15x16_t + 0.171 x16x16_t + 0.162 x17x16_t + -0.147 x18x16_t + -0.108 x19x16_t + 0.036 x20x16_t + -0.109 x21x16_t + -0.002 x22x16_t + 0.188 x23x16_t + 0.082 x24x16_t + -0.008 x0x17_t + -0.027 x1x17_t + -0.038 x2x17_t + 0.018 x3x17_t + 0.081 x4x17_t + -0.053 x5x17_t + 0.076 x6x17_t + 0.042 x7x17_t + -0.023 x8x17_t + -0.010 x9x17_t + -0.018 x10x17_t + 0.065 x12x17_t + -0.027 x13x17_t + -0.033 x14x17_t + -0.129 x15x17_t + -0.083 x16x17_t + -0.012 x17x17_t + -0.054 x18x17_t + -0.118 x19x17_t + 0.016 x20x17_t + 0.206 x21x17_t + 0.175 x22x17_t + 0.047 x23x17_t + -0.108 x24x17_t + 0.108 x0x18_t + -0.162 x1x18_t + -0.011 x2x18_t + 0.039 x3x18_t + 0.023 x4x18_t + 0.004 x5x18_t + -0.186 x6x18_t + 0.036 x7x18_t + -0.042 x8x18_t + 0.045 x9x18_t + 0.066 x10x18_t + 0.060 x11x18_t + -0.117 x12x18_t + 0.017 x13x18_t + 0.047 x14x18_t + 0.068 x15x18_t + -0.084 x16x18_t + 0.043 x17x18_t + 0.029 x18x18_t + -0.070 x19x18_t + 0.149 x20x18_t + -0.008 x21x18_t + 0.004 x22x18_t + 0.039 x23x18_t + -0.061 x24x18_t + -0.074 x0x19_t + -0.024 x1x19_t + -0.094 x2x19_t + -0.013 x3x19_t + -0.133 x4x19_t + 0.018 x5x19_t + 0.023 x6x19_t + -0.095 x7x19_t + 0.056 x8x19_t + 0.015 x9x19_t + -0.061 x10x19_t + -0.030 x11x19_t + 0.091 x12x19_t + -0.062 x13x19_t + -0.024 x14x19_t + 0.062 x15x19_t + 0.237 x16x19_t + 0.030 x17x19_t + 0.257 x18x19_t + 0.017 x19x19_t + -0.023 x20x19_t + -0.332 x21x19_t + -0.050 x22x19_t + 0.081 x23x19_t + 0.128 x24x19_t + 0.004 x0x20_t + -0.036 x1x20_t + 0.019 x2x20_t + -0.074 x3x20_t + 0.127 x4x20_t + -0.197 x5x20_t + 0.225 x6x20_t + 0.153 x7x20_t + -0.148 x8x20_t + 0.029 x9x20_t + 0.008 x10x20_t + -0.128 x11x20_t + -0.113 x12x20_t + -0.148 x13x20_t + 0.070 x14x20_t + -0.105 x15x20_t + 0.024 x16x20_t + 0.086 x17x20_t + -0.222 x18x20_t + 0.010 x19x20_t + 0.140 x20x20_t + 0.118 x21x20_t + -0.006 x22x20_t + 0.169 x23x20_t + 0.040 x24x20_t + 0.041 x0x21_t + -0.007 x1x21_t + -0.202 x2x21_t + 0.078 x3x21_t + 0.158 x4x21_t + -0.230 x5x21_t + 0.051 x6x21_t + -0.024 x7x21_t + 0.053 x8x21_t + 0.035 x9x21_t + 0.064 x10x21_t + 0.052 x11x21_t + -0.061 x12x21_t + 0.101 x13x21_t + -0.017 x14x21_t + -0.068 x15x21_t + -0.017 x16x21_t + -0.045 x17x21_t + 0.086 x18x21_t + 0.067 x19x21_t + -0.020 x20x21_t + 0.011 x21x21_t + 0.051 x22x21_t + -0.036 x23x21_t + -0.016 x24x21_t + 0.001 x0x22_t + 0.043 x1x22_t + -0.109 x2x22_t + 0.084 x3x22_t + 0.420 x4x22_t + -0.043 x5x22_t + 0.031 x6x22_t + -0.036 x7x22_t + -0.158 x8x22_t + -0.048 x9x22_t + 0.072 x10x22_t + 0.227 x11x22_t + 0.068 x12x22_t + 0.006 x13x22_t + 0.142 x14x22_t + -0.143 x15x22_t + -0.109 x16x22_t + -0.083 x17x22_t + -0.148 x18x22_t + -0.005 x19x22_t + -0.098 x20x22_t + -0.094 x21x22_t + 0.058 x22x22_t + -0.074 x23x22_t + 0.002 x24x22_t + -0.125 x0x23_t + -0.044 x1x23_t + 0.208 x2x23_t + -0.015 x3x23_t + 0.274 x4x23_t + -0.084 x5x23_t + -0.162 x6x23_t + 0.086 x7x23_t + 0.192 x8x23_t + 0.087 x9x23_t + -0.089 x10x23_t + 0.009 x11x23_t + -0.109 x12x23_t + 0.134 x13x23_t + 0.088 x14x23_t + 0.131 x15x23_t + -0.148 x16x23_t + -0.097 x17x23_t + 0.023 x18x23_t + 0.058 x19x23_t + -0.145 x20x23_t + 0.037 x21x23_t + -0.047 x22x23_t + -0.081 x23x23_t + -0.114 x24x23_t + 0.047 x0x24_t + -0.123 x1x24_t + 0.132 x2x24_t + 0.012 x3x24_t + -0.258 x4x24_t + 0.023 x5x24_t + 0.052 x6x24_t + 0.016 x7x24_t + -0.124 x8x24_t + 0.113 x9x24_t + -0.088 x10x24_t + -0.009 x11x24_t + 0.005 x12x24_t + 0.052 x13x24_t + -0.091 x14x24_t + 0.103 x15x24_t + -0.071 x16x24_t + -0.099 x17x24_t + 0.054 x18x24_t + -0.050 x19x24_t + 0.130 x20x24_t + 0.123 x21x24_t + 0.084 x22x24_t + 0.009 x23x24_t + -0.069 x24x24_t

Similarly, I am getting 25 equations, for 25 stations. "(*spatial terms, time, coordinate/feature)" is showing index error. I wanted to improve this, as the number of terms are getting too big for each discovered equation. OTOH, accuracy is good, around 93%-97%.

@Jacob-Stevens-Haas
Copy link
Collaborator

  1. (*spatial terms, time, coordinate/feature) was pseudocode meant to show axis ordering
  2. SINDyPI Tends to work best with only a few terms. Why did you choose SINDyPI?
  3. Accuracy might be good simply because you have so many terms.
  4. It's still not clear what you're asking for. Let's reduce the number of stations in examples to 2 or 3.

@rijul01
Copy link
Author

rijul01 commented Jun 10, 2024

Hello,

Thank you for the quick reply.

  1. When I use other optimizers, the resulting equations are overly simplistic, often resulting in (x0)' = 1 x0_t and similar forms for other features. Therefore, I opted for SINDyPI to obtain more meaningful equations. Is there an alternative approach to resolve this issue with other optimizers?

  2. I have tested the model with a reduced number of stations (2-3 stations), which results in feature libraries containing around 8-19 terms. In these cases, the accuracy remains high. However, I still used SINDyPI for these models as well. For 2-3 stations, results are somewhat interpretable but it would be really good if this feature library can take spatial derivatives (on non-uniform data) too. Can we create a function for this where we are explicitly calculating spatial derivatives and then include that in the 'feature_library'?

  3. My goal is to understand the influence of other stations (x_j ∈ [0, 24] and i≠j) on the CO2 concentration at the target station (x_i). With SINDyPI, the derived equations become too lengthy and complex to interpret, as you have pointed out. Is there a way to simplify these equations or use another method to achieve clearer insights?

This is for 3 stations using STLSQ:
Feature names: ['1', 'x0', 'x1', 'x2', 'x0_t', 'x1_t', 'x2_t', '1x0_t', 'x0x0_t', 'x1x0_t', 'x2x0_t', '1x1_t', 'x0x1_t', 'x1x1_t', 'x2x1_t', '1x2_t', 'x0x2_t', 'x1x2_t', 'x2x2_t']
Feature length: 19
(x0)' = 1.000 1x0_t
(x1)' = 1.000 1x1_t
(x2)' = 1.000 1x2_t

Using SR3 (L0):
code:
optimizer = ps.SR3( threshold=0.1, max_iter=10000, tol=1e-10, nu=1e1, thresholder="l0", normalize_columns=True, ) model = ps.SINDy(feature_library=pde_lib, optimizer = optimizer, feature_names=["x0", "x1", "x2"]

Output:
(x0)' = 0.500 x0_t + 0.500 1x0_t
(x1)' = 0.500 x1_t + 0.500 1x1_t
(x2)' = 0.500 x2_t + 0.500 1x2_t

With SR3 (l2):
(x0)' = 0.496 x0_t + 0.496 1x0_t
(x1)' = 0.495 x1_t + 0.495 1x1_t
(x2)' = 0.495 x2_t + 0.495 1x2_t

SSR model:
(x0)' = 2.932 x0_t + -1.932 1x0_t
(x1)' = 2.587 x1_t + -1.587 1x1_t
(x2)' = -0.015 x2_t + 1.015 1x2_t

SSR (metric = model residual) model:
(x0)' = 2.932 x0_t + -1.932 1x0_t
(x1)' = 2.587 x1_t + -1.587 1x1_t
(x2)' = -0.015 x2_t + 1.015 1x2_t

@Jacob-Stevens-Haas
Copy link
Collaborator

Jacob-Stevens-Haas commented Jun 17, 2024

If you are using implicit_terms=True, you have to use SINDyPIOptimizer. Thus, if you're not doing SINDy-PI, you can't use implicit_terms=True.

The line:

 (x0)' = 0.500 x0_t + 0.500 1x0_t

simply says $\frac{dx_0}{dt}={x_0}_t$

@rijul01 rijul01 closed this as completed Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants