17.6.3 高度なハイパーパラメータ・カスタマイズ

豊富なハイパーパラメータ・カスタマイズを使用して、Unsupervised Anomaly Detection GraphWiseモデルを作成できます。

これは、サブ構成クラスGraphWiseConvLayerConfigおよびGraphWiseEmbeddingConfigを使用して実装されます。

また、enable_ml_acceleratorsグラフ・サーバー(PGX)構成パラメータを使用して、グラフィック処理ユニット(GPU)を有効または無効にできます(詳細は、「グラフ・サーバー(PGX)エンジンの構成パラメータ」を参照)。また、GPUサポートを使用するために、システムが次の前提条件を満たしていることを確認してください:

  • CUDA (Compute Unified Device Architecture)ツールキットがインストールされているGPUデバイスが必要です。
  • 次のCUDAライブラリのリストが必要です:
    • libcuda.so.1
    • libnvrtc.so.12
    • libnvToolsExt.so.1
    • libcudart.so.12

enable_ml_acceleratorsオプションはデフォルトで有効になっています。ただし、GPUデバイスが検出されず、CUDAツールキットがインストールされていない場合、この機能は無効になり、CPUはすべてのPgxMLライブラリ操作に使用されます。

次の例では、過剰適合に対抗するために、モデルに対して重み減衰パラメータ0.001およびドロップ確率0.5のドロップアウトを指定しています。Dominant埋込み層のアルファ値は0.6と指定され、フィーチャ再構築の重要性が若干向上します。また、setEnableAcceleratorメソッドが、使用可能な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)