Connecting a Matlab Neural Network with a VB.NET program - vb.net

I developed a neural network to train for face detection of the extracted images. However my program is built on VB.NET and I need to know the techniques by which I could load this neural network (Exported using NNTOOL) into memory and call it from VB.NET
So far I was only able to find this,
Dim MatLab As Object
Dim Result As String
Dim MReal(1, 3) As Double
Dim MImag(1, 3) As Double
Dim RealValue As Double
MatLab = CreateObject("matlab.application")
Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8;]")
Call MatLab.GetFullMatrix("a", "base", MReal, MImag)
I do not quite understand how this works, any suggestions on whether I could conenct the Neural network to VB.NET using this code and if so could you please explain to me about the Matlab.Execute and Matlab.GetFullMatrix functions. (What arguements would it support

In this article, three possible solutions are described. If you don't care much about performance, go with the first solution (use COM interop). Else, go with the third option (PInvoke), which is the fastest one. If you do choose to use PInvoke, a great resource is PInvoke.net

Related

Writing a computer program that will analyse the quality of another computer program?

I'm interested in knowing the possibilities of this. I'm working on a project that validates the skills of a software engineer, currently we validate skills based on code reviews by credentialed developers.
I know the answer if far more completed that the question, I couldn't imagine how complex the program would have to be able to analyse complex code but I am starting with basic programming interview questions.
For example, the classic FizzBuzz question:
Write a program that prints the numbers from 1 to 20. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
and below is the solution in python:
for num in range(1,21):
string = ""
if num % 3 == 0:
string = string + "Fizz"
if num % 5 == 0:
string = string + "Buzz"
if num % 5 != 0 and num % 3 != 0:
string = string + str(num)
print(string)
Question is, can we programatically analyse the validity of this solution?
I would like to know if anyone has attempted this, and if there are current implementations I can take a look at. Also if anyone has used z3, and if it is something I can use to solve this problem.
As Vilx- mentioned, correctness of programs (including whether or not they terminate) is in general known to be undecidable. However, tools such as Z3 show that relevant concrete cases can still be reasoned about, despite the general undecidability of the problem.
Static analysers typically look for "simple" problems (e.g. null dereferences, out-of-bounds accesses, numerical overflows), but are comparably fast and require little user guidance (think of guidance in the spirit of adding type annotations to your code).
A non-exhaustive (and biased) list of keywords to search for: "static analysers", "abstract interpretation"; "facebook infer", "airbus absint", "juliasoft".
Verifiers attempt to prove much richer properties, in particular functional correctness, e.g. "does this sort-implementation really sort my array (and not do anything else, e.g. deallocate some global memory or update an element reachable from the array)?" or "does that crypto-implementation really implement the crypto protocol it promises to implement?". This is a much harder task and tools from that line of research are typically rather slow, require expert users with a background in formal verification and significant user guidance.
A non-exhaustive (and biased) list of keywords to search for: "verification", "hoare logic", "separation logic"; "eth viper", "microsoft dafny", "kuleuven verifast", "microsoft f*".
Other formal methods exist, e.g. refinement (or correct-by-construction), but with even less tool support and, as far as I know, industry acceptance.
Let's put it this way: it's been mathematically proven that you CANNOT determine if a program will ever terminate. So if you want a mathematically perfect answer of if the target program is correct, you're doomed.
That said, you can still do unit tests and "linting" which will give you plenty of intetesting insights.
But for simple pieces of code like the FizzBuzz, I think that eyeballing by an experienced dev will probably bring the best results.

VB.net sending/recieving AT commands from SIM Card

ok, so i have been using Vb for a while but brand new to communicating with devices.
I have a HP Elitebook 820 which has a SIM card slot, what id like to do is display the SIM card info - specifically the serial number. I have done a bit of searching and found lots of people talking about AT commands. after a bit more searching i gave it a try.
Dim com1 As SerialPort = New System.IO.Ports.SerialPort
com1.PortName = "COM6"
com1.Open()
If com1.IsOpen Then
com1.Write("AT+CIMI")
Dim result As String
result = com1.ReadExisting
MsgBox(result)
Else
MsgBox("port not open")
End If
No Errors but just blank string returned. Could anyone help me out by letting me know, first if this even possible and second am i going about it the right way?
Step 1. Fetch a copy of the V.250 modem standard and read at least all of chapter 5. That will teach you a lot of basic AT command handling, like for instance that an AT command line should be terminated with \r.
Step 2. The very best documentation is your modem manufacturer's specific documentation which you definitely should try to get hold of that, however for basic mobile phone commands like AT+CIMI you can use the 3GPP spec 27.007 as well (assuming the manufacturer has not deviated in its implementation. Sometimes they do for some commands so this is something to watch out for (hence my recommendation to first and foremost get the modem manufacturer's specific documentation). The AT+CIMI command is however so simple there is nothing to deviate from really.).
Step 3. The reception handling, e.g. result = com1.ReadExisting is way too simplistic. You MUST read and parse every single line of response from the modem until you get a Final result code back (most commonly OK or ERROR, but there are several others). Any other way cannot work reliably. See this answer for pseudo code structure of how to do it properly.

Speed up MATLAB filter command

I am relatively new to using MATLAB filters. I am trying to filter a fairly large data set (about 2 million data points) using the following commands
rrc = rcosdesign(0.25, 10, floor(Fs/symRate), 'sqrt');
filtered = filter(rrc, 1, samples);
filtered = filtered / sqrt(floor(Fs/symRate));
When I run the MATLAB Profiler, it says the line
filtered = filter(rrc, 1, samples);
takes over 500 seconds to run. Any ideas on how to speed this up? I have tried using a FilterM function I found online ( http://www.mathworks.com/matlabcentral/fileexchange/32261-filterm ) but it takes the same amount of time. Anyone else have any ideas?
Thanks in advance
Few Ideas:
If you have FIR filter (As it seems from the code) you may gain performance using conv2 which uses Intel IPP which might speed things up. Use the 'valid' flag to get filter results.
If the filter is long and the data is long, try using xcorr as it uses FFT to speed up correlations. Since you're after filtering, remember to flip your filter coefficients.
Compile filterX using Visual Studio 2013 or even better Intel C Compiler 2013 with optimization flags (/03). When using it, use the filterX command directly (Skip FilterM wrapper).
Use FFT manually to perform convolution.
Create a MEX version of Intel MKL / Intel IPP filter function.
Any of these should help considerably.

Get most frequently used applications in VB.NET

Is there a way that I can get the most used applications via VB.NET? I'm developing a sort of hobby project as a quick launcher kind of thing and thought this would sit perfectly on the main form.
If possible, would somebody be able to explain to me how add/remove applications manages to get the frequency of used applications? It would be good if I could get it in a list like the XP/Vista start menu as well.
Any guidance would be greatly appreciated. :)
It looks like you can find information on how often a program is run in the registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\
There's more explanation here and a .NET program here that you could reverse engineer to get at the count values using VB.Net.
This might be a decent place to start. It seems like windows does a crappy job of determining frequency of applications use.
http://blogs.msdn.com/oldnewthing/archive/2004/07/09/178342.aspx
According to this posting the information is stored in the first 28 bytes of the SlowInfoCache Registry value found at the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Management\ARPCache
The format of the value is (in VB.Net):
Structure SlowInfoCache
Dim cLen As Integer ' size of the SlowInfoCache (552 bytes)
Dim Flag As Boolean ' has a name
Dim Size As Long ' program size in bytes
Dim LastUsed As Long ' API-style FILETIME
Dim Frequency As Integer ' 0-2 = rarely; 3-9 = occassionaly; 10+ = frequently
Dim Path As String ' remaining 524 bytes (max path of 260 + null) in unicode
End Structure
If you are interested in the other information displayed in Control Panel -> Add or Remove Programs you will find it listed for each product under the following Registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Or course these solutions only track when the shell (explorer.exe) is used to start a program via a shortcut (all start menu items are shortcuts). That's why it is so inaccurate.
FWIW I'm not aware of any microcomputer operating system that tracks the execution frequency of program images.
I suggest for your launcher tool that you initially popule it with the shortcuts from the quicklaunch bar and just make it really easy for the user to configure rather than trying to do anything automatic - automatic stuff that doesn't work in the way the user expects is one of the most annoying aspects of user interface design.
One question you should ask yourself is how are you going to determine frequency?
Are you going to base it on the number of times and application is run, or based on the length of time that an application is run for?

Quick divisibility check in ZX81 BASIC

Since many of the Project Euler problems require you to do a divisibility check for quite a number of times, I've been trying to figure out the fastest way to perform this task in ZX81 BASIC.
So far I've compared (N/D) to INT(N/D) to check, whether N is dividable by D or not.
I have been thinking about doing the test in Z80 machine code, I haven't yet figured out how to use the variables in the BASIC in the machine code.
How can it be achieved?
You can do this very fast in machine code by subtracting repeatedly. Basically you have a procedure like:
set accumulator to N
subtract D
if carry flag is set then it is not divisible
if zero flag is set then it is divisible
otherwise repeat subtraction until one of the above occurs
The 8 bit version would be something like:
DIVISIBLE_TEST:
LD B,10
LD A,100
DIVISIBLE_TEST_LOOP:
SUB B
JR C, $END_DIVISIBLE_TEST
JR Z, $END_DIVISIBLE_TEST
JR $DIVISIBLE_TEST_LOOP
END_DIVISIBLE_TEST:
LD B,A
LD C,0
RET
Now, you can call from basic using USR. What USR returns is whatever's in the BC register pair, so you would probably want to do something like:
REM poke the memory addresses with the operands to load the registers
POKE X+1, D
POKE X+3, N
LET r = USR X
IF r = 0 THEN GOTO isdivisible
IF r <> 0 THEN GOTO isnotdivisible
This is an introduction I wrote to Z80 which should help you figure this out. This will explain the flags if you're not familiar with them.
There's a load more links to good Z80 stuff from the main site although it is Spectrum rather than ZX81 focused.
A 16 bit version would be quite similar but using register pair operations. If you need to go beyond 16 bits it would get a bit more convoluted.
How you load this is up to you - but the traditional method is using DATA statements and POKEs. You may prefer to have an assembler figure out the machine code for you though!
Your existing solution may be good enough. Only replace it with something faster if you find it to be a bottleneck in profiling.
(Said with a straight face, of course.)
And anyway, on the ZX81 you can just switch to FAST mode.
Don't know if RANDOMIZE USR is available in ZX81 but I think it can be used to call routines in assembly. To pass arguments you might need to use POKE to set some fixed memory locations before executing RANDOMIZE USR.
I remember to find a list of routines implemented in the ROM to support the ZX Basic. I'm sure there are a few to perform floating operation.
An alternative to floating point is to use fixed point math. It's a lot faster in these kind of situations where there is no math coprocessor.
You also might find more information in Sinclair User issues. They published some articles related to programming in the ZX Spectrum
You should place the values in some pre-known memory locations, first. Then use the same locations from within Z80 assembler. There is no parameter passing between the two.
This is based on what I (still) remember of ZX Spectrum 48. Good luck, but you might consider upgrading your hw. ;/
The problem with Z80 machine code is that it has no floating point ops (and no integer divide or multiply, for that matter). Implementing your own FP library in Z80 assembler is not trivial. Of course, you can use the built-in BASIC routines, but then you may as well just stick with BASIC.