Skip to content

Conversation

@Nikongen
Copy link
Contributor

@Nikongen Nikongen commented Sep 5, 2025

Fixes #143

Validated using

import numpy as np
import pycpufit.cpufit as gf


def test(n_fits: float = 1e6) -> float:
    n_fits = int(n_fits)
    params = np.random.rand(n_fits, 2).astype(np.float32)

    x = np.random.rand(n_fits, 300).astype(np.float32) * 100
    y = params[:, :1] + params[:, 1:] * x

    init_params = np.array([0.1, 0.1], dtype=np.float32)
    init_params = np.tile(init_params, (n_fits, 1))

    parameters, states, chi_squares, number_iterations, execution_time = gf.fit(
        data=y,
        weights=None,
        model_id=gf.ModelID.LINEAR_1D,
        initial_parameters=init_params,
        tolerance=1e-8,
        user_info=x
        )
    max_error = np.max(abs(params - parameters))
    print(f"\tmean abs error = {np.mean(abs(params - parameters)):2.2e}")
    print(f"\tmax abs error = {max_error:2.2e}")
    print(f"\tHas{"" if np.any(abs(params - parameters) > 1e-3) else ' no'} fit with error > 1e-3")
    return max_error


iters = 2
n_fits = 1700000
max_errors = np.zeros(iters, dtype=float)
for i in range(iters):
    print(f"Test run {i+1:3d}")
    max_errors[i] = test(n_fits)

print(f"Overall max error after : {np.max(max_errors):2.2e}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with (py)Cpufit

1 participant