how can I change autoencoder weights?

2 views (last 30 days)
nadia
nadia on 11 Apr 2018
Answered: Anurag Ojha on 11 Jun 2024
Hi, I train an autoencoder in matlab R2016a and I want to change some weights of encoder or decoder and flip them to zero or one, but by doing it, I saw this error"You cannot set the read-only property 'EncoderWeights' of Autoencoder.". I need to change the weights and consider the changes. how can I do it? is there any way to solve this problem? thanks.

Answers (1)

Anurag Ojha
Anurag Ojha on 11 Jun 2024
Hi Nadia
Unfortunately, you cannot directly modify the weights of an autoencoder in MATLAB. The 'EncoderWeights' property is read-only, which means you cannot change its values. However, you can train a new autoencoder with the desired weights by specifying the 'EncoderWeights' option during training.
Here's an example:
% Create and train an autoencoder
autoenc = trainAutoencoder(X, hiddenSize);
% Modify the weights
newWeights = ones(size(autoenc.EncoderWeights)); % Set all weights to 1
% Train a new autoencoder with the modified weights
newAutoenc = trainAutoencoder(X, hiddenSize, 'EncoderWeights', newWeights);
Adding MATLAB documentation, for your reference:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!