[英]In an Observable notebook, unable to use a function from an npm library, perhaps because unable to import a function from the library's dependency
I want to reproduce the example in this npm library in an Observable notebook.我想在 Observable 笔记本中重现此 npm 库中的示例。 I run the following in a cell and a block:
我在一个单元格和一个块中运行以下命令:
fit_data = {
let data = {
x: [0, 1, 2],
y: [1, 1, 1]
}
return data
}
{
const LM = require('ml-levenberg-marquardt@2.1.1/lib/index.js').catch(() => window["_interopDefault"]);
function sinFunction([a, b]) {
return (t) => a * Math.sin(b * t);
}
const options = {
damping: 1.5,
gradientDifference: 10e-2,
maxIterations: 100,
errorTolerance: 10e-3
};
let fittedParams = levenbergMarquardt(fit_data, sinFunction, options);
return fittedParams
}
and I get the error message TypeError: isArray is not a function
, which I suspect is this function failing to be imported from the library's dependency.我收到错误消息
TypeError: isArray is not a function
,我怀疑这是 function未能从库的依赖项中导入。
I am importing the library by following this guide .我正在按照 本指南导入库。
Everything looks fine, I guess you misspelled the import method name.一切看起来都很好,我猜你拼错了导入方法的名称。 Another suggestion is to break into cells.
另一个建议是闯入细胞。 Here are the cells that worked for me
这是对我有用的细胞
Here is how you import it这是你如何导入它
LM = await require('ml-levenberg-marquardt@2.1.1/lib/index.js').catch(
() => window["_interopDefault"]
)
Here is how you use it这是你如何使用它
{
const options = {
damping: 1.5,
gradientDifference: 10e-2,
maxIterations: 100,
errorTolerance: 10e-3
};
let fittedParams = LM(fit_data, sinFunction, options);
return fittedParams;
}
fit_data = {
let data = {
x: [0, 1, 2],
y: [1, 1, 1]
};
return data;
}
function sinFunction([a, b]) {
return t => a * Math.sin(b * t);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.