tensorflow.js估计参数的标准误差



我使用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库吗?谢谢

对于任何感兴趣的人,在tensorflow.js对参数进行优化后,我最终自己估计指数函数的Hessian矩阵,以计算参数的标准误差。我遵循了以下代码: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];
};

最新更新