You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用alglib::lsfitcreatef()出现参数匹配错误的技术求助

使用ALGLIB的lsfitcreatef进行非线性最小二乘拟合时出现参数不匹配错误

我在C++中使用alglib::lsfitcreatef()进行非线性最小二乘拟合,复制了官方示例代码,区别在于使用程序生成的vector数据。按照论坛示例将数据转换为alglib::real_2d_array后,Visual Studio提示没有匹配该参数列表的重载函数。

以下是我的代码(包含将输入转换为real_1d_array的逻辑):

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include "interpolation.h"
#include <integration.h>
#include <alglib-cpp/src/ap.h>

double epsx = 0.000001;
alglib_impl::ae_int_t maxits = 0;
alglib_impl::lsfitstate  state;
alglib_impl::lsfitreport  rep;
const double diffstep = 0.0001;

//convert to proper parameters
const alglib::real_2d_array  x_data = convert_to_alglib_2d_array(x);
const alglib::real_1d_array  y_data = convert_to_alglib_1d_array(y_sub_array);
alglib::real_1d_array  parameter_data = convert_to_alglib_1d_array(p0);

//
// Fitting without weights
//
alglib::lsfitcreatef(x_data, y_data, parameter_data, diffstep, state); //error here
lsfitsetcond(state, epsx, maxits); //this defines the stopping criteria
alglib::lsfitfit(state, lorentzian); //actual fit function
lsfitresults(state, parameter_data, rep); //middle parameter is the output parameter
    
alglib::real_2d_array SpectrumData::convert_to_alglib_2d_array(std::vector<int> input)
{
    alglib::real_2d_array xy;
    xy.setlength(input.size(), 1); //# rows first, # columns second, just for this method

    for (int i = 0; i < input.size(); i++)
    {
        //xy(columns, rows)
        xy(0, i) = input[i];
    }

    return xy;
}

alglib::real_1d_array SpectrumData::convert_to_alglib_1d_array(std::vector<long> input)
{
    std::vector<double> contents(input.begin(), input.end());
    alglib::real_1d_array y;
    y.setlength(contents.size());

    for (int i = 0; i < y.length(); i++)
    {
        y[i] = contents[i];
    }

    return y;
}

实际错误信息:“no instance of overloaded function alglib::lsfitcreatef matches the argument list.”

我的环境配置及已尝试的操作:

  • 下载了官方源码,在项目中添加附加包含目录:C:\3d-party-software\alglib-cpp\src,该目录包含官方下载的所有.h和.cpp文件
  • 多次查阅论坛及官方示例代码,写法与示例一致
  • 谷歌搜索相关问题未找到有效答案
  • 使用自动补全确认调用的是期望的函数重载版本
  • 查看了interpolation.h中的函数声明:void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const double diffstep, lsfitstate &state, const xparams _xparams = alglib::xdefault);

内容的提问来源于stack exchange,提问作者Unstable Andy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 17:42:50