4.10. Relative Score Method — General
- imselection.compute_rsm_general(demands, im1_values, im2_values, pdf_func_im1, pdf_func_im2)[source]
General Relative Sufficiency Measure using user-supplied PDF callables.
Implements Equation 1 of Ebrahimian & Jalayer (2021). Useful for custom demand models or non-lognormal formulations.
- Parameters:
demands (array_like) – EDP value for each record, shape
(N,).im1_values (array_like) – IM₁ value for each record, shape
(N,).im2_values (array_like) – IM₂ value for each record, shape
(N,).pdf_func_im1 (callable) –
f(d_k, im1_k) → float— probability density of demand d_k given IM₁ = im1_k.pdf_func_im2 (callable) –
f(d_k, im2_k) → float— same for IM₂.
- Returns:
dict with keys
*
'rsm'— scalar RSM in bits*
'rsm_per_record'— ndarray of per-record log₂ ratios*
'n_records'— total records*
'n_valid'— records with finite log₂ ratio*
'method'—'general'
Example
from openquake.vmtk.imselection import imselection
import numpy as np
from scipy.stats import lognorm
ims = imselection()
# f(d, im): density of the demand d given the IM, here a lognormal
# model ln(d) ~ N(ln(a) + b ln(im), sigma) with user-fitted (a, b, sigma)
def pdf_im1(d, im, a=0.01, b=1.0, sigma=0.4):
return lognorm.pdf(d, s=sigma, scale=a * im**b)
def pdf_im2(d, im, a=0.012, b=0.9, sigma=0.6):
return lognorm.pdf(d, s=sigma, scale=a * im**b)
# demands, im1_values, im2_values: 1-D arrays of equal length
result = ims.compute_rsm_general(
demands, im1_values, im2_values, pdf_im1, pdf_im2
)
print(f"RSM = {result['rsm']:.4f} bits")