问题
(* superuser does not like this question, so i post it here *)
I have a set of scripts in Octave to undertake a machine-learning algorithm. I have also a website by mean-stack. My question is whether it is possible to integrate this Octave code into the site web, either front-end or back-end. Do I have to rewrite everything in JavaScript or nodeJS?
回答1:
You have several options. From a backend point of view:
- use standard cgi solutions. Octave has a cgi package you can use. This would be my best bet.
- more generally, use server-side 'system' calls to run particular scripts on your server, capture the output in files etc, and read those files back in your web-session
- try to communicate with an open octave session and execute commands via sockets (would require more substantial programming)
- try to find a third-party javascript-octave bridge / interface (not sure one exists - this appears on github but no idea if it works)
From a front-end point of view, you may have some luck finding online code execution services, I can't remember nor recommend actual names at the moment, but I've definitely seen such services advertised in the past.
回答2:
Given the lack of direct JS-Octave bridges on npm, and that you probably mainly use octave to do linear algebra operations (matrix operations, etc.) one option is to use the math.js library, which has all of those operations.
Yes, it'd mean you'd have to convert your Octave scripts to JavaScript, but if you understand what they're doing that won't be too hard. There's a great blog post by Robin Wieruch called Linear Algebra in JavaScript with Matrix Operations showing how to do just this.
Or else just go straight to Tensorflow, wich has Octave-like matrix (tensors) operations built-in as well.
If you're in the MEAN stack it seems to me it's more important to use a JS library, and not try to integrate external Octave files. Tensorflow works in Node and in the browser, so you have everything you need there.
来源:https://stackoverflow.com/questions/48243845/integrate-octave-code-to-a-mean-stack-website