DeepEmbeddedClusteringModel: Deep embedded clustering (DEC) model class

DeepEmbeddedClusteringModelR Documentation

Deep embedded clustering (DEC) model class

Description

Deep embedded clustering (DEC) model class

Arguments

numberOfUnitsPerLayer

array describing the auteoencoder.

numberOfClusters

number of clusters.

alpha

parameter

initializer

initializer for autoencoder

Details

$initialize instantiates a new class.

$pretrain

$loadWeights

$extractFeatures

$predictClusterLabels

$targetDistribution

$compile

$fit

Author(s)

Tustison NJ

Examples

## Not run: 

library( keras )
library( ANTsRNet )

fmnist <- dataset_fashion_mnist()

numberOfTrainingData <- length( fmnist$train$y )
numberOfTestingData <- length( fmnist$test$y )

numberOfPixels <- prod( dim( fmnist$test$x[1,,] ) )

fmnist$train$xreshaped <- array_reshape( fmnist$train$x,
  dim = c( numberOfTrainingData, numberOfPixels ), order = "C" )
fmnist$test$xreshaped <- array_reshape( fmnist$train$x,
  dim = c( numberOfTrainingData, numberOfPixels ), order = "C" )

x <- rbind( fmnist$test$xreshaped, fmnist$train$xreshaped ) / 255
y <- c( fmnist$test$y, fmnist$train$y )

numberOfClusters <- length( unique( fmnist$train$y ) )

initializer <- initializer_variance_scaling(
  scale = 1/3, mode = 'fan_in', distribution = 'uniform' )
pretrainOptimizer <- optimizer_sgd( lr = 1.0, momentum = 0.9 )

decModel <- DeepEmbeddedClusteringModel$new(
   numberOfUnitsPerLayer = c( numberOfPixels, 500, 500, 2000, 10 ),
   numberOfClusters = numberOfClusters, initializer = initializer )

modelWeightsFile <- "decAutoencoderModelWeights.h5"
if( ! file.exists( modelWeightsFile ) )
  {
  decModel$pretrain( x = x, optimizer = optimizer_sgd( lr = 1.0, momentum = 0.9 ),
    epochs = 300L, batchSize = 256L )
  save_model_weights_hdf5( decModel$autoencoder, modelWeightsFile )
  } else {
  load_model_weights_hdf5( decModel$autoencoder, modelWeightsFile )
  }

decModel$compile( optimizer = optimizer_sgd( lr = 1.0, momentum = 0.9 ), loss = 'kld' )

yPredicted <- decModel$fit( x, maxNumberOfIterations = 2e4, batchSize = 256,
  tolerance = 1e-3, updateInterval = 10 )

## End(Not run)


ANTsX/ANTsRNet documentation built on Nov. 21, 2024, 4:07 a.m.