17.6.3 Advanced Hyperparameter Customization
This is implemented using the sub-config classes,
GraphWiseConvLayerConfig
and
GraphWiseEmbeddingConfig
.
Also, you can enable or disable a graphics processing unit (GPU) by
using the enable_ml_accelerators
graph server (PGX)
configuration parameter (see Configuration Parameters for the Graph Server (PGX) Engine for more information). In addition, ensure that your system meets the
following prerequisites to use the GPU support:
- You must have a GPU device with the CUDA (Compute Unified Device Architecture) toolkit installed.
- The following list of CUDA libraries are expected:
libcuda.so.1
libnvrtc.so.12
libnvToolsExt.so.1
libcudart.so.12
Note that the enable_ml_accelerators
option is
enabled by default. But if a GPU device is not detected and the CUDA toolkit is
not installed, then this feature gets disabled and the CPU will be used for all
the PgxML library operations.
The following example specifies a weight decay parameter of
0.001
and dropout with dropping probability
0.5
for the model to counteract overfitting. The Dominant
embedding layer's alpha value is specified as 0.6 to slightly increase the
importance of the feature reconstruction. Also, note that the
setEnableAccelerator
method is enabled to use any available
GPU.
opg4j> var weightProperty = analyst.pagerank(trainGraph).getName()
opg4j> var convLayerConfig = analyst.graphWiseConvLayerConfigBuilder(). // customize convolutional layer config
setNumSampledNeighbors(25).
setActivationFunction(ActivationFunction.TANH).
setWeightInitScheme(WeightInitScheme.XAVIER).
setWeightedAggregationProperty(weightProperty).
setDropoutRate(0.5). // set dropout rate to prevent overfitting
build()
opg4j> var predictionLayerConfig = analyst.graphWisePredictionLayerConfigBuilder().
setHiddenDimension(8).
setActivationFunction(ActivationFunction.RELU).
build()
opg4j> var dominantConfig = analyst.graphWiseDominantLayerConfigBuilder(). // customize embedding layer config
setDecoderLayerConfigs(predictionLayerConfig).
setAlpha(0.6). // increase the importance of feature reconstruction
build()
opg4j> var model = analyst.unsupervisedAnomalyDetectionGraphWiseModelBuilder().
setVertexInputPropertyNames("vertex_features").
setConvLayerConfigs(convLayerConfig).
setEmbeddingConfig(dominantConfig).
setWeightDecay(0.001). // set weight decay to prevent overfitting
setEmbeddingDim(256).
setLearningRate(0.05).
setNumEpochs(30).
setSeed(42).
setShuffle(false).
setStandardize(true).
setBatchSize(64).
setEnableAccelerator(true). // Enable or disable GPU
build()
// customize convolutional layer config
String weightProperty = analyst.pagerank(trainGraph).getName()
GraphWiseConvLayerConfig convLayerConfig = analyst.graphWiseConvLayerConfigBuilder()
.setNumSampledNeighbors(25)
.setActivationFunction(ActivationFunction.TANH)
.setWeightInitScheme(WeightInitScheme.XAVIER)
.setWeightedAggregationProperty(weightProperty)
.setDropoutRate(0.5) // set dropout rate to prevent overfitting
.build();
GraphWisePredictionLayerConfig predictionLayerConfig = analyst.graphWisePredictionLayerConfigBuilder()
.setHiddenDimension(8)
.setActivationFunction(ActivationFunction.RELU)
.build();
// customize embedding layer config
GraphWiseEmbeddingConfig dominantConfig = analyst.graphWiseDominantLayerConfigBuilder()
.setDecoderLayerConfigs(predictionLayerConfig)
.setAlpha(0.6) // increase the importance of feature reconstruction
.build();
// build the anomaly detection model
UnsupervisedAnomalyDetectionGraphWiseModel model = analyst.unsupervisedAnomalyDetectionGraphWiseModelBuilder()
.setVertexInputPropertyNames("vertex_features")
.setEmbeddingConfig(dominantConfig)
.setConvLayerConfigs(convLayerConfig)
.setWeightDecay(0.001) // set weight decay to prevent overfitting
.setEmbeddingDim(256)
.setLearningRate(0.05)
.setNumEpochs(30)
.setSeed(42)
.setShuffle(false)
.setStandardize(true)
.setBatchSize(64)
.setEnableAccelerator(true) // Enable or disable GPU
.build();
# customize convolutional layer config
weightProperty = analyst.pagerank(train_graph).name
conv_layer_config = dict(num_sampled_neighbors=25,
activation_fn='tanh',
weight_init_scheme='xavier',
neighbor_weight_property_name=weightProperty,
dropout_rate=0.5) # set dropout rate to prevent overfitting
conv_layer = analyst.graphwise_conv_layer_config(**conv_layer_config)
# customize embedding layer config
dominant_config = dict(alpha=0.6) # increase the importance of feature reconstruction
dominant_layer = analyst.graphwise_dominant_layer_config(**dominant_config)
# build the anomaly detection model
params = dict(conv_layer_config=[conv_layer],
embedding_config=dominant_layer,
vertex_input_property_names=["vertex_features"],
weight_decay=0.001, # set weight decay to prevent overfitting
layer_size=256,
learning_rate=0.05,
num_epochs=30,
seed=42,
standardize=true,
batch_size=64,
enable_accelerator=True # Enable or disable GPU
)
model = analyst.unsupervised_anomaly_detection_graphwise_builder(**params)