【问题标题】:Standard error of estimated parameters with tensorflow.jstensorflow.js 估计参数的标准误差
【发布时间】:2021-02-28 02:32:45
【问题描述】:

我正在使用 tensorflow.js 来获取指数回归的参数:

y(x) = c0*e^(kx)

我附上代码:

x = tf.tensor1d(x);
y = tf.tensor1d(y);
const c0 = tf.scalar().variable();
const k = tf.scalar(this.regression_parameters.array[index][0]).variable();
// y = c0*e^(k*x)
const fun = (x) => x.mul(k).exp().mul(c0);
const cost = (pred, label) => pred.sub(label).square().mean();
const learning_rate = 0.1;
const optimizer = tf.train.adagrad(learning_rate);
// Train the model.
for (let i = 0; i < 500; i++) {
optimizer.minimize(() => cost(fun(x), y));
}

非常适合实验信号。但是,我需要报告估计值(c0 和 k)的标准误差,因为它在 SciPy 中由 curve_fit() 给出。我想知道这是否可以用 tensorflow.js 完成。如果没有,是否还有其他可用的 JavaScript 库?谢谢!

【问题讨论】:

  • 我认为事实上,您无法预测标准误差。预测变量的误差假设预测是与置信区间一起进行的。这里没有区间预测。
  • 我明白了。我知道 SciPy curve_fit() 通过从协方差矩阵中估计它们来获得标准误差。我希望能够在不使用 Python 服务器的情况下进行非线性拟合,但我找不到任何具有类似方法的 JavaScript 库。如果有人知道任何可用的图书馆,将不胜感激。

标签: javascript tensorflow tensorflow.js exponential


【解决方案1】:

对于任何感兴趣的人,我最终会自己估计指数函数的 Hessian 矩阵,以在 tensorflow.js 优化参数后计算参数的标准误差。我按照以下代码: https://www.cpp.edu/~pbsiegel/javascript/curvefitchi.html

如下:

function hess_exp_errors(c0, k, x, y){
 var sum1=0,sum2=0,sum3=0,sum4=0,sum5=0, expon1,
 he11, he12, he22, dett, dof, k_err, c0_error;
 for (i=0;i<x.length;i++){
  expon1=Math.exp(k*x[i]);
  sum1+=expon1*expon1;
  sum2+=y[i]*x[i]*x[i]*expon1;
  sum3+=x[i]*x[i]*expon1*expon1;
  sum4+=y[i]*x[i]*expon1;
  sum5+=x[i]*expon1*expon1;
 }
 he11=4*c0*c0*sum3-2*c0*sum2; he22=2*sum1;
 he12=4*c0*sum5-2*sum4; dett=he11*he22-he12*he12;
 c0_err=Math.sqrt(he11/dett); k_err=Math.sqrt(he22/dett);
 return [c0_err, k_err];
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-22
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    相关资源
    最近更新 更多