运行指定的函数后,我得到类类型为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.
要理解这种行为,我们应该看看Autoencoder
类(\MATLAB\R20###\toolbox\nnet\nnet\nnnetwork\Autoencoder.m
)。我们可以看到以下内容:
'EncoderWeights'
定义在properties(SetAccess = private, Dependent)
区块内。function val = get.EncoderWeights(this)
。因此,我们看到'EncoderWeights'
既不是一个可公开设置的领域,也没有一个公开的setter方法 - 所以你得到一个错误并不奇怪。顺便说一句,在R2018b上,错误可能会提供更多信息:
You cannot set the read-only property 'EncoderWeights' of Autoencoder.
(如果您不熟悉我上面使用的概念,我建议您阅读有关classes in MATLAB的内容。)
您可以使用network()
对象的Autoencoder
方法获取network
对象,然后根据需要自定义它。在您的情况下,您将新的重量分配到net.IW{1}
。之后你可以train
,sim
等。