- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试解决问题 http://postimg.org/image/4bmfha8m7/
我在为 36 个输入实现权重矩阵时遇到问题。
我有一个 3 个神经元的隐藏层。
我使用反向传播算法来学习。
到目前为止我尝试过的是:
% Sigmoid Function Definition
function [result] = sigmoid(x)
result = 1.0 ./ (1.0 + exp(-x));
end
% Inputs
input = [1 1 0 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0;
0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 1;
0 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0;
0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 1];
% Desired outputs
output = [1;1;1;1];
% Initializing the bias (Bias or threshold are the same thing, essential for learning, to translate the curve)
% Also, the first column of the weight matrix is the weight of the bias values
bias = [-1 -1 -1 -1];
% Learning coefficient
coeff = 1.0;
% Number of learning iterations
iterations = 100;
disp('No. Of Learning Iterations = ');
disp(iterations);
% Initial weights
weights = ones(36,36);
% Main Algorithm Begins
for i = 1:iterations
out = zeros(4,1);
numIn = length (input(:,1));
for j = 1:numIn
% 1st neuron in the hidden layer
H1 = bias(1,1)*weights(1,1) + input(j,1)*weights(1,2) + input(j,2)*weights(1,3) + input(j,3)*weights(1,4)+ input(j,4)*weights(1,5) + input(j,5)*weights(1,6) + input(j,6)*weights(1,7)
+ input(j,7)*weights(1,8) + input(j,8)*weights(1,9) + input(j,9)*weights(1,10)+ input(j,10)*weights(1,11) + input(j,11)*weights(1,12) + input(j,12)*weights(1,13)
+ input(j,13)*weights(1,14) + input(j,14)*weights(1,15) + input(j,15)*weights(1,16)+ input(j,16)*weights(1,17) + input(j,17)*weights(1,18) + input(j,18)*weights(1,19)
+ input(j,19)*weights(1,20) + input(j,20)*weights(1,21) + input(j,21)*weights(1,22)+ input(j,22)*weights(1,23) + input(j,23)*weights(1,24) + input(j,24)*weights(1,25)
+ input(j,25)*weights(1,26) + input(j,26)*weights(1,27) + input(j,27)*weights(1,28)+ input(j,28)*weights(1,29) + input(j,29)*weights(1,30) + input(j,30)*weights(1,31)
+ input(j,31)*weights(1,32) + input(j,32)*weights(1,33) + input(j,33)*weights(1,34)+ input(j,34)*weights(1,35) + input(j,35)*weights(1,36)
x2(1) = sigmoid(H1);
% 2nd neuron in the hidden layer
H2 = bias(1,2)*weights(2,1) + input(j,1)*weights(2,2) + input(j,2)*weights(2,3) + input(j,3)*weights(2,4)+ input(j,4)*weights(2,5) + input(j,5)*weights(2,6) + input(j,6)*weights(2,7)
+ input(j,7)*weights(2,8) + input(j,8)*weights(2,9) + input(j,9)*weights(2,10)+ input(j,10)*weights(2,11) + input(j,11)*weights(2,12) + input(j,12)*weights(2,13)
+ input(j,13)*weights(2,14) + input(j,14)*weights(2,15) + input(j,15)*weights(2,16)+ input(j,16)*weights(2,17) + input(j,17)*weights(2,18) + input(j,18)*weights(2,19)
+ input(j,19)*weights(2,20) + input(j,20)*weights(2,21) + input(j,21)*weights(2,22)+ input(j,22)*weights(2,23) + input(j,23)*weights(2,24) + input(j,24)*weights(2,25)
+ input(j,25)*weights(2,26) + input(j,26)*weights(2,27) + input(j,27)*weights(2,28)+ input(j,28)*weights(2,29) + input(j,29)*weights(2,30) + input(j,30)*weights(2,31)
+ input(j,31)*weights(2,32) + input(j,32)*weights(2,33) + input(j,33)*weights(2,34)+ input(j,34)*weights(2,35) + input(j,35)*weights(2,36)
x2(2) = sigmoid(H2);
% 3rd neuron in the hidden layer
H3 = bias(1,3)*weights(3,1) + input(j,1)*weights(3,2) + input(j,2)*weights(3,3) + input(j,3)*weights(3,4)+ input(j,4)*weights(3,5) + input(j,5)*weights(3,6) + input(j,6)*weights(3,7)
+ input(j,7)*weights(3,8) + input(j,8)*weights(3,9) + input(j,9)*weights(3,10)+ input(j,10)*weights(3,11) + input(j,11)*weights(3,12) + input(j,12)*weights(3,13)
+ input(j,13)*weights(3,14) + input(j,14)*weights(3,15) + input(j,15)*weights(3,16)+ input(j,16)*weights(3,17) + input(j,17)*weights(3,18) + input(j,18)*weights(3,19)
+ input(j,19)*weights(3,20) + input(j,20)*weights(3,21) + input(j,21)*weights(3,22)+ input(j,22)*weights(3,23) + input(j,23)*weights(3,24) + input(j,24)*weights(3,25)
+ input(j,25)*weights(3,26) + input(j,26)*weights(3,27) + input(j,27)*weights(3,28)+ input(j,28)*weights(3,29) + input(j,29)*weights(3,30) + input(j,30)*weights(3,31)
+ input(j,31)*weights(3,32) + input(j,32)*weights(3,33) + input(j,33)*weights(3,34)+ input(j,34)*weights(3,35) + input(j,35)*weights(3,36)
x2(3) = sigmoid(H3);
% Output layer
x3_1 = bias(1,4)*weights(4,1) + x2(1)*weights(4,2) + x2(2)*weights(4,3) + x2(3)*weights(4,4);
out(j) = sigmoid(x3_1);
% Adjust delta values of weights
% For output layer: delta(wi) = xi*delta,
% delta = (1-actual output)*(desired output - actual output)
delta3_1 = out(j)*(1-out(j))*(output(j)-out(j));
% Propagate the delta backwards into hidden layers
delta2_1 = x2(1)*(1-x2(1))*weights(3,2)*delta3_1;
delta2_2 = x2(2)*(1-x2(2))*weights(3,3)*delta3_1;
delta2_3 = x2(3)*(1-x2(3))*weights(3,4)*delta3_1;
% Add weight changes to original weights and then use the new weights.
% delta weight = coeff*x*delta
for k = 1:4
if k == 1 % Bias cases
weights(1,k) = weights(1,k) + coeff*bias(1,1)*delta2_1;
weights(2,k) = weights(2,k) + coeff*bias(1,2)*delta2_2;
weights(3,k) = weights(3,k) + coeff*bias(1,3)*delta2_3;
weights(4,k) = weights(4,k) + coeff*bias(1,4)*delta3_1;
else % When k=2 or 3 input cases to neurons
weights(1,k) = weights(1,k) + coeff*input(j,1)*delta2_1;
weights(2,k) = weights(2,k) + coeff*input(j,2)*delta2_2;
weights(3,k) = weights(3,k) + coeff*input(j,3)*delta2_3;
weights(4,k) = weights(4,k) + coeff*x2(k-1)*delta3_1;
end
end
end
end
disp('For the Input');
disp(input);
disp('Output Is');
disp(out);
disp('Test Case: For the Input');
input = [1 1 0 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0];
最佳答案
对我来说问题是标签,我看不到输出在哪里
输出 (1,1,1,1)?你是什么意思。也许我错过了一些东西,但对我来说,有两种标记多类分类的方法,一种是直接使用标签(A 为 0,B 为 1,C 为 3 ...)并在之后展开或直接展开,如 A=1, 0,0,0 = [1,0,0,0;0,1,0,0;0,0,1,0;0,0,0,1]
你做运算的方式很容易出错,看看matlab/octave matrix operations,它非常强大,可以简化很多事情。
关于matlab - 在 Matlab/Octave 中实现神经网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35094385/
假设我们在 Octave 中运行以下命令集: pkg load symbolic %loads the symbolic math package syms x y %declare x and y
Octave中vec的逆运算是什么? 例如。如果我需要将12x1向量转换成3x4矩阵,该怎么办? 最佳答案 我不知道Octave,但我认为您正在寻找 reshape 。 — Built-in Func
我试图在向量中找到一个字符串。 例如:query = "ab"in vector = ["ab", "cd", "abc", "cab"] 问题是:当我使用函数 strfind(vector,quer
对于练习,我必须以 Octave 为单位创建函数 x^i 从 i=1 到 i=10 的动画图。绘图必须有一个动态的标题,曲线的颜色必须改变。目前我的代码如下: function exercicequa
有没有一种方法可以让 Octave 矩阵将字符串和数字放在一起? 我想要一个休闲类型的矩阵: A=["A","B","C","D";1,2,3,4;2,3,4,5;3,4,5,6;4,5,6,7];
事实上,我已经为此奋斗了大约两个月。是什么让这些有所不同? hypotheses= X * theta temp=(hypotheses-y)' temp=X(:,1) * temp temp=tem
我想在我的绘图中添加带有注释的文本或图例框。 目前我的图例绘制在东北外,我想将新的图例(或文本框)添加到东南外的位置。 谢谢! 最佳答案 缺乏有关您的案例的更多信息: 据我所知,一个坐标区对象只能有一
我想在我的绘图中添加带有注释的文本或图例框。 目前我的图例绘制在东北外,我想将新的图例(或文本框)添加到东南外的位置。 谢谢! 最佳答案 缺乏有关您的案例的更多信息: 据我所知,一个坐标区对象只能有一
我想在 Octave 中执行整数除法(我使用的是最新版本 5.1.0)。我厌倦了 idivide(5, 2, "round") 应该产生 3。 Documentation表示将 idivide 与 r
我正在尝试从矩阵中按行获取最大索引。为此,我正在做: [throwaway, indexes] = max(blah, [], 2); 变量“throwaway”会存储我不再需要且永远不会使用的值,我
我在启动 Octave 后收到以下警告。我使用了来自 here 的安装说明. 可能是什么问题?这些是主要警告吗?我正在使用 Windows。 warning: gmsh does not seem t
我一直在学习机器学习类(class),目前学习分类。我实现了分类算法并获得了参数和成本。该作业已经具有绘制决策边界的功能并且可以正常工作,但我试图阅读他们的代码但无法理解这些行。 plot_x = [
我正在尝试更改 octave 中的polar 图中标记的外观。 r = rand(1,10); % the radius t = 30*rand(1,10); % the angles polar(t
我正在尝试从 Octave 中的文件读取矩阵,但我找不到解决方案。 输入文件是: 4 1 4 2 3 1 4 2 1 4 2 1 4 1 2 1 3 其中 4 是行数和列数。我希望能够将该信息存储在矩
我正在运行 Octave 3.4.0 并想创建一个透明的曲面图。但是,我在处理 facealpha 时无法这样做。 , edgealpha , alphadata和 alphadatamapping
安装一个包后,查找该包中有哪些功能的命令是什么? 例如,我有 control安装包。但是如何找到关于这个包的帮助,比如它包含哪些函数等等,就像使用 Matlab 一样? 是否必须去http://oct
我正在尝试在 Octave 音程终端中打印一长串数字。 disp(vec); 我得到的 7.0931e-01 6.2041e-05 9.7740e-01 9.9989e-01 8.8428e-01 9
我试图在OS X上安装Octave。执行brew install octave时,出现以下错误: octave: A LaTeX distribution is required to install
有人知道如何在 Octave 中增加图例字体大小吗? 最佳答案 这对我有用(kubuntu 9.04, Octave 3.2.2) print("plot.eps","-deps", "-F:30")
我试图弄清楚如何增加命令窗口文本。 我想出了legend: legend('{\fontsize{10} Low }', '{\fontsize{10} Medium }', '{\fontsize{
我是一名优秀的程序员,十分优秀!