如何修改Autoencoder对象的只读输出?

问题描述 投票:0回答:1

运行指定的函数后,我得到类类型为Autoencoder的对象:

[X,T] = wine_dataset;
hiddenSize = 25;
autoenc1 = trainAutoencoder(X,hiddenSize,...
                            'L2WeightRegularization',0,...
                            'SparsityRegularization',0,...
                            'SparsityProportion',1,...
                            'DecoderTransferFunction','purelin');

如果我尝试查询其中一个属性,我可以毫无问题地得到它,

>> autoenc1.EncoderWeights(1,1)  

ans = -0.0404  

但是,如果我尝试设置它,我会收到一个错误:

>> autoenc1.EncoderWeights(1,1) = 0.4 

In class 'Autoencoder', no set method is defined for Dependent property 'EncoderWeights'. A 
Dependent property needs a set method to assign its value.
matlab properties setter autoencoder readonly-attribute
1个回答
0
投票

Why are you getting this problem?

要理解这种行为,我们应该看看Autoencoder类(\MATLAB\R20###\toolbox\nnet\nnet\nnnetwork\Autoencoder.m)。我们可以看到以下内容:

  • 'EncoderWeights'定义在properties(SetAccess = private, Dependent)区块内。
  • 为此属性定义了一个公共的“getter”方法:function val = get.EncoderWeights(this)

因此,我们看到'EncoderWeights'既不是一个可公开设置的领域,也没有一个公开的setter方法 - 所以你得到一个错误并不奇怪。顺便说一句,在R2018b上,错误可能会提供更多信息:

You cannot set the read-only property 'EncoderWeights' of Autoencoder.

(如果您不熟悉我上面使用的概念,我建议您阅读有关classes in MATLAB的内容。)

How to solve it?

您可以使用network()对象的Autoencoder方法获取network对象,然后根据需要自定义它。在您的情况下,您将新的重量分配到net.IW{1}。之后你可以trainsim等。

© www.soinside.com 2019 - 2024. All rights reserved.