BayesianLogic / blog

The BLOG programming language
http://bayesianlogic.github.io/
BSD 4-Clause "Original" or "Old" License
98 stars 31 forks source link

Use as a library #342

Open miromannino opened 8 years ago

miromannino commented 8 years ago

Let's say I have a server, written in Java, and I need to execute the same model with some specific observations.

I would like to use BLOG as a library instead of using it as an external command line application. How can I do that? I have seen something that could be used in the test folder, for example using simpleSetupFromFiles; but I cannot find any official/compact solution.

Thank you

jxwuyi commented 8 years ago

@miromannino Hi, you can always execute BLOG by (1) running command line inside a process (2) calling the Java class within Java or Scala. The simpleSetupFromFiles option does essentially the same thing as the command line: it takes in the model/query/obs written in a text file and builds a BLOG data structure on it to perform inference. You can always write a model in a fixed text file and generate different query files and obs files. I guess the subtle thing is data/query input and output. BLOG can output to jason format. So what kind of input/output would you like? I mean the most naive solution will be sth like: you write a script which takes in the data (in some format) and produces a query/obs file and then call the BLOG class. Anyway, I think you may want nicer solution. We are working on data input/output stuff recently. So we do appreciate your feedback. Can you provide mode details on your use case?

miromannino commented 8 years ago

Yes, the problem is that I would like to avoid launching a process to execute it. I would like to load the model, and then execute that each time with many different observations (load a Java process each time seems time consuming).

The Json option, seems only an option to let it to write into a file. I would avoid to do that, at least, if I need to open another process to launch BLOG, I should get the data redirecting the stdout of that process.

So how can I call it following the second strategy you were talking about?

Thank you

jxwuyi commented 8 years ago

Unfortunately, now the BLOG system does not support streaming/incremental data processing. You need to store the model in a file, data in a file, obs in a file; then load the java class; process all the fies to process a internal data structure; and perform inference as a whole over all the files. Only compiling the model and support incremental/streaming/new data will be a good direction for us. We will start to investigate this option in the near future.

Well, for the output, the output from screen will be the statistics of all the produced samples. If you need all the produced samples, there is currently now way to load that. The samples are stored in a internal histogram data structure. The jason file will contain all the produced samples.

So can you tell me what form you would like the output data in? I can probably add a new output option for you.