我如何在matlab中实现这个神经网络成本函数:

以下是符号代表的含义:
% m is the number of training examples. [a scalar number]
% K is the number of output nodes. [a scalar number]
% Y is the matrix of training outputs. [an m by k matrix]
% y^{(i)}_{k} is the ith training output (target) for the kth output node. [a scalar number]
% x^{(i)} is the ith training input. [a column vector for all the input nodes]
% h_{\theta}(x^{(i)})_{k} is the value of the hypothesis at output k, with …Run Code Online (Sandbox Code Playgroud) 我在网上找不到这个问题的答案,而在其他类似问题的答案中,似乎DFS的一个优点就是它使用的内存比DFS少.
对我而言,这似乎与我的期望相反.BFS只需存储它访问的最后一个节点.例如,如果我们在下面的树中搜索数字7:

它会搜索值为8的节点,然后是3,10,1,6,14,4,然后是最终的7.对于DFS,它将搜索值为8的节点,然后是3,1,6,4,最后是7 .
如果每个节点都存储在内存中,并且有关于其值,子节点以及它在树中的位置的信息,则BFS程序只需要存储有关其访问的最后一个节点的位置的信息,然后它就可以检查树,找到树中的下一个节点.DFS程序必须存储它所在的最后一个节点,以及它已经访问过的所有节点,因此它不会再次检查它们,只是循环遍历从第二代到最后一代节点之一的所有叶节点.
那么为什么BFS实际上使用更少的内存呢?
我过去曾在本网站上询问过一些关于神经网络的问题,并得到了很好的答案,但我仍然在努力为自己实施一个.这是一个相当长的问题,但我希望它可以作为其他人在MATLAB中创建自己的基本神经网络的指南,所以它应该是值得的.
到目前为止我所做的完全错了.我正在跟随Andrew Y. Ng教授的在线斯坦福机器学习课程,并试图尽我所能地实施他所教授的内容.
您能否告诉我,我的代码的前馈和成本函数部分是否正确,以及我在最小化(优化)部分出错的地方?
我有一个饲料2层前馈神经网络.
前馈部分的MATLAB代码是:
function [ Y ] = feedforward2( X,W1,W2)
%This takes a row vector of inputs into the neural net with weight matrices W1 and W2 and returns a row vector of the outputs from the neural net
%Remember X, Y, and A can be vectors, and W1 and W2 Matrices
X=transpose(X); %X needs to be a column vector
A = sigmf(W1*X,[1 0]); %Values of the first hidden layer
Y = sigmf(W2*A,[1 0]); %Output Values …Run Code Online (Sandbox Code Playgroud) 在GitLab CI文档中,Windows支持bash shell.
Supported systems by different shells:
Shells Bash Windows Batch PowerShell
Windows ? ? (default) ?
Run Code Online (Sandbox Code Playgroud)
在我的config.toml中,我尝试过:
[[runners]]
name = "myTestRunner"
url = xxxxxxxxxxxxxxxxxxx
token = xxxxxxxxxxxxxxxxxx
executor = "shell"
shell = "bash"
Run Code Online (Sandbox Code Playgroud)
但是,如果我的.gitlab-ci.yml尝试执行bash脚本,例如
stages:
- Stage1
testJob:
stage: Stage1
when: always
script:
- echo $PWD
tags:
- myTestRunner
Run Code Online (Sandbox Code Playgroud)
然后从包含GitLab多跑步者的文件夹中右键单击并选择'git bash here',然后键入:
gitlab-runner.exe exec shell testJob
Run Code Online (Sandbox Code Playgroud)
它无法解决$PWD,证明它实际上并没有使用bash执行程序.(Git bash通常可以$PWD在Windows上正确打印出来.)
Running with gitlab-runner 10.6.0 (a3543a27)
Using Shell executor...
Running on G0329...
Cloning repository...
Cloning …Run Code Online (Sandbox Code Playgroud) Qt Creator(4.2.1)默认情况下用于执行此操作。它会显示与我的文件系统中的目录结构相同的文件结构,但是只会显示当前项目的源文件或头文件。它可以工作,这一点与CMake的add_executable,add_library或者add_custom_target函数调用。
现在,新版本的Qt Creator会显示文件系统中的所有文件,无论它们是源文件还是头文件。我可以将其从“文件系统”视图更改为“项目”视图,但是这种结构以与目录结构不同的方式来组织文件,即,将文件组织为“标题”,“目标”和“ CMake模块”。
如何才能使Qt Creator表现得更像旧版本,并且只显示与我的项目相关的文件,而是显示它们实际所在的目录结构?
谢谢。
我有一个代码,可以生成0到36之间4个整数的所有可能组合.
这将是37 ^ 4个数字= 1874161.
我的代码是用MATLAB编写的:
i=0;
for a = 0:36
for b= 0:36
for c = 0:36
for d = 0:36
i=i+1;
combination(i,:) = [a,b,c,d];
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
我用数字3而不是数字来测试这个,36它运行正常.
如果有1874161个组合,并且An过度警告猜测100个时钟周期来进行添加并写入值,那么如果我有一个2.3GHz的PC,那么:
1874161*(1/2300000000)*100 = 0.08148526086
几分之一秒.但到目前为止它已经运行了大约半个小时.
我确实收到了一个警告combination changes size every loop iteration, consider predefining its size for speed,但这不能影响那么多吗?
我有一个程序,它在循环中创建线程,并检查它们是否已完成并清理它们(如果已完成)。请参阅下面的最小示例:
use std::thread;
fn main() {
let mut v = Vec::<std::thread::JoinHandle<()>>::new();
for _ in 0..10 {
let jh = thread::spawn(|| {
thread::sleep(std::time::Duration::from_secs(1));
});
v.push(jh);
for jh in v.iter_mut() {
if jh.is_finished() {
jh.join().unwrap();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这给出了错误:
error[E0507]: cannot move out of `*jh` which is behind a mutable reference
--> src\main.rs:13:17
|
13 | jh.join().unwrap();
| ^^^------
| | |
| | `*jh` moved due to this method call
| move occurs because `*jh` has type `JoinHandle<()>`, which does …Run Code Online (Sandbox Code Playgroud) 如果我有一个向量:
A=[1,1,1]
我知道它有长度,SQRT((1 ^ 2)+(1 ^ 2)+(1 ^ 2))= SQRT(3)=约1.73
但是我如何在MATLAB中做到这一点?
我试过了:
abs(A)
Run Code Online (Sandbox Code Playgroud)
但这只返回数组中每个元素的绝对值.所以它只返回相同的数组,如下所示:
B=abs(A)
B=[1,1,1]
Run Code Online (Sandbox Code Playgroud)
如何让MATLAB给出整个向量的绝对值,所以我得到一个标量输出?
我宁愿用单个函数来做,而不是单独操作向量中的每个元素,因为我的代码变得非常混乱.
谢谢!
我怎样才能得到std::typeindex当前类型的帮助?
假设我有一个变体:
\n\nusing variant_t = std::variant<int, float, bool, double, std::string>;\nRun Code Online (Sandbox Code Playgroud)\n\n我希望能够创建该函数:
\n\nstd::typeindex get_held_type(const variant_t& var);\nRun Code Online (Sandbox Code Playgroud)\n\n这只是出于好奇,我知道这不是处理变体数据的常用方法。
\n\n如果我添加另一种类型variant_t,我不想更改任何其他代码。即,类型需要自注册。
到目前为止,这是我的尝试。我有点作弊,因为我使用映射而不是函数,并且必须构造一个对象才能在运行时注册类型。
\n\n#include <iostream>\n#include <variant>\n#include <string>\n#include <vector>\n#include <typeindex>\n#include <map>\n\nusing variant_t = std::variant<int, float, bool, double, std::string>;\nstatic constexpr size_t variant_t_size = std::variant_size<variant_t>();\nstatic auto get_held_type = std::map<size_t, std::type_index>{};\n\n//loop across all types in the variant\ntemplate<size_t N>\nstruct crtp : crtp<N - 1>{\n //ctor\n crtp(){\n get_held_type[N] = std::type_index(typeid (std::get<N>(variant_t{})));\n }\n};\n\ntemplate<>\nstruct crtp<0>{\n //ctor\n crtp(){\n get_held_type[0] = std::type_index(typeid (std::get<0>(variant_t{})));\n …Run Code Online (Sandbox Code Playgroud) 我想为可变参数模板中的每种类型创建一个纯虚拟接口。例如,一个类:
overloads_interface<int,float,bool>
Run Code Online (Sandbox Code Playgroud)
定义了功能:
virtual void overload(const int& arg) = 0
virtual void overload(const float& arg) = 0
virtual void overload(const bool& arg) = 0
Run Code Online (Sandbox Code Playgroud)
如果我将其他类型添加到变量模板中,例如
overloads_interface<int,float,bool, std::string>
Run Code Online (Sandbox Code Playgroud)
它将自动添加重载:
virtual void overload(const std::string& arg) = 0
Run Code Online (Sandbox Code Playgroud)
然后,为了实例化此类,我必须实现这些功能,例如:
class concrete : public overloads_interface<int,float,bool> {
public:
virtual void overload(const int& arg) override { /**handle int**/ }
virtual void overload(const float& arg) override { /**handle float**/ }
virtual void overload(const bool& arg) override { /**handle bool**/ }
};
Run Code Online (Sandbox Code Playgroud)
这是我创建此类的最佳尝试:
template<typename... args>
class overloads_interface { …Run Code Online (Sandbox Code Playgroud)