def plot(m_bounds, h_bounds): m_min, m_max = m_bounds h_min, h_max = h_bounds max_hits = np.array(range(m_min, m_max+1)) healths = np.array(range(h_min, h_max+1)) Ms, Hs = np.meshgrid(max_hits, healths) fig, ax = config.get_figure(50, 18, scale=5 if showing else 10) plt.xlabel("$h_0$", fontsize=25, labelpad=20) plt.ylabel("$M$", fontsize=25, labelpad=20) ax.set_zlabel("Turns to kill", fontsize=25, rotation=90, labelpad=20) ax.tick_params(axis='z', labelsize=18) ax.tick_params(axis='y', labelsize=18) ax.tick_params(axis='x', labelsize=18) A = np.vectorize(lambda m, h: MarkovChain().turns_to_kill(m, h))(Hs, Ms) surf = ax.plot_surface(Hs, Ms, A, cmap=cm.hot) A = np.vectorize(lambda m, h: Crude().turns_to_kill(m, h))(Hs, Ms) surf = ax.plot_surface(Hs, Ms, A, cmap=cm.cool) return plt
import osrsmath.combat.damage as damage from matplotlib import cm import matplotlib.pyplot as plt import osrsmath.config as config import numpy as np import sys import os if __name__ == '__main__': showing = len(sys.argv) >= 2 and sys.argv[1] == 'show' fig, ax = config.get_figure(-124, 23, scale=5 if showing else 10) plt.xlabel("$M$", fontsize=15) plt.ylabel("$h$", fontsize=15) ax.set_zlabel("Average Damage", fontsize=15, rotation=90) h, M = 100, 100 y, x = np.meshgrid(range(h), range(M)) z = np.vectorize(damage.average)(y, x) surf = ax.plot_surface(x, y, z, cmap=cm.coolwarm) xs = range(min(h, M)) ax.plot(xs, xs, [damage.average(x, x) for x in xs], linewidth=2, c='black', zorder=3) if showing: plt.show() else: file_name = "average_damage"
[err(inverse(h, m), sim[str(h)][str(m)]) for m in max_hits]) for h in healths ]) surf = ax.plot_wireframe(Ms, Hs, Z, color=colors[label], linewidth=1, label=f"{label}") return {label: (np.average(Z), np.std(Z), np.max(Z), np.min(Z))} for method in Model.__subclasses__(): if method.__name__ == 'Simulation': continue fig, ax = config.get_figure(33, 36, scale=3 if showing else 10) plot_error(method.__name__, lambda h, m: method().turns_to_kill(h, m)) ax.tick_params(axis='z', labelsize=12) ax.tick_params(axis='y', labelsize=12) ax.tick_params(axis='x', labelsize=12) ax.set_zlabel("Percent Error", fontsize=16, labelpad=20) plt.xlabel("Max Hit", fontsize=16, labelpad=20) plt.ylabel("Initial Health", fontsize=16, labelpad=20) if showing: plt.show() else: from pathlib import Path file_name = str(Path(__file__).parent / method.__name__) plt.savefig(f"{file_name}.png")
from matplotlib import cm import matplotlib.pyplot as plt import osrsmath.config as config import numpy as np import sys import os if __name__ == '__main__': showing = len(sys.argv) >= 2 and sys.argv[1] == 'show' a = range(1000) d = range(1000) a, d = np.meshgrid(a, d) A = np.vectorize(accuracy)(a, d) fig, ax = config.get_figure(-168, 25, scale=5 if showing else 10) plt.xlabel("$A_{max}$", fontsize=15) plt.ylabel("$D_{max}$", fontsize=15) ax.set_zlabel("Accuracy", fontsize=15, rotation=90) surf = ax.plot_surface(a, d, A, cmap=cm.coolwarm) ax.plot([1000], [1000], [1.01]) ax.plot(range(1000), range(1000), [accuracy(x, x) for x in range(1000)], linewidth=2, c='black', zorder=3) if showing: plt.show() else:
from osrsmath.results.part_II.colors import colors from osrsmath.combat.successful_hits import * from osrsmath.results.part_II.generate_simulation import load_dataset from pprint import pprint from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np import sys import os import osrsmath.config as config if __name__ == '__main__': showing = len(sys.argv) >= 2 and sys.argv[1] == 'show' fig, ax = config.get_figure(38, 17, scale=3 if showing else 10) m_min, m_max = (1, 110) h_min, h_max = (1, 255) max_hits = np.array(range(m_min, m_max+1)) healths = np.array(range(h_min, h_max+1)) Ms, Hs = np.meshgrid(max_hits, healths) sim = load_dataset(N=100_000) def plot_error(label, inverse): """ inverse: hinv(h, m) """ def err(a, b): # return abs(a - b) return abs(1 - a /b)*100 print(label) Z = np.array([np.array([err(inverse(h, m), sim[str(h)][str(m)]) for m in max_hits]) for h in healths]) surf = ax.plot_wireframe(Ms, Hs, Z, color=colors[label], linewidth=2.3, label=f"{label}") return {label: (np.average(Z), np.std(Z), np.max(Z), np.min(Z))}