SStepMaranta
Product

Product features · Finite Markov distribution steps

01

Keep the initial vector and transition rows together while examining how a proposed iteration preserves probability mass.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Finite Markov distribution steps

● ● ●StepMaranta●
A concrete starting point · Finite Markov distribution steps ×
from math import fsum, isfinite
def markov_steps(initial, matrix, steps):
    if type(initial) is not list or not 1 <= len(initial) <= 8:
        raise ValueError("state count")
    n = len(initial)
    if type(matrix) is not list or len(matrix) != n or any(
        type(row) is not list or len(row) != n for row in matrix):
        raise ValueError("square matrix")
    rows = [initial] + matrix
    if any(type(x) not in (int, float) or not 0 <= x <= 1 or
           not isfinite(x) for row in rows for x in row):
        raise ValueError("probability values")
    if any(abs(fsum(row)-1) > 1e-12 for row in rows):
        raise ValueError("row sums")
    if type(steps) is not int or not 0 <= steps <= 100:
        raise ValueError("step count")
    result = initial[:]
    for _ in range(steps):
        result = [fsum(result[i] * matrix[i][j] for i in range(n))
                  for j in range(n)]
    return result
✳Advance a probability vector through up to 100 transitions of a Markov matrix with at most eight states.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗