* Functional unparsing @ 2009-04-15 20:41 Andrey Riabushenko 2009-04-15 21:21 ` [Caml-list] " Daniel Bünzli ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Andrey Riabushenko @ 2009-04-15 20:41 UTC (permalink / raw) To: caml-list Hi ocaml developers, I am currently developing a library for multivariate regressions including linear, nonlinear, generalized, weighted and so on. In my opinion most the convenient interface is the one described further and is based on functional unparsing. Something like that: Stats.linear_regression "y ~ x1 exp(x2) log(x3) x3^2" Returns float -> float -> float -> float -> regression_result = <fun> Stats.generalized_regression "log(y) ~ x1 x^2 log(x3) " Returns float -> float -> float -> float -> regression_result = <fun> For time series: Stats.ts_regression "y ~ ARMA(5,3)" Stats.ts_regression "y ~ ARMA(2,2) GARCH(2,1)" If want to ask you two questions. 1. Do you find such interface convenient? Critique is welcome. If you have better idea, please tell me. I will make all publicly available. 2. The second question regarding function unparsing. I haven't used this technique before. Are there some docs, blog articles, descriptions and etc? The only relevant documentation I have found is printf.ml :). Might someone have a minimal working example to demonstrate? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Functional unparsing 2009-04-15 20:41 Functional unparsing Andrey Riabushenko @ 2009-04-15 21:21 ` Daniel Bünzli 2009-04-15 21:40 ` Hezekiah M. Carty 2009-04-16 9:25 ` Cedric Auger 2 siblings, 0 replies; 5+ messages in thread From: Daniel Bünzli @ 2009-04-15 21:21 UTC (permalink / raw) To: Andrey Riabushenko; +Cc: caml-list Le 15 avr. 09 à 22:41, Andrey Riabushenko a écrit : > Something like that: > > Stats.linear_regression "y ~ x1 exp(x2) log(x3) x3^2" > Returns float -> float -> float -> float -> regression_result = <fun> It won't work with control strings as plain strings -- what would the type of Stats.linear_regression be ? Functional unparsing solves the problem by using values of a particular type and combinators to represent the control string (you can actually see it as directly manipulating the abstract syntax tree of the corresponding control string). Have a look at Olivier Danvy's paper [1]. You may also be interested in language embedding in general, see this message [2] for a reference and an example. Best, Daniel [1] http://www.brics.dk/RS/98/12/BRICS-RS-98-12.pdf [2] http://caml.inria.fr/pub/ml-archives/caml-list/2008/03/8bc5f07678134c77037c1a2feedd4d90.en.html ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Functional unparsing 2009-04-15 20:41 Functional unparsing Andrey Riabushenko 2009-04-15 21:21 ` [Caml-list] " Daniel Bünzli @ 2009-04-15 21:40 ` Hezekiah M. Carty 2009-04-17 8:36 ` Andrey Riabushenko 2009-04-16 9:25 ` Cedric Auger 2 siblings, 1 reply; 5+ messages in thread From: Hezekiah M. Carty @ 2009-04-15 21:40 UTC (permalink / raw) To: Andrey Riabushenko; +Cc: caml-list On Wed, Apr 15, 2009 at 4:41 PM, Andrey Riabushenko <cdome@bk.ru> wrote: > Something like that: > > Stats.linear_regression "y ~ x1 exp(x2) log(x3) x3^2" > Returns float -> float -> float -> float -> regression_result = <fun> ... > 2. The second question regarding function unparsing. I haven't used this > technique before. Are there some docs, blog articles, descriptions and etc? > The only relevant documentation I have found is printf.ml :). Might someone > have a minimal working example to demonstrate? The Batteries Print module and associated syntax extension may be a useful base for implementing something similar to what you are proposing: http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=batteries/batteries.git;a=blob_plain;f=src/core/extlib/print.ml;hb=HEAD and http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=batteries/batteries.git;a=tree;f=src/syntax/pa_strings;hb=HEAD This allows for syntax like: Print.printf p"This is a list of integers: %{int list}" to return: int list -> unit = <fun> Hez -- Hezekiah M. Carty Graduate Research Assistant University of Maryland Department of Atmospheric and Oceanic Science ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Functional unparsing 2009-04-15 21:40 ` Hezekiah M. Carty @ 2009-04-17 8:36 ` Andrey Riabushenko 0 siblings, 0 replies; 5+ messages in thread From: Andrey Riabushenko @ 2009-04-17 8:36 UTC (permalink / raw) To: caml-list > The Batteries Print module and associated syntax extension may be a > useful base for implementing something similar to what you are > proposing: > > http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=batteries/batteries.git;a=blo >b_plain;f=src/core/extlib/print.ml;hb=HEAD and > http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=batteries/batteries.git;a=tre >e;f=src/syntax/pa_strings;hb=HEAD > > This allows for syntax like: > Print.printf p"This is a list of integers: %{int list}" > to return: > int list -> unit = <fun> > Thank you, this one was much more helpful then standard printf.ml. This one is much shorter and easier to understand. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Functional unparsing 2009-04-15 20:41 Functional unparsing Andrey Riabushenko 2009-04-15 21:21 ` [Caml-list] " Daniel Bünzli 2009-04-15 21:40 ` Hezekiah M. Carty @ 2009-04-16 9:25 ` Cedric Auger 2 siblings, 0 replies; 5+ messages in thread From: Cedric Auger @ 2009-04-16 9:25 UTC (permalink / raw) To: Andrey Riabushenko; +Cc: caml-list Andrey Riabushenko a écrit : > Hi ocaml developers, > > I am currently developing a library for multivariate regressions including > linear, nonlinear, generalized, weighted and so on. In my opinion most the > convenient interface is the one described further and is based on functional > unparsing. > > Something like that: > > Stats.linear_regression "y ~ x1 exp(x2) log(x3) x3^2" > Returns float -> float -> float -> float -> regression_result = <fun> > > Stats.generalized_regression "log(y) ~ x1 x^2 log(x3) " > Returns float -> float -> float -> float -> regression_result = <fun> > > For time series: > Stats.ts_regression "y ~ ARMA(5,3)" > Stats.ts_regression "y ~ ARMA(2,2) GARCH(2,1)" > > > If want to ask you two questions. > 1. Do you find such interface convenient? Critique is welcome. If you have > better idea, please tell me. I will make all publicly available. > I don't know what is really itended, but I think implementing something like " let double x = 2 *. x in Stats.linear_regression "y ~ double x1"" will be painfull, since you need to parse the string according to the environnement. The solution " let double x = 2 *. x in Stats.linear_regression "y ~ %1 x1" double" closer to printf and format %1 meaning "float -> float" is easier to implement, but less readable. If you don't require custom function, what you think should do the trick and seems to be manageable, but maybe that will be awfull to repeat many times the same function in case of use in different places. > 2. The second question regarding function unparsing. I haven't used this > technique before. Are there some docs, blog articles, descriptions and etc? > The only relevant documentation I have found is printf.ml :). Might someone > have a minimal working example to demonstrate? > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > You can also take a look in format.ml, but it will be more complicate. I don't know if it is a good idea, but if your expressions are complicate, try to use ocamllex and ocamlyacc. Another thing, printf is simplistic in the syntax of the string, that is you only have text and no complicate expression to type (we can printf "x log () / 0"), but complicate in managing formatters you don't need (printf "it is %s o clock" time) with your examples (you have no parameter); from this point of view, ocamllex and ocamlyacc may be more relevant (and are well documented). -- Cédric AUGER Univ Paris-Sud, Laboratoire LRI, UMR 8623, F-91405, Orsay ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-04-17 8:35 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-04-15 20:41 Functional unparsing Andrey Riabushenko 2009-04-15 21:21 ` [Caml-list] " Daniel Bünzli 2009-04-15 21:40 ` Hezekiah M. Carty 2009-04-17 8:36 ` Andrey Riabushenko 2009-04-16 9:25 ` Cedric Auger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox