keurfonluu / evodcinv

Inversion of dispersion curves using Evolutionary Algorithms
BSD 3-Clause "New" or "Revised" License
77 stars 31 forks source link

Adding a constraint for velocity increasing with depth #13

Closed ariellellouch closed 1 year ago

ariellellouch commented 1 year ago

Geologically (especially at large scales), we often want the velocity models to increase with depth. The current model parametrization doesn't really allow to do that (unless layers are mutually exclusive). Could it be possible to add a flag for this constraint, so that for the layer number n+1, the velocity will be between [velocity of layer n, max allowed velocity of layer n+1]?

Thanks again!

keurfonluu commented 1 year ago

Hi @ariellellouch,

That was actually planned, I just didn't have time to implement such feature. But basically, right now, it's possible to do it by:

But it will definitely be better to have a boolean option to automate that.

ariellellouch commented 1 year ago

Thanks! I am a bit scared to play with the extra_terms without an example, but will give it a go! :)

Edit: Quick and dirty solution which assures Vs is going up with depth (I'm sure this can be made prettier and not depend on the structure of x, but I am not a good enough coder). Adding extra_terms=inc_misfit works for me.

def inc_misfit(x): nel = int((np.size(x)-2)/3) return 999999.9 np.any(np.diff(x[nel:2nel+1])<0)

keurfonluu commented 1 year ago

As long as it works!

I added an option increasing_velocity in configure that initializes the population with increasing velocity models, and adds a penalty term to reject generated models given the constraint:

model.configure(
    optimizer="cpso",  # Evolutionary algorithm
    misfit="rmse",  # Misfit function type
    optimizer_args={
        "popsize": 10,  # Population size
        "maxiter": 100,  # Number of iterations
        "workers": -1,  # Number of cores
        "seed": 0,
    },
    increasing_velocity=True,
)

You can update to evodcinv v2.1.1: pip install evodcinv -U.

ariellellouch commented 1 year ago

Fantastic, thanks again and sorry for bugging you :)