标签:排查 条件 nal not run package float stack simulink 结果
http://www.cnblogs.com/bellkosmos/p/5598439.html
alldata = load(‘alldata.txt‘);
alldata = alldata(:,:);
|
clc;
clear;
%导入300组数据
alldata = load(‘alldata.txt‘);
alldata = alldata(:,:);
%输入输出数据
input = alldata(:,2:33);
outputtemp = alldata(:,1);
%输出数据需要处理一下
output = zeros(300,2);%预先分配内存
for i=1:300
switch outputtemp(i)
case 0
output(i,:) = [1 0];%意思是如果数据结果是0,则输出层的状态是[1 0],或者用第一个输出节点表示
case 1 %能直接识别带小数位的数据
output(i,:) = [0 1];
end
end
%从中随机抽取280组数据作为训练数据,20组数据作为预测数据
k = rand(1,300);
[m,n] = sort(k);
input_train = input(n(1:280),:)‘;
output_train = output(n(1:280),:)‘;
input_test = input(n(281:300),:)‘;
output_test = output(n(281:300),:)‘;
%输入输出数据进行归一化处理
[inputn,inputps] = mapminmax(input_train);
[outputn,outputps] = mapminmax(output_train);
%网络结构构建32-6-2
net=newff(inputn,outputn,6);
%网络参数配置(迭代次数,学习率,目标)
net.trainParam.epochs=100;
net.trainParam.lr=0.1;
net.trainParam.goal=0.0004;
%网络训练
net=train(net,inputn,outputn);
%BP网络预测
%预测数据归一化
inputn_test=mapminmax(‘apply‘,input_test,inputps);
%网络预测输出
an=sim(net,inputn_test);
%网络输出反归一化
BPoutput=mapminmax(‘reverse‘,an,outputps);
%结果分析
figure(1)
plot(BPoutput,‘:og‘)
hold on
plot(output_test,‘-*‘);
legend(‘预测输出‘,‘期望输出‘)
title(‘BP网络预测输出‘,‘fontsize‘,12)
ylabel(‘函数输出‘,‘fontsize‘,12)
xlabel(‘样本‘,‘fontsize‘,12)
%预测误差
error=BPoutput-output_test;
figure(2)
plot(error,‘-*‘)
title(‘BP网络预测误差‘,‘fontsize‘,12)
ylabel(‘误差‘,‘fontsize‘,12)
xlabel(‘样本‘,‘fontsize‘,12)
figure(3)
plot((output_test-BPoutput)./BPoutput,‘-*‘);
title(‘神经网络预测误差百分比‘)
errorsum = sum(abs(error))
|
MATLAB官方论坛中看到这样一个回答:
You will not be able to compile any function which trains the network (like ADAPT). Though the link does not explicitly list these funcions (like ADAPT), they fall under the ‘All other command line functionality‘.
However, you can deploy a M function code which uses a pre-trained network. I believe the SIM function will deploy fine.
The workflow I see is:
1. In MATLAB, train you network using test input/output
2. Save the network (mat file?)
3. Create a deployable function which then uses the pretrained network for new data. The network itself would not change/adapt/train in this function
4. Compile and deploy the above function
大意:MATLAB compile不支持对神经网络工具箱中涉及到训练的函数命令进行编译,只能编译那些用在已训练好的网络上的函数命令
|
function output = annforecastthi(input_test)
%ANNFORECAST
% 输入长度为32的行矩阵,输出为1或2
A = load(‘annnet.mat‘);
B = fieldnames(A);
net = A.(B{1});
net = network(net);
C = load(‘anninputps.mat‘);
D = fieldnames(C);
inputps = C.(D{1});
E = load(‘annoutputps.mat‘);
F = fieldnames(E);
outputps = E.(F{1});
%BP网络预测
%预测数据归一化
inputn_test=mapminmax(‘apply‘,input_test‘,inputps);
%网络预测输出
an=sim(net,inputn_test);
%网络输出反归一化
BPoutput=mapminmax(‘reverse‘,an,outputps);
%结果分析
%根据网络输出找出数据属于哪类
output=find(BPoutput(:,1)==max(BPoutput(:,1)));
end
|
public class TestMatlab {
public static void main(String[] args){ try { ANNMatlab annMatlab = new ANNMatlab();
double[] array = {74.5,75.5 ,83.3 ,93.4 ,93.9 ,90.1 ,86.1 ,... };
Object result[]=annMatlab.annforecastthi( 1,array);
//函数第一个参数是输出数据个数,之后的就是是输入数据。
System.out.println("result=="+result[ 0]);
} catch (MWException e) { e.printStackTrace(); } }
}
|
The .jar files that Compiler SDK generates cannot be run on Android. The .jar has a small interface to call upon the machine code library that is MCR, and otherwise the .jar contains encrypted data files. The encrypted data files are the "compiled" .m code, which is not compiled to java, but rather to MATLAB‘s internal threaded interpreter. MCR decrypts the encrypted pcode‘d .m files and uses them as data to be processed by the threaded interpreter. The encrypted data files themselves can be fairly operating system independent, but you need MCR to interpret them, and MCR is in x86 or x64 machine code for all versions of MATLAB since about R2009a. Android does not run on x86 or x64: Android runs on ARM processors (or possibly PowerPC as well, I am not certain.)
In short, you cannot use Compiler SDK to generate for anything useful on Android.
At this time, the only way to deploy for Android is to use Simulink with Target set to Android. You can have your Simulink blocks call a MATLAB Function block which is specialized MATLAB code (that has to be careful about how it allocates memory.) There is not much graphics you can do with this mechanism but it is the best that is available at this time.
I happened to look last night at some of the blocks available for deployment to a couple of the Android Galaxy devices. There is a block which accepts R, G, and B signals and displays the result as the screen. It would require computing the entire screen, I suspect. Some of the routines in the Vision toolbox help in that.
大意:matlab生成的jar包不能直接在android上运行,还需要用一个叫MCR的东西进行解码(The MATLAB Compiler Runtime (MCR) has the same System requirements as MATLAB. See System Requirements - Android is not one of them.它是matlab代码解析器),而MCR目前只能运行在X86或者X64的CPU上,但因为android是运行在ARM CPU上,所以是不可能使用的。
然后它说:此时,部署Android的唯一方法是使用Simulink与目标设定为Android。你可以有你的Simulink模块调用MATLAB函数的MATLAB代码块是专业(需注意如何分配内存)没有多大的图形可以做这种机制,但它是最好的,此时可用。
后边这个就看不懂了:我碰巧看的最后一个晚上的一些块可供部署到一对夫妇的安卓银河设备。有一个块,它接受R,G和B信号,并显示屏幕的结果。它将需要计算整个屏幕,我怀疑。一些例程中的“视觉工具箱”中的帮助。
I have not read about what can be done in R2016a. The situation as of R2015b was that in order to generate code for Android from MATLAB, what you needed to do was include the MATLAB code in a MATLAB Function block in Simulink and tell Simulink to target Android; there was no direct path for MATLAB to Android.
大意:你需要做的是包括在Simulink MATLAB功能块的matlab代码告诉Simulink目标Android
However, you should be able to use the MATLAB Coder product to generate a standalone C/C++ library from your MATLAB code and then invoke that from your Android application, possibly using JNI.
大意:你可以使用一个叫MATLAB Coder的工具来生成可以独立运行的C/C++库,他们可以在android中通过JNI来直接运行
MATLAB code that is put into a Simulink MATLAB Function Block (with appropriate adjustments made) can be generated for Android target using Simulink. There are a bunch of restrictions on this, but I think it can access the Android Sensor information for supported devices (Galaxy S4, Galaxy Note 2)
大意:matlab代码,把MATLAB的一个Simulink功能块(适当调整)可以为Android使用Simulink生成目标。有一些限制,但我认为它可以访问支持的设备Android传感器信息(Galaxy S4,Galaxy Note 2)
From MATLAB, you can communicate with Android camera and with Android sensors (at least for some models), but it is not possible to generate code for Android. You need to use Simulink to generate code for Android.
MATLAB Coder does not know about Android, so MATLAB Coder cannot generate Android calls for user interaction, networking, graphics, and so on. MATLAB Coder can generally generate C or C++, but unless it has been given information about the target system, MATLAB Coder has a library of calls that is not even as complete as the Standard C Library. This is not enough to create an Android "app"; at most it is enough to create a utility program.
Simulink does know how to target Android, so if you have a Simulink model and use the Android-specific blocks, Simulink can create apps. See http://www.mathworks.com/hardware-support/android-programming-simulink.html
大意:可以用Simulink
.so files are Linux Shared Object libraries. Those .so files are only available for Intel x86 (32 bit) and x64 (64 bit) instruction set (including AMD CPUs that implement those.) They are not available for ARM or other instruction architectures.
大意:.so文件本身也只能再X86的系统上使用,而不能在ARM上使用(这个存疑)
The .jar file requires the MATLAB Compiler Runtime (a freely redistributable component that you get with MATLAB Compiler and MATLAB Builder products) to be present. The MCR has a much larger footprint than is suitable for the typical Android device (it‘s like a copy of MATLAB itself, without the user interface).
You could think about either
1)Running your MATLAB .jar file remotely on a server, and having your Android application connect to it, or
2)Instead of using MATLAB Compiler and Builder products, use MATLAB Coder, which will convert a subset of the MATLAB language directly into C code. This C code doesn‘t require the MCR, and could be compiled to run directly on Android. Make sure your MATLAB algorithm falls within, or can be expressed in, the appropriate subset of the MATLAB language.
大意:前面都一样不说了,后边提了两个解决办法:1)不要再app上用Matlab代码,转移到服务器上;2)用MATLAB Coder编译成可以不需要MCR支持才能运行的C/C++文件
A new feature in Matlab 2014a:
http://www.mathworks.com/help/simulink/samsung-galaxy-android-devices.html
You can now directly install (limited set of) models to Samsung Android devices, and this should work actually on any Android device.
大意:2014的新版本中,你可以直接把matlab模型安装在三星安卓设备上,实际上就可以安装在所有安卓设备上
|
标签:排查 条件 nal not run package float stack simulink 结果
原文地址:http://www.cnblogs.com/jukan/p/7275110.html