MSc/MEng Data Mining and Machine Learning (2024) Lab 4 – Neural NetworksPython

Java Python MSc/MEng Data Mining and Machine Learning (2024)

Lab 4 – Neural Networks

Problem

The challenge is to implement the Error Back-Propagation (EBP) training algorithm for a multi-layer perceptron (MLP) 4-2-4 encoder [1] using Matlab (or Python if you wish).   Intuitively the structure of the encoder is as shown in Figure 1.

Figure 1: MLP structure for 4-2-4 encoder

The MLP has an input layer with 4 units, a single hidden layer with 2 hidden units, and an output layer with 4 units.  Each unit has a  sigmoid activation function. The task of the encoder is to  map the following inputs onto outputs:

Table 1: Input-output pairs for the 4-2-4 encoder

The problem is that this has to be achieved through the 2-unit “bottle-neck” hidden layer.  Rumelhart, Hinton and Williams demonstrate that to achieve this, the MLP learns binary encoding in the hidden layer.

Input (and target) pattern

There are 4 input patterns, and the targets are equal to the inputs (Table 1).  Recall that the output oj of the jth  unit in the network is given by:

where netj  is the input to the jth unit.  The values of oj  converge towards 0 and 1 as the magnitude of netj  becomes large, but the values 0 and 1 are never realised.  Hence for practical purposes it is better to replace, for example,  1, 0, 0, 0  in Table 1 with a `softer’ version  0.9, 0.1, 0.1, 0.1.

Since there are only these 4 input/output pairs, the training set consists of just 4 input/output pairs.

Structure of the program

The program needs to run the EBP weight updating process multiple times.  So you will need a variable N for the number of iterations and an outer loop (for n=1:1:N).  You could terminate the process when the change in error drops below a threshold but this is simpler for the moment.  In addition you will need a second inner loop (for d=1:1:4) to cycle through the 4 input patterns in each iteration. But before you do this you need to set up some basic structures:

•     You will  need two arrays W1 and W2 to store the weights  between the input and hidden, and hidden and output layers, respectively.  I suggest that you make W1of size 4x2 and W2of size 2x4. You will need to initialize these arrays (randomly?).  Given an output x from the input layer, the input y to the hidden layer is given by:

y = W1’*x;

Note the transpose!

•     The output from the hidden layer is obtained by applying the  MSc/MEng Data Mining and Machine Learning (2024) Lab 4 – Neural NetworksPython ;sigmoid function to y, so you will need to write a function to implement this function.

•     Once you have propagated the input to the output layer you can calculate the error.   In fact the only use you have for the error is to plot it to help confirm that your code is working.

•     Now you need to back-propagate to calculate δj  for every unit j in the output and hidden layers. First you need to calculate δj  for every output unit (see Eq. (12) in the slides).  Then you need to apply back-propagation to calculate δj  for every hidden unit (again see Eq. (12) in the slides).  To back-propagate the vector of δjs from the output layer to the hidden layer you just need to multiply by W2 (no transpose this time):

deltaH = W2*deltaO;

where deltaO and deltaH are the deltas in the output and hidden layers, respectively.  Note that the above equation is only a part of the equation needed (just to indicate the use of the matrices for doing this calculation) – the full equation is Eq. (12) in the slides.

Once you have calculated the δjs for the output and hidden layers you can calculate ∆wij  = −θδjoi

(see slide 19 from the lecture).

•     Finally, you can update the weights: wij   → wij  + ∆wij

I suggest you do all this about 2,000 times (for n=1:1:N, N=2000) and plot the error as a function of n.

Practical considerations

If you implement all of this properly you will see that the error decreases as a function of n.  You should explore the learning rate, different initialisations of the weight matrices, different numbers of iterations, `softening’ the input/output patterns, etc.   However, you will find that whatever you do you cannot get the error to reduce to zero.  To do this I think you need to add bias units to the input and hidden layers.

Lab-Report Submission

Submit your lab report and source code.   Your  lab report should include thorough comments on experimental evaluations and results obtained.  Include the listing of your source code in appendix of the lab report.

References

[1] D. E. Rumelhart, G. E. Hinton, and R. J. Williams (1986), “Learning Internal Representations by Error Propagation”,  In:  Rumelhart,  D.E.,  McClelland,  J.L.  and  the   PDP  Research  Group,   Eds.,   Parallel Distributed  Processing:  Explorations  in  the  Microstructure  of  Cognition,  Vol.  1:  Foundations,  MIT Press, Cambridge, MA, 318-362         

### 解决 Ubuntu 中 `umount failed: target is busy` 错误 当尝试卸载挂载的Ventoy U盘时出现 `target is busy` 错误,通常是因为有进程正在访问该设备或其挂载点。为了解决此问题,需确保设备未被占用,以下是几种有效的处理方式。 1. **使用 `lsof` 检查占用设备的进程** 可以通过以下命令查看哪些文件或进程正在使用U盘设备: ```bash lsof /media/username/mount_point ``` 或者直接查找设备文件: ```bash lsof /dev/sdX1 ``` 找到相关进程后,可以使用 `kill` 命令终止它们: ```bash kill PID ``` 如果进程无法轻易终止,可使用 `kill -9 PID` 强制终止。 2. **使用 `fuser` 查找并终止占用设备的进程** 执行以下命令查找占用设备的进程: ```bash fuser -v /media/username/mount_point ``` 然后使用以下命令终止所有占用该挂载点的进程: ```bash fuser -k /media/username/mount_point ``` 这样可以快速释放设备资源,使其可以被卸载。 3. **卸载所有挂载在设备上的分区** 如果U盘有多个分区被挂载(例如 `/dev/sdX1` 和 `/dev/sdX2`),需确保所有分区都被卸载: ```bash sudo umount /dev/sdX1 sudo umount /dev/sdX2 ``` 4. **使用 `umount --lazy` 延迟卸载设备** 如果设备无法立即卸载,可以使用延迟卸载选项: ```bash sudo umount -l /media/username/mount_point ``` 该命令会立即解除挂载点与文件系统的绑定,并在设备不再被使用后自动完成卸载过程。 5. **检查是否有自动挂载服务干扰** Ubuntu 中的 `udisks` 或 `gvfs` 等自动挂载服务可能在后台持续访问U盘。可以通过以下命令临时禁用这些服务: ```bash gnome-disks --stop-device /dev/sdX ``` 或者手动编辑 `fstab` 配置,避免设备被自动挂载。 6. **重启系统并尝试卸载** 如果以上方法均无效,可以尝试重启系统后再卸载设备。重启会终止所有用户进程,确保设备不再被占用。 ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值