Class KPCFitKt

  • All Implemented Interfaces:

    
    public final class KPCFitKt
    
                        
    • Constructor Detail

    • Method Detail

      • kpcfit_init

         final static TraceData kpcfit_init(DoubleArray S, IntArray acLags, IntArray bcGridLags)

        Initializes trace data for KPC fitting. Computes moments, autocorrelations, and bicovariances.

        Parameters:
        S - Input trace (inter-arrival times)
        acLags - Optional: specific lags for autocorrelation
        bcGridLags - Optional: lags for bicovariance grid
        Returns:

        TraceData structure with computed statistics

      • kpcfit_auto

         final static KPCFitResult kpcfit_auto(TraceData trace, KPCFitOptions options)

        Automatic KPC fitting of a trace to a MAP.

        Parameters:
        trace - Prepared trace data from kpcfit_init
        options - Fitting options
        Returns:

        KPCFitResult with fitted MAP and diagnostics

      • kpcfit_sub_bic

         final static Integer kpcfit_sub_bic(DoubleArray ACFull, IntArray orders)

        BIC-based order selection for KPC fitting.

        Fix 2: Replaced heuristic with proper BIC regression algorithm matching MATLAB kpcfit_sub_bic.m. For each candidate order, fits AR(p) model via OLS regression, computes residual SSE, then applies Schwarz Bayesian Criterion: SBC = nlog(SSE) - nlog(n) + log(n)*order. Returns log2 of the order that minimizes SBC.

        Parameters:
        ACFull - Full autocorrelation sequence (SA in MATLAB)
        orders - Candidate orders (powers of 2)
        Returns:

        Nstar = log2(best order)

      • kpcfit_sub_eval_acfit

         final static Pair<Double, DoubleArray> kpcfit_sub_eval_acfit(DoubleArray SCVj, DoubleArray G2j, IntArray lags)

        Evaluates ACF for given SCV and G2 parameters.

        Fix 1: Replaced simplified additive formula with exact iterative algorithm from MATLAB kpcfit_sub_eval_iat2.m. The key difference is the cross-term SCVj_1acfCoeff(1+X) in the numerator of the iterative update.

        MATLAB algorithm: SCVj = SCV(1); acfCoeff = 0.5*(1-1/SCV(1))G2(1).^acfLag; for j=2:J SCVj_1 = SCVj; SCVj = (1+SCVj)(1+SCV(j))/2 - 1; r0j = 0.5*(1-1/SCV(j)); X = SCV(j)r0jG2(j).^acfLag; acfCoeff = (X + SCVj_1acfCoeff.(1+X)) / SCVj; end

      • kpcfit_sub_bcfit

         final static Triple<DoubleArray, DoubleArray, Double> kpcfit_sub_bcfit(DoubleArray E, DoubleArray SCVj, DoubleArray G2j, DoubleArray BC, Array<IntArray> BCLags, Integer maxIterBC, Integer maxRunsBC)

        Bicovariance fitting sub-routine.

        Fix 3: Replaced random stub with proper optimization matching MATLAB kpcfit_sub_bcfit.m. Uses Nelder-Mead optimization (approximating MATLAB fmincon) with:

        • Proper initialization: E1j = E(1)^(1/J) * ones(1,J)

        • Actual bicovariance objective via kpcfit_sub_compose + map_joint

        • Multiple random restarts with best-of tracking

        • Constraint enforcement via penalty terms

      • kpcfit_hyper_charpoly

         final static DoubleArray kpcfit_hyper_charpoly(DoubleArray E, Integer n)

        Computes the characteristic polynomial coefficients for a hyper-exponential distribution from its moments, using the Prony method.

        Ported from MATLAB: kpcfit_hyper_charpoly.m

        Parameters:
        E - Array of moments EX, EX^2, ...
        n - Number of exponential phases
        Returns:

        Coefficients of the characteristic polynomial (n+1 elements)

      • kpcfit_ph_prony

         final static MatrixCell kpcfit_ph_prony(DoubleArray E, Integer n)

        Fits a hyper-exponential PH distribution using Prony's method.

        Ported from MATLAB: kpcfit_ph_prony.m

        Parameters:
        E - Array of moments EX, EX^2, ...
        n - Number of exponential phases
        Returns:

        MatrixCell with D0 and D1 matrices of the PH distribution

      • kpcfit_ph_options

         final static KPCFitPhOptions kpcfit_ph_options(DoubleArray E, Boolean verbose, Integer runs, Integer minNumStates, Integer maxNumStates, Integer minExactMom)

        Factory function for KPCFitPhOptions with validation. Validates options (power-of-2 checks, range checks, moment sufficiency checks).

        Ported from MATLAB: kpcfit_ph_options.m

        Parameters:
        E - Array of moments
        verbose - Whether to print verbose output
        runs - Maximum number of optimization runs
        minNumStates - Minimum number of states (must be power of 2)
        maxNumStates - Maximum number of states (must be power of 2)
        minExactMom - Minimum number of moments to be fitted exactly
        Returns:

        Validated KPCFitPhOptions

      • kpcfit_ph_exact

         final static List<MatrixCell> kpcfit_ph_exact(DoubleArray E, KPCFitPhOptions options)

        Exact PH fitting using Prony's method (SCV 1), PH(2) fitting (SCV < 1), or exponential (SCV == 1).

        Ported from MATLAB: kpcfit_ph_exact.m

        Parameters:
        E - Array of moments (normalized to mean=1)
        options - Fitting options
        Returns:

        List of feasible PH distributions as MatrixCells

      • kpcfit_ph_search

         final static Triple<MatrixCell, Double, DoubleArray> kpcfit_ph_search(DoubleArray E, Integer J, KPCFitPhOptions options, DoubleArray x0, Integer maxAphOrder)

        Optimization-based search for PH distributions using KPC composition. Works in log-moment space with penalty-based constraint enforcement.

        Ported from MATLAB: kpcfit_ph_search.m

        Parameters:
        E - Array of moments (normalized to mean=1)
        J - Number of PH(2) sub-distributions to compose (total states = 2^J)
        options - Fitting options
        x0 - Initial point (optional)
        maxAphOrder - Maximum APH order for SCV < 1 case (optional)
        Returns:

        Triple of (composed MAP, objective value, optimization variable x)

      • psfit_hyperexp_weighted

         final static Triple<MatrixCell, DoubleArray, DoubleArray> psfit_hyperexp_weighted(DoubleArray E, Integer n)

        Fits a hyperexponential distribution with n states using constrained optimization in parameter space with weighted log-moment objective.

        Ported from MATLAB: psfit_hyperexp_weighted.m

        Parameters:
        E - Array of moments
        n - Number of states (exponential phases)
        Returns:

        Triple of (PH distribution, approximate moments, optimization variables)

      • psfit_aph_weighted

         final static Triple<MatrixCell, DoubleArray, DoubleArray> psfit_aph_weighted(DoubleArray E, Integer n)

        Fits an acyclic PH (APH) distribution with n states using constrained optimization in parameter space with weighted log-moment objective.

        The difference from psfit_hyperexp_weighted is the T matrix structure: T = diag(-1/xn:2n) + diag(1/xn:2n-1, 1) (upper bidiagonal)

        Ported from MATLAB: psfit_aph_weighted.m

        Parameters:
        E - Array of moments
        n - Number of states
        Returns:

        Triple of (PH distribution, approximate moments, optimization variables)

      • kpcfit_ph_auto

         final static Array<Array<Object>> kpcfit_ph_auto(DoubleArray E, KPCFitPhOptions options)

        Automatic PH distribution fitting from moments. Combines exact fitting, KPC-based approximate fitting (moment space), and parameter-space fitting (hyperexp or APH).

        Ported from MATLAB: kpcfit_ph_auto.m

        Parameters:
        E - Array of moments EX, EX^2, ...
        options - Fitting options
        Returns:

        Array of rows where each row is: PH (MatrixCell), dist (Double), x (DoubleArray?), method (String)

      • kpcfit_ph_summary

         final static String kpcfit_ph_summary(Array<Array<Object>> PH, DoubleArray E)

        Returns a formatted summary string for PH fitting results. Analogous to the MATLAB kpcfit_ph_summary script (without plotting).

        Parameters:
        PH - Results array from kpcfit_ph_auto: each row is PH, dist, x, method
        E - Original moments array
        Returns:

        Formatted summary string