I am thinking about compiling CmdStan (say the Bernoulli example) to https://webassembly.org/ .
This would be easiest to generate a “large” C++ files, that containes “everything”, which can be passed to the https://webassembly.org/ compiler. The problem is … I don’t know how to do that.
A huuuuuge chunk of C++ code, one laaarge C++ file, which, when compiled with a cc compiler,
gcc, clang, etc… will produce, say, the bernoulli example. Then that one C++ file could be piped into
the https://webassembly.org/ compiler which produces js code (or something similar) which can be
run on https://webassembly.org/ supported browsers.
Then, Stan models can be run in pretty much any https://webassembly.org/ supported browser.
That would be pretty cool ! (In case it has not been done already :) ).
If that could work then I could throw in StanScala into the mix and use Scala.js to make some
fun demo of Stan, that could be run in the browser only (or on a mobile phone, for that matter).
For educational purposes / cool interactive demos, etc.
I am writing a “toy” web framework, full Scala stack. If Stan could be added to it then
there would be a “demo” on how to make some SPA (in Scala/Scala.js/ScalaStan,
fully type safe => awesome, easy, cool ) where someone can do some real time MCMC fitting
of some model on their mobile phone, to any model they can make in ScalaStan).
This would make it possible to use Stan in Cordova applications
(if https://webassembly.org/ is compatible with Cordova, or some other
SPA into phone-app converter framework), i.e. to make some mobile phone apps
where Stan is part of the app, just take the generated .js and put it into Cordova
and then publish it as an iPhone app, or Android app, or whatever platform Cordova supports.
Then you can use Stan to build some fun applications, educational, or say, using the
magnetometer/accelerometer, etc … built into the phone, calculate some sort of sensor
fusion “something” (I have seen a demo on such thing a few months ago, a researcher at
Aalto was using MCMC + Maxwell equations to do some sort of online learning of magnetic
field / navigation inside some building/office). I think he was using some custom made MCMC
algorithm. Custom code, etc.
With this https://webassembly.org/ + Cordova approach, one could use Stan to process sensor
data without writing custom code for Android/iOS etc … just use Scala for everything. Full
stack Scala Android/iOS apps that process sensor data gathered by mobile phones (including
camera, gps, accelerometer, magnetometer, you name it).
Might be useful for the community, and it might be just fun for it’s own sake. A good learning tool.
Bottom line, if someone knows how to make ONE LARGE C++ file, say, for the bernoulli example,
from the CmdStan codebase, then please let me know, right now it seems to be making a C++
code that uses precompiled dynamic Stan librararies, if I understand the makefile correctly.
But I am not sure. I might be playing around with this idea a bit, but if somebody happens
to know how to make that “one large monolithic” “God” C++ file, that when passed to the https://webassembly.org/ compiler will make the “binary” for a browser, then please let me know.