I made many models with scikit learn, and i want to make predictions with these models from a C# program, is there any API which will help me to do that ?.
It is not possible to load sklearn models in C# directly (for my knowledge).
There is a language for the language-/tool-independent exchange of ML models called PMML. sklearn doesn't bring native support for PMML however. If you're lucky, your model/pipeline might be exportable to PMML using third party tools and loadable in C# using third party libraries.
The more reliable and way more flexible way is to do the prediction in Python using sklearn and communicate with your C# program via files or (better) a web service. Olivier Grisel (one of the sklearn authors) concisely describes your options in this post.
Related
I am looking out for developing a C# application which posts message to a ebMS3 platform using AS4. I am new to this area. Could anyone please help? Is there any third party libraries to do this easily? If not, how we post messages using AS4 from a c# solution.
I have just implemented our own AS4 solution, and it is hard task to accomplish. Especially because .NET does not support SOAP with attachments out of the box. And there is a lot background knowledge you need to know about - all the different specifications AS4 is based on. I have not been able to find an AS4 API written in .NET without it being a standalone solution as well...
First thing is to understand AS4, and a good place to start is this blog:
https://www.codit.eu/blog/2016/02/03/as4-for-dummies-part-ii-messaging-overview/
And then you will have to understand most of the EBMS3 specification:
http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/core/ebms_core-3.0-spec.html
That being said - it is not impossible.
I have been looking at the AS4.NET framework as Sander talks about, and it is well-written and a very good starting point for exchanging AS4 messages. I have used it as a test-endpoint.
So unless you need to incorporate AS4 directly into an existing product (which we needed to), I can only recommend using AS4.NET.
AS4.NET is also open source (and e-SENS profile conformant), so you can have a look at their code-base and let you inspire by the hard parts in AS4.
For the MIME parts I can recommend Mimekit: https://github.com/jstedfast/MimeKit
And for some of the encryption/signing stuff Bouncycastle is great: http://www.bouncycastle.org/csharp/
Not sure whether it can be used as a library, but for a project within the European Commission an open source .NET based AS4 implementation was developed. You can find it here in the EC's code repository. I don't know if there is any support on this, so if that is important you should probably consider another implementation. A list of solutions tested by the EC for conformance with their own profile of AS4 is available here (or if that link doesn't work by searching for "as4 conformance tested implementations")
Note that most are standalone applications which you connect to for executing the AS4 message exchange. Most offer different integration options, so you should be able to integrate it into your solution.
As title states I'm trying to use my Keras (tf backend) pretrained model for predicitions in c#. What's the best approach?
I've tried IronPython but it gave me errors, after search I found it isn't supported. Simply calling python script won't work since target Windows devices won't have python interpreters installed.
This question is somewhat vague, but I'll try to answer it the best I can:
Tensorflow core is written in c++ and exposes an interface, which can be consumed by a client written in whichever language (although yes, the Python one is the most developed so far).
What could you do:
You could use a python script to train the keras model and save its computation graph in a file. Then use TensorFlowSharp --- which is the project that contracts with the tensorflow API using c# -- to reload the computation graph and generate predictions with the trained network.
If your devices are phones, tablets and such, Tensorflow for mobile could help you too. It would work similarly to the option above. I'm not sure if they offer support to windows phones, though.
You mentioned:
[...] devices won't have python interpreters installed.
Well, okay. You could, however, define an boot process that would cascade the installation of the necessary dependencies (cpython included). Some applications do that to set databases, for example. In this case, you could create a microservice that boots tensorflow and answers to prediction requests through a file, pipe or socket. Your c# application would then connect to your microservice and request predictions.
Try Keras.NET. That uses C# numpy and calls the installed Keras and backend.
https://github.com/SciSharp/Keras.NET
I have used it succesfully to train and predict with Keras directly from C#. Not ideal but it works.
it does not work like that, since you wont even be able to install tensorflow in a C# project. Abandon C# stack and learn framework in python stack instead, ex. if if you need to consume the prediction result in a web app, learn Flask or Django
I need to make a desktop app which is pretty complex and handles a particular
domain. The domain has entities at the back end. I want the UI of this desktop app to be portable
to different frameworks such as Java(Eclipse RCP Plugin) and .NET(Visual Studio Plugin). So
1.)can I write the domain layer using C++ and interface with Java using JNI for Java
2.)use same C++ layer as point 1.) for interfacing with .NET (C++/CLI) as plugin for VStudio
What are the architectural considerations, pitfalls, future issues one will face if one
relies on a portable C++ layer interfaced with higher level APIs like Java and C# for a rich
client desktop application
For example one of the issue I will face is that I cannot debug and step into Native code from Java.
Are there many such items?
Should I just rewrite my domain layer using .NET and Java for each type of environment rather than keeping it portable as C++ layer?
Why isn't such an approach adopted by the industry?
What are the practical issues one faces when one has a JNI layer in between the View and Domain Layer?
Interfacing with domain models in another language / on another platform is really painful and my main architectural advice would be to avoid going there.
If you want a portable desktop app, I think you are better off writing it end-to-end in Java (or perhaps another JVM language like Scala or Clojure if you are one of the people who thinks that Java itself is a bit old-fashioned).
Rationale:
You'll only need to write the GUI layer once as Java will give you access to all the environments you need. You can run Java desktop apps pretty much everywhere that has a JVM, without recompiling. You just need to take a little care to avoid hard-coding platform specific features (e.g obvious stuff like don't assume "\" as a file separator, you need to use the portable File/pathSeparator instead).
This avoids the complexities of having to do a lot of cross-language interfacing. This is inherently a hard problem, since the languages have different object format and method calling semantics.
Java has a great open source library ecosystem with respect to portable code.
You can make pretty decent portable UIs in Java for most purposes (using Swing or SWT), and this is probably better in the long run than developing a custom UI layer for each target platform.
If you are smart, you can architect the app so that the GUI interacts with the back end domain objects through a clean and simple API. If you do this, then it will be easier to add new GUI options in the future (for example a web-based front end).
Writing the app end-to-end in .Net is also clearly feasible and might even be a bit easier on the GUI side given how good Microsoft's GUI-building tools are, but has the big disadvantage that you're now effectively locked into Windows, so your portability and platform flexibility goes out of the window. In addition (though this will depend on your domain) I think the Java ecosystem has the overall edge in terms of library ecosystem and tool support (with things like Maven).
When you want a cross language data model, a common pattern is to use a DSL to describe the domain model and generate the code from that. e.g. proto buffers. That way you can have native C++, Java, C# etc code for a common domain model.
One of the pitfalls of using a C++ library from Java is it doesn't feel like a Java library. You have to do all sorts of unnatural things to use it and you end up adding a layer to make it more Java friendly. I imagine its the same for C#
For example one of the issue I will face is that I cannot debug and step into Native code from Java. Are there many such items?
Netbeans supports Java + Native code debugging and you can step into native code from Java and debug both.
Should I just rewrite my domain layer using .NET and Java for each type of environment rather than keeping it portable as C++ layer?
I would have said yes, but that is me. For you it could make sense to leave in C++. There are pluses and minuses both ways.
Why isn't such an approach adopted by the industry?
Developing in Java and C# (and other virtual machine languages) is often seen as more productive and easier to find people who can support it.
What are the practical issues one faces when one has a JNI layer in between the View and Domain Layer?
You have to mirror the domain model, as you cannot just import it. i.e. all the data model you expose needs to be translated. This requires creating Java versions of the exposed model and well as translation code. (Another good reason to have all of it generated)
I am starting work on a new project where the core product is a Software Library. There is existing code we will be wrapping, written in C++ because it is very numerically intensive; we own and compile this core code.
I believe we will have two prominent client types:
1. App written in C++, probably MFC
2. App written in C#.NET.
The Question: In order to offer an "ideal" interface to both these client types, what technology do we use? For example, we could offer two interfaces, one using C/C++ functions and callbacks for the C++ clients, and the other using C#.NET for the C# clients? Also, in principle, could this be done nicely in one DLL, or will we want two (or more)?
Other info... Client apps are embedded, not a desktop or laptop; assume any UI is not Windows-based. Also we will have to compile and test for both 32-bit and 64-bit, probably C++ on 32-bit and C# on 64-bit.
My apologies here -- I realize this question may have been asked and answered previously, but if so, I was not able to find it.
Interesting question, I'm looking forward to other answers.
One possible solution, if probably not the best: If your library code follows object-oriented practices, you could write the core functionality in C++ and then provide separate COM wrapper classes around the core classes (also in C++). This would allow you to use your library components from .NET via COM interop. I don't know how efficient that would be — I suspect performance should generally be fine —, and COM has some obvious drawbacks (no generics, for example), so that may not be the optimal solution.
If your library is not object-oriented, you can still call single functions exported from any DLL in .NET using P/Invoke... if you go down this route, it's likely that you'll end up with a C# wrapper around your C++ DLL.
I'm working on a project that has a website in Rails and a C# GUI that use the same database and data models. I'd like to share the (active)models between the two parts. Any ideas on how this is possible?
IronRuby is exactly for that.
You will need to run Ruby on Rails with IronRuby (you can do that via IIS too) and then you can call your C# assemblies like they were Ruby libraries.
Some resources to get you started:
http://IronRuby.net - official site with some documentation (not full but you will find some good info there)
http://www.IronShay.com - my blog with several posts about IronRuby. You can also contact me via its contact form if you need more directions
http://www.ruby-forum.com/forum/34 - The IronRuby forum/mailing list, questions answered by members of the IronRuby community and the team members as well.
The short answer is you can't without redefining them on the C# gui.
You can expose the controllers as WSDL/SOAP instead of the restful stuff, then you can have visual studio generate the proxies for you. C# is really bad at dynamic stuff so you can't just take the ruby models and reuse them in C# because they need to be compiled.
You can of course write your own proxy generation tool for the "restful" resources of rails but at the end of the day you'll have to duplicate the model code somehow.
Like shay says you can use IronRuby to bridge the gap but it depends do you want to reuse the ActiveRecord classes or are you using the website as your point to get to the data?
When you want to reuse the activerecord models then IronRuby is the way to go to talk to your database (but to get good integration with C# you would have to create strong typed wrappers around the models, so I don't really see the point).
First thing that comes to mind for me would be to expose RESTful web services from the Rails application, and consume those services in your C# client application. I don't know of a way to avoid duplication if you want POCO's in your C# application - maybe write a CodeSmith or T4 template that reads schema.rb and generates POCO's.