Skip to content

Instantly share code, notes, and snippets.

@Yasir-siddiqui
Created February 2, 2020 17:43
Show Gist options
  • Save Yasir-siddiqui/6700377947afb921c77022f7738c8484 to your computer and use it in GitHub Desktop.
Save Yasir-siddiqui/6700377947afb921c77022f7738c8484 to your computer and use it in GitHub Desktop.
EAS cluster cost interpolator
#!/usr/bin/python
# Tyler Nijmeh <tylernij@gmail.com>
from scipy import interpolate
# P.S.: The default target values are from sdm660
# P.S.: The default source values are from NICOBAR/trinket
# Target frequencies
target_cluster0_freqs = [300000, 633600, 902400, 1113600, 1401600, 1536000, 1612800, 1747200]
target_cluster1_freqs = [300000, 1113600, 1401600, 1747200]
# Source frequencies
src_cluster0_freqs = [300000, 614400, 864000, 1017600, 1305600, 1420800, 1612800, 1804800]
src_cluster1_freqs = [300000, 652800, 902400, 1056000, 1401600, 1536000, 1804800, 2016000]
# Source costs
src_core0_costs = [12, 22, 39, 54, 83, 102, 130, 172]
src_core1_costs = [211, 417, 722, 991, 1577, 1932, 2579, 3391]
src_cluster0_costs = [5, 8, 9, 12, 18, 21, 27, 36]
src_cluster1_costs = [38, 46, 52, 68, 88, 100, 108, 120]
# Interpolate
def interp(src_freqs, src_costs, target_freqs):
# Interpolated values
interp_target_freqs = []
interp_src_freqs = []
interp_src_costs = []
# Extrapolated values
extrap_target_freqs = []
# Sort freqs and costs into either interp or extrap
max_src_freq = src_freqs[len(src_freqs)-1]
for idx in range(0, len(target_freqs)):
if target_freqs[idx] <= max_src_freq:
interp_target_freqs.append(target_freqs[idx])
interp_src_freqs.append(src_freqs[idx])
interp_src_costs.append(src_costs[idx])
else:
extrap_target_freqs.append(target_freqs[idx])
# Use more accurate cubic spline interpolation when target <= source freqs
c_f = interpolate.interp1d(src_freqs, src_costs, kind='cubic')
for freq in interp_target_freqs:
print('%d %.0f' % (freq, c_f(freq)))
# Use linear spline interpolation if we can't accurately extrapolate the cubic spline
l_f = interpolate.interp1d(src_freqs, src_costs, kind='slinear', fill_value='extrapolate')
for freq in extrap_target_freqs:
print('%d %.0f' % (freq, l_f(freq)))
# Newline
print("")
# Interpolate for core0, core1, cluster0, cluster1
print("Energy Model Interpolation Script")
print("By Tyler Nijmeh <tylernij@gmail.com>")
print("")
print("--- CORE0 ---")
interp(src_cluster0_freqs, src_core0_costs, target_cluster0_freqs)
print("--- CORE1 ---")
interp(src_cluster1_freqs, src_core1_costs, target_cluster1_freqs)
print("--- CLUSTER0 ---")
interp(src_cluster0_freqs, src_cluster0_costs, target_cluster0_freqs)
print("--- CLUSTER1 ---")
interp(src_cluster1_freqs, src_cluster1_costs, target_cluster1_freqs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment