← 返回 Skills 市场
wu-uk

scipy-curve-fit

作者 wu-uk · GitHub ↗ · v0.1.0 · MIT-0
cross-platform ✓ 安全检测通过
76
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install hvac-control-scipy-curve-fit
功能描述
Use scipy.optimize.curve_fit for nonlinear least squares parameter estimation from experimental data.
使用说明 (SKILL.md)

Using scipy.optimize.curve_fit for Parameter Estimation

Overview

scipy.optimize.curve_fit is a tool for fitting models to experimental data using nonlinear least squares optimization.

Basic Usage

from scipy.optimize import curve_fit
import numpy as np

# Define your model function
def model(x, param1, param2):
    return param1 * (1 - np.exp(-x / param2))

# Fit to data
popt, pcov = curve_fit(model, x_data, y_data)

# popt contains the optimal parameters [param1, param2]
# pcov contains the covariance matrix

Fitting a First-Order Step Response

import numpy as np
from scipy.optimize import curve_fit

# Known values from experiment
y_initial = ...  # Initial output value
u = ...          # Input magnitude during step test

# Define the step response model
def step_response(t, K, tau):
    """First-order step response with fixed initial value and input."""
    return y_initial + K * u * (1 - np.exp(-t / tau))

# Your experimental data
t_data = np.array([...])  # Time points
y_data = np.array([...])  # Output readings

# Perform the fit
popt, pcov = curve_fit(
    step_response,
    t_data,
    y_data,
    p0=[K_guess, tau_guess],      # Initial guesses
    bounds=([K_min, tau_min], [K_max, tau_max])  # Parameter bounds
)

K_estimated, tau_estimated = popt

Setting Initial Guesses (p0)

Good initial guesses speed up convergence:

# Estimate K from steady-state data
K_guess = (y_data[-1] - y_initial) / u

# Estimate tau from 63.2% rise time
y_63 = y_initial + 0.632 * (y_data[-1] - y_initial)
idx_63 = np.argmin(np.abs(y_data - y_63))
tau_guess = t_data[idx_63]

p0 = [K_guess, tau_guess]

Setting Parameter Bounds

Bounds prevent physically impossible solutions:

bounds = (
    [lower_K, lower_tau],    # Lower bounds
    [upper_K, upper_tau]     # Upper bounds
)

Calculating Fit Quality

R-squared (Coefficient of Determination)

# Predicted values from fitted model
y_predicted = step_response(t_data, K_estimated, tau_estimated)

# Calculate R-squared
ss_residuals = np.sum((y_data - y_predicted) ** 2)
ss_total = np.sum((y_data - np.mean(y_data)) ** 2)
r_squared = 1 - (ss_residuals / ss_total)

Root Mean Square Error (RMSE)

residuals = y_data - y_predicted
rmse = np.sqrt(np.mean(residuals ** 2))

Complete Example

import numpy as np
from scipy.optimize import curve_fit

def fit_first_order_model(data, y_initial, input_value):
    """
    Fit first-order model to step response data.

    Returns dict with K, tau, r_squared, fitting_error
    """
    t_data = np.array([d["time"] for d in data])
    y_data = np.array([d["output"] for d in data])

    def model(t, K, tau):
        return y_initial + K * input_value * (1 - np.exp(-t / tau))

    # Initial guesses
    K_guess = (y_data[-1] - y_initial) / input_value
    tau_guess = t_data[len(t_data)//3]  # Rough guess

    # Fit with bounds
    popt, _ = curve_fit(
        model, t_data, y_data,
        p0=[K_guess, tau_guess],
        bounds=([0, 0], [np.inf, np.inf])
    )

    K, tau = popt

    # Calculate quality metrics
    y_pred = model(t_data, K, tau)
    ss_res = np.sum((y_data - y_pred) ** 2)
    ss_tot = np.sum((y_data - np.mean(y_data)) ** 2)
    r_squared = 1 - (ss_res / ss_tot)
    fitting_error = np.sqrt(np.mean((y_data - y_pred) ** 2))

    return {
        "K": float(K),
        "tau": float(tau),
        "r_squared": float(r_squared),
        "fitting_error": float(fitting_error)
    }

Common Issues

  1. RuntimeError: Optimal parameters not found

    • Try better initial guesses
    • Check that data is valid (no NaN, reasonable range)
  2. Poor fit (low R^2):

    • Data might not be from step response phase
    • System might not be first-order
    • Too much noise in measurements
  3. Unrealistic parameters:

    • Add bounds to constrain solution
    • Check units are consistent
安全使用建议
This is a documentation-style, instruction-only skill for fitting data with scipy.curve_fit. It does not ask for credentials or install packages, but it assumes numpy/scipy are available in the environment. Before using: ensure your data arrays (t_data, y_data) are valid (no NaNs), confirm units and bounds make sense for your system, and provide reasonable initial guesses to avoid convergence issues. If you need the skill to run in an environment without numpy/scipy, install those packages from trusted sources first.
功能分析
Type: OpenClaw Skill Name: hvac-control-scipy-curve-fit Version: 0.1.0 The skill bundle provides standard documentation and Python code examples for using the SciPy library to perform nonlinear least squares curve fitting. There are no indicators of malicious intent, data exfiltration, or prompt injection; the content is entirely focused on mathematical modeling and parameter estimation in SKILL.md.
能力评估
Purpose & Capability
Name and description match the content: the SKILL.md explains how to use scipy.optimize.curve_fit to fit first-order step responses and compute fit quality. There are no unrelated requirements (no env vars, binaries, or external services).
Instruction Scope
Instructions stay within the stated purpose: they define model functions, compute initial guesses, run curve_fit, and compute metrics (R^2, RMSE). The file does not instruct reading unrelated system files, exporting data to external endpoints, or accessing secrets.
Install Mechanism
No install spec or downloaded code is included (instruction-only), so nothing is written to disk. The SKILL.md assumes numpy and scipy are available but does not attempt to install them; this is reasonable for a usage guide.
Credentials
The skill requests no environment variables, credentials, or config paths. No sensitive access is requested or needed for the documented functionality.
Persistence & Privilege
always is false and the skill does not request or describe modifying agent/system configuration or maintaining persistent credentials. It is a transient, instruction-only skill.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install hvac-control-scipy-curve-fit
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /hvac-control-scipy-curve-fit 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.1.0
Bulk publish from all-task-skills-dedup
元数据
Slug hvac-control-scipy-curve-fit
版本 0.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

scipy-curve-fit 是什么?

Use scipy.optimize.curve_fit for nonlinear least squares parameter estimation from experimental data. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 76 次。

如何安装 scipy-curve-fit?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install hvac-control-scipy-curve-fit」即可一键安装,无需额外配置。

scipy-curve-fit 是免费的吗?

是的,scipy-curve-fit 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

scipy-curve-fit 支持哪些平台?

scipy-curve-fit 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 scipy-curve-fit?

由 wu-uk(@wu-uk)开发并维护,当前版本 v0.1.0。

💬 留言讨论