MCPcopy Create free account
hub / github.com/Open-Quant/openquant / _power_iteration

Function _power_iteration

python/openquant/feature_diagnostics.py:478–489  ·  view source on GitHub ↗
(a: list[list[float]], iters: int = 200)

Source from the content-addressed store, hash-verified

476 n = len(x)
477 p = len(x[0])
478 means = [sum(row[j] for row in x) / n for j in range(p)]
479 stds = []
480 for j in range(p):
481 var = sum((row[j] - means[j]) ** 2 for row in x) / max(n - 1, 1)
482 stds.append(sqrt(var) if var > 0 else 1.0)
483
484 z = [[(row[j] - means[j]) / stds[j] for j in range(p)] for row in x]
485 return z, means, stds
486
487
488def _mat_vec(a: Sequence[Sequence[float]], v: Sequence[float]) -> list[float]:
489 return [sum(aij * vj for aij, vj in zip(row, v)) for row in a]
490
491
492def _norm(v: Sequence[float]) -> float:

Callers 1

Calls 3

_mat_vecFunction · 0.85
_dotFunction · 0.85
_normFunction · 0.70

Tested by

no test coverage detected