• deeplog中输出某个 event 的概率


    1 实现之后效果

    # import DeepLog and Preprocessor
    import numpy as np
    from deeplog import DeepLog
    import torch
    
    # Create DeepLog object
    deeplog = DeepLog(
        input_size  = 10, # Number of different events to expect
        hidden_size = 64 , # Hidden dimension, we suggest 64
        output_size = 10, # Number of different events to expect
    )
    
    # X数据维度 30×10
    X = torch.randint(1,8, size=(30, 10))
    # 标签
    Y = np.random.randint(1,8, size=30)
    # 输出每个标签的概率
    result = deeplog.predict_prob(
        X = X,
        y = Y)
    
    print(result.shape)
    print(result)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    输出结果:
    在这里插入图片描述

    2 实现步骤

    step1 找到安装包位置,并打开文件
    在这里插入图片描述

    step2 DeepLog 类中添加如下函数

    class DeepLog(Module):
    	......
    	......
    	......
    	def predict_prob(self, X, y, k=1, variable=False, verbose=True):
    	"""Predict the k most likely output values
    	
    	   Parameters
    	   ----------
    	   X : torch.Tensor of shape=(n_samples, seq_len)
    	       Input of sequences, these will be one-hot encoded to an array of
    	       shape=(n_samples, seq_len, input_size)
    	
    	   y : Ignored
    	       Ignored
    	
    	   k : int, default=1
    	       Number of output items to generate
    	
    	   variable : boolean, default=False
    	       If True, predict inputs of different sequence lengths
    	
    	   verbose : boolean, default=True
    	       If True, print output
    	
    	   Returns
    	   -------
    	   result : torch.Tensor of shape=(n_samples, k)
    	       k most likely outputs
    	
    	   confidence : torch.Tensor of shape=(n_samples, k)
    	       Confidence levels for each output
    	   """
    	# Get the predictions
    	result = super().predict(X, variable=variable, verbose=verbose)
    	# Get the probabilities from the log probabilities
    	result = result.exp()
    	# return a given key's prob
    	index_c = y
    	index_r = torch.arange(y.shape[0])
    	return result[index_r, index_c]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
  • 相关阅读:
    宝藏又小众的覆盖物PBR多通道贴图素材网站分享
    [C++随笔录] stack && queue模拟实现
    嵌入式开发:选择嵌入式GUI生成器时要注意什么
    Linux基本指令(二)
    学习开发一个RISC-V上的操作系统(汪辰老师) — 环境配置
    给小白的 PostgreSQL 容器化部署教程(上)
    4、React组件三大核心属性
    关于linux与android传输代码tcp -传文件
    HTML和CSS
    人工智能学习:CIFAR-10数据分类识别
  • 原文地址:https://blog.csdn.net/weixin_40994552/article/details/134314411