Soundscape Perception Indices (SPI) Reference
This section provides an overview of the tools for using the Soundscape Perception Indices (SPI) framework. It includes a brief description of each tool, as well as information on how to access and use them.
Soundscapy Psychoacoustic Indicator (SPI) calculation module.
This module provides functions and classes for calculating SPI, based on the R implementation. Requires optional dependencies.
MODULE | DESCRIPTION |
---|---|
ks2d |
|
msn |
Module for handling Multi-dimensional Skewed Normal (MSN) distributions. |
CLASS | DESCRIPTION |
---|---|
CentredParams |
Represents the centered parameters of a distribution. |
DirectParams |
Represents a set of direct parameters for a statistical model. |
MultiSkewNorm |
A class representing a multi-dimensional skewed normal distribution. |
FUNCTION | DESCRIPTION |
---|---|
cp2dp |
Convert centred parameters to direct parameters. |
dp2cp |
Convert direct parameters to centred parameters. |
spi_score |
Compute the Soundscape Perception Index (SPI). |
CentredParams
CentredParams(mean, sigma, skew)
Represents the centered parameters of a distribution.
PARAMETER | DESCRIPTION |
---|---|
mean
|
The mean of the distribution.
TYPE:
|
sigma
|
The standard deviation of the distribution.
TYPE:
|
skew
|
The skewness of the distribution.
TYPE:
|
ATTRIBUTE | DESCRIPTION |
---|---|
mean |
The mean of the distribution.
TYPE:
|
sigma |
The standard deviation of the distribution.
TYPE:
|
skew |
The skewness of the distribution.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
from_dp |
Converts DirectParams object to CentredParams object. |
Initialize CentredParams instance.
Source code in soundscapy/spi/msn.py
161 162 163 164 165 |
|
__repr__
__repr__()
Return a string representation of the CentredParams object.
Source code in soundscapy/spi/msn.py
167 168 169 |
|
__str__
__str__()
Return a user-friendly string representation of the CentredParams object.
Source code in soundscapy/spi/msn.py
171 172 173 174 175 176 177 178 |
|
from_dp
classmethod
from_dp(dp)
Convert a DirectParams object to a CentredParams object.
PARAMETER | DESCRIPTION |
---|---|
dp
|
The DirectParams object to convert.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CentredParams
|
A new CentredParams object with the converted parameters. |
Source code in soundscapy/spi/msn.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
DirectParams
DirectParams(xi, omega, alpha)
Represents a set of direct parameters for a statistical model.
Direct parameters are the parameters that are directly used in the model. They are the parameters that are used to define the distribution of the data. In the case of a skew normal distribution, the direct parameters are the xi, omega, and alpha values.
PARAMETER | DESCRIPTION |
---|---|
xi
|
The location of the distribution in 2D space, represented as a 2x1 array with the x and y coordinates.
TYPE:
|
omega
|
The covariance matrix of the distribution, represented as a 2x2 array. The covariance matrix represents the measure of the relationship between different variables. It provides information about how changes in one variable are associated with changes in other variables.
TYPE:
|
alpha
|
The shape parameters for the x and y dimensions, controlling the shape (skewness) of the distribution. It is represented as a 2x1 array.
TYPE:
|
Initialize DirectParams instance.
METHOD | DESCRIPTION |
---|---|
__repr__ |
Return a string representation of the DirectParams object. |
__str__ |
Return a user-friendly string representation of the DirectParams object. |
from_cp |
Convert a CentredParams object to a DirectParams object. |
validate |
Validate the direct parameters. |
Source code in soundscapy/spi/msn.py
48 49 50 51 52 53 |
|
__repr__
__repr__()
Return a string representation of the DirectParams object.
Source code in soundscapy/spi/msn.py
55 56 57 |
|
__str__
__str__()
Return a user-friendly string representation of the DirectParams object.
Source code in soundscapy/spi/msn.py
59 60 61 62 63 64 65 66 |
|
from_cp
classmethod
from_cp(cp)
Convert a CentredParams object to a DirectParams object.
PARAMETER | DESCRIPTION |
---|---|
cp
|
The CentredParams object to convert.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DirectParams
|
A new DirectParams object with the converted parameters. |
Source code in soundscapy/spi/msn.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
validate
validate()
Validate the direct parameters.
In a skew normal distribution, the covariance matrix, often denoted as Ω (Omega), represents the measure of the relationship between different variables. It provides information about how changes in one variable are associated with changes in other variables. The covariance matrix must be positive definite and symmetric.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the direct parameters are not valid. |
RETURNS | DESCRIPTION |
---|---|
None
|
|
Source code in soundscapy/spi/msn.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
MultiSkewNorm
MultiSkewNorm()
A class representing a multi-dimensional skewed normal distribution.
ATTRIBUTE | DESCRIPTION |
---|---|
selm_model |
The fitted SELM model.
|
cp |
The centred parameters of the fitted model.
TYPE:
|
dp |
The direct parameters of the fitted model.
TYPE:
|
sample_data |
The generated sample data from the fitted model.
TYPE:
|
data |
The input data used for fitting the model.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
summary |
Prints a summary of the fitted model. |
fit |
Fits the model to the provided data. |
define_dp |
Defines the direct parameters of the model. |
sample |
Generates a sample from the fitted model. |
sspy_plot |
Plots the joint distribution of the generated sample. |
ks2ds |
Computes the two-sample Kolmogorov-Smirnov statistic. |
spi |
Computes the similarity percentage index. |
Initialize the MultiSkewNorm object.
Source code in soundscapy/spi/msn.py
236 237 238 239 240 241 242 |
|
__repr__
__repr__()
Return a string representation of the MultiSkewNorm object.
Source code in soundscapy/spi/msn.py
244 245 246 247 248 |
|
define_dp
define_dp(xi, omega, alpha)
Initiate a distribution from the direct parameters.
PARAMETER | DESCRIPTION |
---|---|
xi
|
The xi values of the direct parameters.
TYPE:
|
omega
|
The omega values of the direct parameters.
TYPE:
|
alpha
|
The alpha values of the direct parameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
self
|
|
Source code in soundscapy/spi/msn.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
fit
fit(data=None, x=None, y=None)
Fit the multi-dimensional skewed normal model to the provided data.
PARAMETER | DESCRIPTION |
---|---|
data
|
The input data as a pandas DataFrame or numpy array.
TYPE:
|
x
|
The x-values of the input data as a numpy array or pandas Series.
TYPE:
|
y
|
The y-values of the input data as a numpy array or pandas Series.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If neither |
Source code in soundscapy/spi/msn.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
from_params
classmethod
from_params(params=None, *, xi=None, omega=None, alpha=None, mean=None, sigma=None, skew=None)
Create a MultiSkewNorm instance from direct parameters.
PARAMETER | DESCRIPTION |
---|---|
params
|
The direct parameters to initialize the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
MultiSkewNorm
|
A new instance of MultiSkewNorm initialized with the provided parameters. |
Source code in soundscapy/spi/msn.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
|
ks2d2s
ks2d2s(test)
Compute the two-sample, two-dimensional Kolmogorov-Smirnov statistic.
PARAMETER | DESCRIPTION |
---|---|
test
|
The test data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
The KS2D statistic and p-value. |
Source code in soundscapy/spi/msn.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
|
sample
sample(n=1000, *, return_sample=False)
Generate a sample from the fitted model.
PARAMETER | DESCRIPTION |
---|---|
n
|
The number of samples to generate, by default 1000.
TYPE:
|
return_sample
|
Whether to return the generated sample as an np.ndarray, by default False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None or ndarray
|
The generated sample if |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the model is not fitted (i.e., |
Source code in soundscapy/spi/msn.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
sample_mtsn
sample_mtsn(n=1000, a=-1, b=1, *, return_sample=False)
Generate a sample from the multi-dimensional truncated skew-normal distribution.
Uses rejection sampling to ensure that the samples are within the bounds [a, b] for both dimensions.
PARAMETER | DESCRIPTION |
---|---|
n
|
The number of samples to generate, by default 1000.
TYPE:
|
a
|
Lower truncation bound for both dimensions, by default -1.
TYPE:
|
b
|
Upper truncation bound for both dimensions, by default 1.
TYPE:
|
return_sample
|
Whether to return the generated sample as an np.ndarray, by default False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None or ndarray
|
The generated sample if |
Source code in soundscapy/spi/msn.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
|
spi_score
spi_score(test)
Compute the Soundscape Perception Index (SPI).
Calculates the SPI for the test data against the target distribution represented by this MultiSkewNorm instance.
PARAMETER | DESCRIPTION |
---|---|
test
|
The test data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The Soundscape Perception Index (SPI), ranging from 0 to 100. |
Source code in soundscapy/spi/msn.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
|
sspy_plot
sspy_plot(color='blue', title=None, n=1000)
Plot the joint distribution of the generated sample using soundscapy.
PARAMETER | DESCRIPTION |
---|---|
color
|
Color for the density plot, by default "blue".
TYPE:
|
title
|
Title for the plot, by default None.
TYPE:
|
n
|
Number of samples to generate if
TYPE:
|
Source code in soundscapy/spi/msn.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
summary
summary()
Provide a summary of the fitted MultiSkewNorm model.
RETURNS | DESCRIPTION |
---|---|
str or None
|
A string summarizing the model parameters and data, or a message indicating the model is not fitted. Returns None if fitted but summary logic is not fully implemented yet. |
Source code in soundscapy/spi/msn.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
cp2dp
cp2dp(cp, family='SN')
Convert centred parameters to direct parameters.
PARAMETER | DESCRIPTION |
---|---|
cp
|
The centred parameters object.
TYPE:
|
family
|
The distribution family, by default "SN" (Skew Normal).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DirectParams
|
The corresponding direct parameters object. |
Source code in soundscapy/spi/msn.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 |
|
dp2cp
dp2cp(dp, family='SN')
Convert direct parameters to centred parameters.
PARAMETER | DESCRIPTION |
---|---|
dp
|
The direct parameters object.
TYPE:
|
family
|
The distribution family, by default "SN" (Skew Normal).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CentredParams
|
The corresponding centred parameters object. |
Source code in soundscapy/spi/msn.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
|
spi_score
spi_score(target, test)
Compute the Soundscape Perception Index (SPI).
Calculates the SPI for the test data against the target distribution represented by the sample data.
PARAMETER | DESCRIPTION |
---|---|
target
|
The sample data representing the target distribution.
TYPE:
|
test
|
The test data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The Soundscape Perception Index (SPI), ranging from 0 to 100. |
Source code in soundscapy/spi/msn.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
|
options: show_root_heading: false show_root_toc_entry: false show_submodules: true members: - msn