Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions simpeg/dask/electromagnetics/static/resistivity/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import numcodecs

import warnings

warnings.filterwarnings("ignore", category=FutureWarning)

numcodecs.blosc.use_threads = False

Sim.sensitivity_path = "./sensitivity/"
Expand Down
4 changes: 2 additions & 2 deletions simpeg/dask/inverse_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def dask_evalFunction(self, m, return_g=True, return_H=True):
self.dpred = self.get_dpred(m, compute_J=return_H)

phi_d = 0
for (mult, objfct), pred in zip(self.dmisfit, self.dpred):
for (_, objfct), pred in zip(self.dmisfit, self.dpred):
residual = objfct.W * (objfct.data.dobs - pred)
phi_d += mult * np.vdot(residual, residual)
phi_d += np.vdot(residual, residual)

phi_d = np.asarray(phi_d)
# print(self.dpred[0])
Expand Down
29 changes: 16 additions & 13 deletions simpeg/directives/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -3586,7 +3586,7 @@ def __init__(self, path: Path | None, **kwargs):
def initialize(self):
self.last_beta = self.invProb.beta
self.multipliers = self.invProb.dmisfit.multipliers

self.scalings = np.ones_like(self.multipliers)
with open(self.filepath, "w", encoding="utf-8") as f:
f.write("Logging of [scaling * chi factor] per misfit function.\n\n")
f.write(
Expand All @@ -3599,28 +3599,31 @@ def initialize(self):

def endIter(self):
ratio = self.invProb.beta / self.last_beta

if ratio > 1:
return

chi_factors = []
phi_ds = []
for objfct, pred in zip(self.invProb.dmisfit.objfcts, self.invProb.dpred):
residual = objfct.W * (objfct.data.dobs - pred)
phi_d = np.vdot(residual, residual)
chi_factors.append(phi_d / objfct.nD)
phi_ds.append(phi_d)

phi_ds = np.asarray(phi_ds)
chi_factors = np.asarray(chi_factors)
scalings = chi_factors / chi_factors.max()

# Force beta ratio scaling if below target
scalings[chi_factors < 1] *= ratio
# Normalize scaling between [ratio, 1]
scalings = (
1 - (1 - ratio) * (chi_factors.max() - chi_factors) / chi_factors.max()
)

# Force the ones that overshot target
scalings[chi_factors < 1] = ratio * chi_factors[chi_factors < 1]

# Update the scaling
self.scalings *= scalings

# Normalize total phi_d with scalings
multipliers = (
self.multipliers
* scalings
* phi_ds.sum()
/ (self.multipliers * phi_ds * scalings).sum()
)
multipliers = self.multipliers * self.scalings

with open(self.filepath, "a", encoding="utf-8") as f:
f.write(
Expand Down