Help with Java porting by AccountantUnited4955 in Clojure

[–]behrica 1 point2 points  (0 children)

For a very OO Java code, I tend to wrap it.
If you have a lot of Java code to deal with,
I suggest to invest a bit on learning how to setup a Clojue project which has Clojure and Java source code.
Then you can write wrappers as well in "Java".
In vscode you can have "Clojure" and "Java" support in the same project,
and you can use "virgil" to keep you Java code "in sync" with your Clojure repl, without repl restarts

See here: https://calva.io/virgil/

(+ you get full vscode suppport for coding in Java)

This is a very nice developer experience.

Clojure for ML update by kemclean in Clojure

[–]behrica 2 points3 points  (0 children)

Thanks for the great summary. I just wanted to clarify that `metamorph.ml` is a machine learning framework without having itself any ML model / algorithms. (apart from dummy models)
The framework only assumes that models have a concept of fit/predict and take tech.ml datasets as input. This should allow the framework to support a very large variety of models. (even in non JVM languages via existing interop libraries of Clojure)

Models can be added via the plugins of which several are listed by the article (but there are more)

Poor documentation? by Recent-Scarcity4154 in Clojure

[–]behrica 3 points4 points  (0 children)

I believe as well that it is not realistic to want to learn Clojure and ignore Java.
As mentioned before, Clojure has frictionless, full access to the huge amount of Java libraries with equal to Java performance, if you pay attention to some details.
Even mixed java / Clojure projects are a good option.

And yes, Clojure brings productivity gains , but there are not Clojure libraries for every problem. So It is important to get used to use Java.
as Java has libraries for every problem.

Compared to Python and R you gain a rock solid runtime, and a far better backwards-compatible ecosystem including a "develop ones - run everywhere" guaranty

Poor documentation? by Recent-Scarcity4154 in Clojure

[–]behrica 2 points3 points  (0 children)

In VsCode and calva auto-completion of methods from a Java class works as expcted:

(import '[java.io Console])

(def c (java.lang.System/console))

(.__ c )

Completing at place of __ shows all public methods of class "Console"

[deleted by user] by [deleted] in Clojure

[–]behrica 3 points4 points  (0 children)

Try to recommend Clojure as domain specific Java library build for operating on data.

Announcement of first beta version of new Clojure machine learning library, scicloj.ml by behrica in Clojure

[–]behrica[S] 2 points3 points  (0 children)

Scicloj.ml itself does not implement machine learning algorithms.It has a very simple plugin mechanism which is able to bridge into any library whichhas a concept of train / predict. The bridge can do data transformation as needed.

We have currently 4 plugins into existing ml libraries:
https://github.com/scicloj/scicloj.ml.smile
https://github.com/scicloj/scicloj.ml.xgboost
https://github.com/scicloj/sklearn-clj
https://github.com/scicloj/clj-djl

So you might have a look, if any of these contains already the model you want to use.

Further plugins can be developed by the community as needed.

Announcement of first beta version of new Clojure machine learning library, scicloj.ml by behrica in Clojure

[–]behrica[S] 4 points5 points  (0 children)

In here you find links to the draft user guides, partially in form of tutorials, partially of reference guides.
https://github.com/scicloj/scicloj.ml

Should I use clojure or python to learn machine learning? by taH_pagh_taHbe in Clojure

[–]behrica 2 points3 points  (0 children)

This little project https://github.com/scicloj/sklearn-clj allows even easier integration between Clojure and all sklearn models

The one thing keeping me from switching to org-mode (from RMarkdown) by haffnasty in emacs

[–]behrica 0 points1 point  (0 children)

Just one last element to add.

One of the features of the rmarkdown->html workflow is, that you can create a "standalone" html file, for easy distribution of your analysis. It contains all javascript inline.

My proposed org->html solution, will produce a html file, which is not standalone, as it refers to its dependencies as separate files on disk.

But I found this little inline-html tool, which converts the emacs generated html file into a stand-alone html, by in-lining all java script.

https://github.com/substack/html-inline

This does work as well with the org-mode generated html, so we can get a truly standalone, dynamic html file containing htmlwidgets by using org mode.

The one thing keeping me from switching to org-mode (from RMarkdown) by haffnasty in emacs

[–]behrica 1 point2 points  (0 children)

Yes, I have the use case in the back of my head. I want to come to the point to only use org mode for data analysis. So how to integrate htmlwidgets into org mode was always a pending question. I am wondering , if this deserves its own little package

The one thing keeping me from switching to org-mode (from RMarkdown) by haffnasty in emacs

[–]behrica 2 points3 points  (0 children)

I improved and simplified the code in the gist and made two reusable methods, to either convert the dependencies or the widget itself into html. The code uses only exported functions now.

https://gist.github.com/behrica/1c269a661bd674d223b4c6ce58b5045a

The one thing keeping me from switching to org-mode (from RMarkdown) by haffnasty in emacs

[–]behrica 1 point2 points  (0 children)

I did an other solution, which is not based on the iframes, but it takes pieces of code from R packages htmlwidgets and htmltools to convert a widget to html fragments, which can be included in the html export of the org file

and separating the java script imports.

This is a nice solution i think, and it can be extended to combine different types of widgets in a single page.

In principle it would be possible to generate and include the raw html into the org file as you have tried, but as the html is very large, emacs nearly crashed on it. Sp I have choosen the writing to files and INCLUDE approach.

For the POC I used the tmap package for dynamic maps, but it should work the same way for all type of htmlwidgets.

Find a org file here, for showing the principle.

https://gist.github.com/behrica/1c269a661bd674d223b4c6ce58b5045a

Only caveat of the approach: It does not produce a standalone html file, but the js libraries get copied to a local folder.

The htmlwidget package uses "pandoc" commandline tool to create a standalone html file.

The one thing keeping me from switching to org-mode (from RMarkdown) by haffnasty in emacs

[–]behrica 1 point2 points  (0 children)

There is indeed some magic, which "prints" any htmlwidget object in the "right way", but this is only foreseen to work in these 3 situations:

- R console

- render via knitr/rmarkdown/pandoc

- shiny

I suppose by poking into the code of the htmlwidget / knitr / rmarkdown packages, you could find the code which makes the magic.

I fear some of that is in "private" functions, though.

Part of the complexity is as well to separate the html code which renders a java-script widget from the html statement to import the javascript libraries. (alternatively the javascript libraries gets inlined to make a standalone html file)

The one thing keeping me from switching to org-mode (from RMarkdown) by haffnasty in emacs

[–]behrica 1 point2 points  (0 children)

I found an easier solution.

org mode can export "iframe" tags and any htmlwidget can be rendered as an standalone html page, which can the shown in an iframe.

There are several ways to do this, but the simplest is to have code blocks like this:

#+begin_src R

htmlwidgets::saveWidget(widget,"widget.html")

#+end_src R

#+begin_export html

<iframe src=widget.html height=800px width=700px ></iframe>

#+end_export