Autoencoder and SVD: Matrix apllications












0















in my study, I am using the so-called Lee Carter Model (Mortality model) in which you can get the model parameters by using Singular Values Decomposition on the matrix of (log mortality rate- the average age-specific pattern of mortality).
I am trying to find a substitution of Singular Value Decomposition, I saw that a good choice could be an autoencoding applied by a Recurrent Neural network. In fact, an SVD could be converging to autoencoder in which the activation function is a linear function. At this purpose, I would try using a nonlinear activation function in order to obtain the same items obtained by SVD with a nonlinear shape.
Let's use this steps in order to obtain data: mortality rates for ages and years



rm(list = ls())

library(MortalitySmooth)

ages <- 0:100

years <- 1960:2009

D <- as.matrix(selectHMDdata("Japan", "Deaths",
"Females", ages,
years))

D[D==0] <- 1

E <- as.matrix(selectHMDdata("Japan", "Exposures",
"Females", ages,
years))

E[E==0] <- 1


lMX <- log(D/E)

alpha <- apply(lMX, 1, mean)`

cent.logMXMatrix <- sweep(lMX, 1, alpha)


Now we apply SVD on cent.logMXMatrix
when I use SVD in R I get this:



SVD <- svd(cent.logMXMatrix)


and I need to get the components of SVD:



SVD$d
SVD$v
SVD$u


I would like to get SVD component using Autoencoder...Is it possible?
I would like to get your opinion, some suggestion from you and whether is possible I need a basic python code formulation for autoencoder on the "cent.logMXMatrix"



Thank a lot,
Andrea










share|improve this question

























  • SVD is a linear algebra problem. You can use a pseudo autoencoder with just 2 linear layers to get it, of course.

    – Matthieu Brucher
    Nov 19 '18 at 10:30











  • Thanks, can you show me?

    – an.dr.ea
    Nov 20 '18 at 11:16
















0















in my study, I am using the so-called Lee Carter Model (Mortality model) in which you can get the model parameters by using Singular Values Decomposition on the matrix of (log mortality rate- the average age-specific pattern of mortality).
I am trying to find a substitution of Singular Value Decomposition, I saw that a good choice could be an autoencoding applied by a Recurrent Neural network. In fact, an SVD could be converging to autoencoder in which the activation function is a linear function. At this purpose, I would try using a nonlinear activation function in order to obtain the same items obtained by SVD with a nonlinear shape.
Let's use this steps in order to obtain data: mortality rates for ages and years



rm(list = ls())

library(MortalitySmooth)

ages <- 0:100

years <- 1960:2009

D <- as.matrix(selectHMDdata("Japan", "Deaths",
"Females", ages,
years))

D[D==0] <- 1

E <- as.matrix(selectHMDdata("Japan", "Exposures",
"Females", ages,
years))

E[E==0] <- 1


lMX <- log(D/E)

alpha <- apply(lMX, 1, mean)`

cent.logMXMatrix <- sweep(lMX, 1, alpha)


Now we apply SVD on cent.logMXMatrix
when I use SVD in R I get this:



SVD <- svd(cent.logMXMatrix)


and I need to get the components of SVD:



SVD$d
SVD$v
SVD$u


I would like to get SVD component using Autoencoder...Is it possible?
I would like to get your opinion, some suggestion from you and whether is possible I need a basic python code formulation for autoencoder on the "cent.logMXMatrix"



Thank a lot,
Andrea










share|improve this question

























  • SVD is a linear algebra problem. You can use a pseudo autoencoder with just 2 linear layers to get it, of course.

    – Matthieu Brucher
    Nov 19 '18 at 10:30











  • Thanks, can you show me?

    – an.dr.ea
    Nov 20 '18 at 11:16














0












0








0








in my study, I am using the so-called Lee Carter Model (Mortality model) in which you can get the model parameters by using Singular Values Decomposition on the matrix of (log mortality rate- the average age-specific pattern of mortality).
I am trying to find a substitution of Singular Value Decomposition, I saw that a good choice could be an autoencoding applied by a Recurrent Neural network. In fact, an SVD could be converging to autoencoder in which the activation function is a linear function. At this purpose, I would try using a nonlinear activation function in order to obtain the same items obtained by SVD with a nonlinear shape.
Let's use this steps in order to obtain data: mortality rates for ages and years



rm(list = ls())

library(MortalitySmooth)

ages <- 0:100

years <- 1960:2009

D <- as.matrix(selectHMDdata("Japan", "Deaths",
"Females", ages,
years))

D[D==0] <- 1

E <- as.matrix(selectHMDdata("Japan", "Exposures",
"Females", ages,
years))

E[E==0] <- 1


lMX <- log(D/E)

alpha <- apply(lMX, 1, mean)`

cent.logMXMatrix <- sweep(lMX, 1, alpha)


Now we apply SVD on cent.logMXMatrix
when I use SVD in R I get this:



SVD <- svd(cent.logMXMatrix)


and I need to get the components of SVD:



SVD$d
SVD$v
SVD$u


I would like to get SVD component using Autoencoder...Is it possible?
I would like to get your opinion, some suggestion from you and whether is possible I need a basic python code formulation for autoencoder on the "cent.logMXMatrix"



Thank a lot,
Andrea










share|improve this question
















in my study, I am using the so-called Lee Carter Model (Mortality model) in which you can get the model parameters by using Singular Values Decomposition on the matrix of (log mortality rate- the average age-specific pattern of mortality).
I am trying to find a substitution of Singular Value Decomposition, I saw that a good choice could be an autoencoding applied by a Recurrent Neural network. In fact, an SVD could be converging to autoencoder in which the activation function is a linear function. At this purpose, I would try using a nonlinear activation function in order to obtain the same items obtained by SVD with a nonlinear shape.
Let's use this steps in order to obtain data: mortality rates for ages and years



rm(list = ls())

library(MortalitySmooth)

ages <- 0:100

years <- 1960:2009

D <- as.matrix(selectHMDdata("Japan", "Deaths",
"Females", ages,
years))

D[D==0] <- 1

E <- as.matrix(selectHMDdata("Japan", "Exposures",
"Females", ages,
years))

E[E==0] <- 1


lMX <- log(D/E)

alpha <- apply(lMX, 1, mean)`

cent.logMXMatrix <- sweep(lMX, 1, alpha)


Now we apply SVD on cent.logMXMatrix
when I use SVD in R I get this:



SVD <- svd(cent.logMXMatrix)


and I need to get the components of SVD:



SVD$d
SVD$v
SVD$u


I would like to get SVD component using Autoencoder...Is it possible?
I would like to get your opinion, some suggestion from you and whether is possible I need a basic python code formulation for autoencoder on the "cent.logMXMatrix"



Thank a lot,
Andrea







python matrix autoencoder svd






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 12:58









Dmitriy Fialkovskiy

1,59521425




1,59521425










asked Nov 18 '18 at 12:05









an.dr.eaan.dr.ea

44




44













  • SVD is a linear algebra problem. You can use a pseudo autoencoder with just 2 linear layers to get it, of course.

    – Matthieu Brucher
    Nov 19 '18 at 10:30











  • Thanks, can you show me?

    – an.dr.ea
    Nov 20 '18 at 11:16



















  • SVD is a linear algebra problem. You can use a pseudo autoencoder with just 2 linear layers to get it, of course.

    – Matthieu Brucher
    Nov 19 '18 at 10:30











  • Thanks, can you show me?

    – an.dr.ea
    Nov 20 '18 at 11:16

















SVD is a linear algebra problem. You can use a pseudo autoencoder with just 2 linear layers to get it, of course.

– Matthieu Brucher
Nov 19 '18 at 10:30





SVD is a linear algebra problem. You can use a pseudo autoencoder with just 2 linear layers to get it, of course.

– Matthieu Brucher
Nov 19 '18 at 10:30













Thanks, can you show me?

– an.dr.ea
Nov 20 '18 at 11:16





Thanks, can you show me?

– an.dr.ea
Nov 20 '18 at 11:16












1 Answer
1






active

oldest

votes


















1














A one-layer autoencoder linearly maps a datapoint to a low-dimensional latent space, then applies a non-linear activation to project the result to the original space while minimizing a reconstruction error.

If we replace the non-linear activation by a linear one (identity) and use the L2 norm as a reconstruction error, you will be performing the same operation as an SVD.



# use keras with tensorflow backend
# This is a vanilla autoencoder with one hidden layer
from keras.layers import Input, Dense
from keras.models import Model

input_dim = Input(shape = (nfeat, )) # nfeat=the number of initial features
encoded1 = Dense(layer_size1, activation='linear')(input_dim) # layer_size1:size of your encoding layer
decoded1 = Dense(nfeat, activation='linear')
autoencoder = Model(inputs = input_dim, outputs = decoded1)
autoencoder.compile(loss='mean_squared_error', optimizer='adam')





share|improve this answer





















  • 1





    No need for more layers in a linear encoder. But thanks for showing the code for OP. Even here, you should have only 2 layers, not three. Which is why I'm not up voting.

    – Matthieu Brucher
    Nov 20 '18 at 14:37













  • @MatthieuBrucher You're right. Since we have linear activation, no need to add more layers. Sorry for this !

    – Akihiko
    Nov 20 '18 at 15:09













  • Thanks for fixing this!

    – Matthieu Brucher
    Nov 20 '18 at 15:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360675%2fautoencoder-and-svd-matrix-apllications%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














A one-layer autoencoder linearly maps a datapoint to a low-dimensional latent space, then applies a non-linear activation to project the result to the original space while minimizing a reconstruction error.

If we replace the non-linear activation by a linear one (identity) and use the L2 norm as a reconstruction error, you will be performing the same operation as an SVD.



# use keras with tensorflow backend
# This is a vanilla autoencoder with one hidden layer
from keras.layers import Input, Dense
from keras.models import Model

input_dim = Input(shape = (nfeat, )) # nfeat=the number of initial features
encoded1 = Dense(layer_size1, activation='linear')(input_dim) # layer_size1:size of your encoding layer
decoded1 = Dense(nfeat, activation='linear')
autoencoder = Model(inputs = input_dim, outputs = decoded1)
autoencoder.compile(loss='mean_squared_error', optimizer='adam')





share|improve this answer





















  • 1





    No need for more layers in a linear encoder. But thanks for showing the code for OP. Even here, you should have only 2 layers, not three. Which is why I'm not up voting.

    – Matthieu Brucher
    Nov 20 '18 at 14:37













  • @MatthieuBrucher You're right. Since we have linear activation, no need to add more layers. Sorry for this !

    – Akihiko
    Nov 20 '18 at 15:09













  • Thanks for fixing this!

    – Matthieu Brucher
    Nov 20 '18 at 15:23
















1














A one-layer autoencoder linearly maps a datapoint to a low-dimensional latent space, then applies a non-linear activation to project the result to the original space while minimizing a reconstruction error.

If we replace the non-linear activation by a linear one (identity) and use the L2 norm as a reconstruction error, you will be performing the same operation as an SVD.



# use keras with tensorflow backend
# This is a vanilla autoencoder with one hidden layer
from keras.layers import Input, Dense
from keras.models import Model

input_dim = Input(shape = (nfeat, )) # nfeat=the number of initial features
encoded1 = Dense(layer_size1, activation='linear')(input_dim) # layer_size1:size of your encoding layer
decoded1 = Dense(nfeat, activation='linear')
autoencoder = Model(inputs = input_dim, outputs = decoded1)
autoencoder.compile(loss='mean_squared_error', optimizer='adam')





share|improve this answer





















  • 1





    No need for more layers in a linear encoder. But thanks for showing the code for OP. Even here, you should have only 2 layers, not three. Which is why I'm not up voting.

    – Matthieu Brucher
    Nov 20 '18 at 14:37













  • @MatthieuBrucher You're right. Since we have linear activation, no need to add more layers. Sorry for this !

    – Akihiko
    Nov 20 '18 at 15:09













  • Thanks for fixing this!

    – Matthieu Brucher
    Nov 20 '18 at 15:23














1












1








1







A one-layer autoencoder linearly maps a datapoint to a low-dimensional latent space, then applies a non-linear activation to project the result to the original space while minimizing a reconstruction error.

If we replace the non-linear activation by a linear one (identity) and use the L2 norm as a reconstruction error, you will be performing the same operation as an SVD.



# use keras with tensorflow backend
# This is a vanilla autoencoder with one hidden layer
from keras.layers import Input, Dense
from keras.models import Model

input_dim = Input(shape = (nfeat, )) # nfeat=the number of initial features
encoded1 = Dense(layer_size1, activation='linear')(input_dim) # layer_size1:size of your encoding layer
decoded1 = Dense(nfeat, activation='linear')
autoencoder = Model(inputs = input_dim, outputs = decoded1)
autoencoder.compile(loss='mean_squared_error', optimizer='adam')





share|improve this answer















A one-layer autoencoder linearly maps a datapoint to a low-dimensional latent space, then applies a non-linear activation to project the result to the original space while minimizing a reconstruction error.

If we replace the non-linear activation by a linear one (identity) and use the L2 norm as a reconstruction error, you will be performing the same operation as an SVD.



# use keras with tensorflow backend
# This is a vanilla autoencoder with one hidden layer
from keras.layers import Input, Dense
from keras.models import Model

input_dim = Input(shape = (nfeat, )) # nfeat=the number of initial features
encoded1 = Dense(layer_size1, activation='linear')(input_dim) # layer_size1:size of your encoding layer
decoded1 = Dense(nfeat, activation='linear')
autoencoder = Model(inputs = input_dim, outputs = decoded1)
autoencoder.compile(loss='mean_squared_error', optimizer='adam')






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 15:13

























answered Nov 20 '18 at 12:46









AkihikoAkihiko

557




557








  • 1





    No need for more layers in a linear encoder. But thanks for showing the code for OP. Even here, you should have only 2 layers, not three. Which is why I'm not up voting.

    – Matthieu Brucher
    Nov 20 '18 at 14:37













  • @MatthieuBrucher You're right. Since we have linear activation, no need to add more layers. Sorry for this !

    – Akihiko
    Nov 20 '18 at 15:09













  • Thanks for fixing this!

    – Matthieu Brucher
    Nov 20 '18 at 15:23














  • 1





    No need for more layers in a linear encoder. But thanks for showing the code for OP. Even here, you should have only 2 layers, not three. Which is why I'm not up voting.

    – Matthieu Brucher
    Nov 20 '18 at 14:37













  • @MatthieuBrucher You're right. Since we have linear activation, no need to add more layers. Sorry for this !

    – Akihiko
    Nov 20 '18 at 15:09













  • Thanks for fixing this!

    – Matthieu Brucher
    Nov 20 '18 at 15:23








1




1





No need for more layers in a linear encoder. But thanks for showing the code for OP. Even here, you should have only 2 layers, not three. Which is why I'm not up voting.

– Matthieu Brucher
Nov 20 '18 at 14:37







No need for more layers in a linear encoder. But thanks for showing the code for OP. Even here, you should have only 2 layers, not three. Which is why I'm not up voting.

– Matthieu Brucher
Nov 20 '18 at 14:37















@MatthieuBrucher You're right. Since we have linear activation, no need to add more layers. Sorry for this !

– Akihiko
Nov 20 '18 at 15:09







@MatthieuBrucher You're right. Since we have linear activation, no need to add more layers. Sorry for this !

– Akihiko
Nov 20 '18 at 15:09















Thanks for fixing this!

– Matthieu Brucher
Nov 20 '18 at 15:23





Thanks for fixing this!

– Matthieu Brucher
Nov 20 '18 at 15:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360675%2fautoencoder-and-svd-matrix-apllications%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)