Execute function server side using Lambda

#1

I am trying to execute a function server side to recreate some results:

var lambda = Lambda.fromJavaScript(function reg(x, y) {
	var regression;
	regression = Packages.c3.love.expr.MatrixUtils.ridgeRegression(
		_.map(x, function (v) { return v.valueOf(); }),
		y.valueOf(),
		0.0001
	);
	return regression;
});
lambda.apply([x, y])

But I get the error Uncaught ReferenceError: Packages is not defined. I understand that this is not defined from the console but isn’t it suppose to run on the server (where Packages is accessible) through Lambda?

0 Likes

#2

@adrienbos can you try that in a function and see if that works
egs

var f = function(){
  var lambda = Lambda.fromJavaScript(function reg(x, y) {
	var regression;
	regression = Packages.c3.love.expr.MatrixUtils.ridgeRegression(
		_.map(x, function (v) { return v.valueOf(); }),
		y.valueOf(),
		0.0001
	);
	return regression;
});
return lambda.apply([x, y])
}
JS.exec(f);
0 Likes

#3

@garrynigel thanks!
It doesn’t work as it is. I am not sure how to pass the argument x and y in this case. If I run it I get ReferenceError: "x" is not defined. And if I look at the JS type I don’t see a way to pass arguments in the exec function.

0 Likes

#4

@adrienbos you can do this

lambda = lambda.partiallyApply({x: 0, y : 1})
JS.exec(lambda);
0 Likes