tobiscode / disstans

Package repository for the Decomposition and Inference of Sources through Spatiotemporal Analysis of Network Signals (DISSTANS) toolbox.
https://tobiscode.github.io/disstans/
GNU General Public License v3.0
22 stars 7 forks source link

Tutorial_1 cannot fit the third step offset? #6

Closed GEOSCIENCELXG closed 1 day ago

GEOSCIENCELXG commented 1 week ago

I tried the code tutorial_1_simple_timeseries.py, and I just changed the value of the third step from -0.01 to 0.1, the result shows the third step cannot be reproduced (see attached plot).

mdl_steps.read_parameters(np.array([0.5, 0.2, -0.01])) > mdl_steps.read_parameters(np.array([0.5, 0.2, 0.1]))

data_model_fit

tobiscode commented 1 week ago

Hi,

sorry but I cannot recreate this problem. I changed the value in the script, then ran the script from scratch, and then got this plot:

grafik

When you changed the values, did you make sure to run the fitting and evaluation algorithm again, and then plot the output of the new fit? I.e., after changing your input data, did you run linear_regression, read_parameters, and evaluate (lines 61-80) again?

If that doesn't solve your issue, please upload a version of the script that recreates your problem so I can take a closer look.

Thanks

GEOSCIENCELXG commented 1 week ago

Thanks, I run lines 61-80 after changing the parameter, but I run the lines one by one in python, which will raise the problem. The problem will be solved if I run the whole script with : python tutorial_1_simple_timeseries.py in terminal.

tobiscode commented 3 days ago

Hi,

I still can't recreate your problem. I ran the original script once, then continued line by line from line 22 with the modified parameters. I'm getting the same plot as I posted above. Maybe you're skipping steps? The following lines are necessary: 30-41 create the new timeseries, line 42 overwrites the Timeseries object called "Data" at the Station object, line 47 re-adds the noise, lines 56-57 add the models to fit to the station (since we've overwritten the station's timeseries object in line 42), and then lines 61 onwards re-fit the data.

If you don't want to recreate the entire Timeseries and Model objects, just assign new data to the Timeseries object directly rather than completely recreating it, similar to line 47:

mdl_steps.read_parameters(np.array([0.5, 0.2, 0.1]))
sum_models = np.zeros((timevector.size, 1))
for model_description, model in collection.items():
    evaluated = model.evaluate(timevector)
    sum_models += evaluated["fit"]
synth_stat["Data"].data = sum_models + noise

And then continue from line 61.

Maybe a useful note: overwriting a timeseries assigned to a station will also remove all the models and fits that were previously computed, since there's no guarantee it has the same shape (timesteps or components), see: https://github.com/tobiscode/disstans/blob/b92299eba9a951be70ca2956bf1f98101678dc7d/disstans/station.py#L311-L313

Hope that helps!