-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScaling_Hyp
61 lines (50 loc) · 1.7 KB
/
Scaling_Hyp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import numpy as np
import matplotlib.pyplot as plt
def plot_scaling_laws(equations, x_range, labels=None, title='Scaling Laws Visualization'):
"""
Plots multiple scaling laws over a specified range.
Parameters:
- equations: List of functions representing scaling laws.
- x_range: Tuple (start, end) defining the range of x-values.
- labels: List of labels for each equation (optional).
- title: Title of the plot (optional).
"""
x_values = np.linspace(x_range[0], x_range[1], 500)
plt.figure(figsize=(10, 6))
for i, eq in enumerate(equations):
y_values = eq(x_values)
label = labels[i] if labels and i < len(labels) else f'Equation {i+1}'
plt.plot(x_values, y_values, label=label)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title(title)
plt.legend()
plt.grid(True)
plt.show()
# Example scaling laws
def power_law(x, a=1, b=0.5):
"""Power law: y = a * x^b"""
return a * np.power(x, b)
def logarithmic_law(x, a=1, b=1):
"""Logarithmic law: y = a * log(x) + b"""
return a * np.log(x) + b
def exponential_law(x, a=1, b=0.1):
"""Exponential law: y = a * exp(b * x)"""
return a * np.exp(b * x)
# Define the range for x-values
x_start = 1
x_end = 100
# List of scaling law functions
scaling_functions = [
lambda x: power_law(x, a=2, b=0.5),
lambda x: logarithmic_law(x, a=1, b=2),
lambda x: exponential_law(x, a=1, b=0.05)
]
# Corresponding labels for the functions
function_labels = [
'Power Law: y = 2 * x^0.5',
'Logarithmic Law: y = log(x) + 2',
'Exponential Law: y = exp(0.05 * x)'
]
# Plot the scaling laws
plot_scaling_laws(scaling_functions, (x_start, x_end), labels=function_labels)