代码拉取完成,页面将自动刷新
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# 设置matplotlib支持中文的字体,这里使用SimHei字体
plt.rcParams['font.sans-serif'] = ['SimHei'] # 指定默认字体
plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
# Assuming an 8x8 grid representing the graphical password pad
grid_size = 8
np.random.seed(0)
# Generate a frequency matrix where the probabilities are influenced by the elements in the image
# Let's say trees are more likely to be chosen, and houses are less likely
# For simplicity, we'll assign higher probabilities to the "tree" locations and lower to "house" locations
# Randomly generated for demonstration; in a real scenario, this would be based on user data
# Example positions based on the image pattern
tree_positions = [(1, 0), (1, 3), (1, 5), (2, 2), (3, 6), (4, 1), (4, 4), (5, 0), (5, 3), (6, 5)]
house_positions = [(0, 1), (0, 4), (2, 1), (2, 4), (2, 6), (3, 0), (3, 3), (4, 7), (6, 2), (7, 3)]
# Initialize a matrix with small base probabilities
probability_matrix = np.random.rand(grid_size, grid_size)
# Ensuring the probabilities are within the range 0 to 0.99
# probability_matrix *= 0.99
# Assign higher probabilities to trees and lower to houses
tree_probability_multiplier = 0.9
house_probability_multiplier = 0.4
for position in tree_positions:
probability_matrix[position] *= tree_probability_multiplier
for position in house_positions:
probability_matrix[position] *= house_probability_multiplier
# Fixed unselectable points have a probability of 0
fixed_unselectable_points = [(0, 0), (7, 0), (0, 7), (7, 7), (3, 3), (3, 4), (4, 3), (4, 4)]
for point in fixed_unselectable_points:
probability_matrix[point] = 0
# Normalize the probabilities to ensure they sum to 1
# probability_matrix /= np.sum(probability_matrix)
# Create the heatmap
plt.figure(figsize=(10, 8))
sns.heatmap(probability_matrix, annot=True, fmt=".2f", cmap="YlGnBu", square=True)
plt.title('RUGP:4-Gram模型概率的热图表示')
plt.xlabel('Grid Points (X 轴)')
plt.ylabel('Grid Points (Y 轴)')
plt.tight_layout()
plt.show()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。