How can I modify the read-only outputs of an Autoencoder object?

284 views Asked by At

I get an object of class type Autoencoder after running the specified function:

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

If I try to query one of the properties, I can get it without problem,

>> autoenc1.EncoderWeights(1,1)  

ans = -0.0404  

However, if I try to set it, I get an error:

>> 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.
1

There are 1 answers

0
Dev-iL On

Why are you getting this problem?

To understand this behaviour we should take a look inside the Autoencoder class (\MATLAB\R20###\toolbox\nnet\nnet\nnnetwork\Autoencoder.m). We can see the following:

  • 'EncoderWeights' is defined inside a properties(SetAccess = private, Dependent) block.
  • A public "getter" method is defined for this property: function val = get.EncoderWeights(this).

Thus, we see that 'EncoderWeights' is neither a publicly settable field, nor is there a public setter method for it - so it's not surprising you're getting an error. BTW, on R2018b the error might be a bit more informative:

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

(If you are unfamiliar with the concepts I used above, I suggest you read about classes in MATLAB.)

How to solve it?

You can use the network() method of you Autoencoder object to get a network object, then customize it as you please. In your case you would assign the new weight(s) into net.IW{1}. Afterwards you can train, sim etc.