I need to perform some basic OLS regression using F#. To do this I need some Linear Algebra functions, but I'm confused as to what's out there. I can't find any way to invert a matrix. There is some documentation for a library called Microsoft.FSharp.Math.LinearAlgebra, but I don't know if that exists anymore.
If you add the FSharp Powerpack to your project (in .NET references), you can use various functionality of the matrix library
edit: you also need to add the experimental library Fsharp.Powerpack.MathProviders, then you can call as follows
open Microsoft.FSharp.Math
let m = Matrix.create 10 10 1.2
let m2 = Experimental.LinearAlgebra.Inverse m
FlyingFrog do a Numerics library which contains Matrix inversion amongst many other functions.
Not sure which is preferable, that or the (apparently deprecated) 'experimental' code from the PowerPack. I guess you could always keep the source code for the managed bit of the PowerPack version in a safe place, still available here:
C:\Program Files\FSharp-1.9.6.2\source\fsharp\FSharp.PowerPack\math\lapack\linear_algebra_managed.fs.
I don't know; in the 1.9.6 version of F# I don't see anything offhand, the docs are here
http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/namespaces.html
and there is Matrix stuff in the Microsoft.FSharp.Math namespace in the FSharp.Powerpack.dll, but I don't see 'invert' offhand, and I don't know about the 'LinearAlgebra' stuff (deprecated? web search suggests it disappeared a few releases back).
Have you checked out this. It might help.
Related
Clang is good for keeping everyone honest regarding the company's coding standards, but it does not provide complete coverage of all cases and makes (IMO) bad choices instead of ignoring certain situations. For example (from another post with similar concerns):
z1 = sqrt(x*x + y*y);
gets "mangled" by clang-format into
z2 = sqrt(x * x + y * y);
Sure that follows the company standards, but the z1 expression is easier to recognize at a glance. I want clang-format to ignore (not add nor remove) spaces around binary operators. I don't see any setting for spaces around binary operators for that matter. It just does it whether I want it or not.
So, can I add the capability to handle a new parameter like
SpaceAroundBinaryOperator: true|false|ignore?
I.e., is the clang-format code accessible to an experienced C++ programmer without having to spend a week or more just figuring out the code? Any tips?
So, can I add the capability to handle a new parameter...
is the clang-format code accessible to an experienced C++ programmer without having to spend a week or more just figuring out the code?
There is this: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options, but there isn't much information there.
Also this: https://clang.llvm.org/docs/LibFormat.html
And maybe this: https://clang.llvm.org/docs/#design-documents
But I think you really would have to dive into the source code. There's a lot of code (since clang-format code is part of the whole clang C++ compiler and related tools LLVM project), so I think you'll want a week or more to figure things out. Just my guess though...
I'm trying to find the c++ file for Z3 where the algorithm backtraces if it can't find a solution on the current branch. I've been looking through all the files and tried debug mode on the python files, but no luck so far. I just want to add a print statement to the method, so I can tell when it is returning to a previous node and trying a new path.
Thanks!
It depends on which solver Z3 uses for your problem. It typically uses smt_context.cpp in src/smt. The relevant backjump can be traced in the context::pop_scope method. Other solvers exist too: the src/sat/sat_solver is used for bit-vector and Boolean problems. It has a similar pop method. Finally, nlsat is used for non-linear polynomial arithmetic over the reals.
I thought I read somewhere that Z3 has some option for returning the model with the "least" value eg given something like
x >= 2
Z3 would return 2. I could swear that I saw some reference to this recently, but I am unable to find it now. Can anyone confirm this?
No, Z3 does not produce 'least' models. However, a separate branch of Z3 that adds optimization features is being developed at the moment (the branch is called `opt'), and perhaps will later be integrated into Z3 proper. A tutorial for the current optimization features is available here: Z3Opt Guide
Reading sources of Array2D module, I've stumbled upon this interesting construct in implementation of many core functions, for example:
[<CompiledName("Get")>]
let get (array: 'T[,]) (n:int) (m:int) = (# "ldelem.multi 2 !0" type ('T) array n m : 'T #)
I can only assume that this is the syntax to inline CIL and is used here obviously to gain performance benefits. However, when I've tried to use this syntax in my program, I get an error:
warning FS0042: This construct is deprecated: it is only for use in the F# library
What exactly is this? Is there any detailed documentation?
I think that this has 2 purposes:
These functions compile down to exactly 1 CIL instruction which has to be encoded somewhere, so encoding at the source seems best.
It allows for some extra trickery with defining polymorphic Add functions in a high performance way which is hard with the F# type system.
You can actually use this but you have to specify the --compiling-fslib (undocumented) and --standalone flags in your code.
I've found some details in usenet archives: http://osdir.com/ml/lang.fsharp.general/2008-01/msg00009.html
Embedded IL in F# codes. Is this feature officially supported
Not really. The 99.9% purpose of this feature is for operations defined
in FSharp.Core.dll (called fslib.dll in 1.9.2.9 and before).
Historically it has been useful to allow end-users to embed IL in order
to access .NET IL functionality not accessible by F# library or
language constructs using their own embedded IL. The need for this is
becoming much more rare, indeed almost non-existent, now that the F#
library has matured a bit more. We expect this to continue to be the
case. It's even possible that we will make this a library-only feature
in the "product" version of F#, though we have not yet made a final
decision in this regard.
This was a message from Don Syme, dated January of 2008.
Is it possible for a person working with statistic to replace his specialized programs by F#? I'm thinking about SAS/SPSS mainly?
Any native support for it in F#?
I am not talking about the trivial things as standard deviation and the likes, but for example item-response modeling.
UPDATE : Dont't let the item-response modeling put you of! I don't even know it, just an example of things I know they do with SPSS to clarify it's about more advanced features.
Short : is there a way to use F# as your main statistical tool and replace SPSS all together?
Sadly, nothing comporable to combination of
R + PostgreSQL + Python/Java/Groovy/Scala/... + VisAD
Of course, there is nice http://www.codeplex.com/vslab instead of gnuplot
and some c# statistics code packaged in http://ta-lib.org/ http://www.alglib.net/
You can use R within F# with the type providers for R
see
http://blogs.msdn.com/b/dsyme/archive/2013/01/30/twelve-type-providers-in-pictures.aspx
and see
http://techblog.bluemountaincapital.com/2012/08/01/announcing-the-f-r-type-provider/
Here at BlueMountain we like to perform statistical analysis of data. The stats package R is great for doing that. We also like to use the data retrieval and processing capabilities of F#. F#’s interactive environment lends itself pretty well to data exploration, and we can also easily access our existing .NET-based libraries. Once we are done, we can build and release production-supportable applications.
Here is something maybe-useful:
http://fsmathtools.codeplex.com/
or
http://mathnetnumerics.codeplex.com/