<jupyter_start><jupyter_text>Let's generate the combinations:<jupyter_code>def combos(combo_min, combo_max, combo_len):
    for combo in it.product(xrange(combo_min, combo_max + 1),
                            repeat=combo_len):
        yield combo
        
def combo_dicts(param_names, combo_min, combo_max, combo_len):
    for d in (OrderedDict(it.izip(param1_names, combo)) for combo in combos(combo_min, combo_max, combo_len)):
        yield d<jupyter_output><empty_output><jupyter_text>We have 5 coefficients. If we make the maximum ratio a 10:1 ratio, and use integer steps, that's 100,000 tests we need to do. 200,000 if we consider that centrality and centrality2 are mutually exclusive. Can we reduce them by taking equivalent ratios? (e.g., [1, 2, 3, 4, 5] and [2, 4, 6, 8, 10] are equivalent.)<jupyter_code>def reduction_percentage(max_ratio, n_slots=5):
    all_combos = list(combos(1, max_ratio, n_slots))
    return 100*(len(all_combos) - len(set(tuple(np.array(i) / max(i)) for i in all_combos))) / len(all_combos)
response = raw_input("This cell takes about 4 minutes to run. Press 'y' to continue: ").lower()
if response == "y":
    x = np.arange(1, 25)
    y = [reduction_percentage(i) for i in tqdm.tqdm_notebook(x)]
if response == "y":
    plt.plot(x, y)
    plt.title("Maximum iteration reduction")
    plt.ylabel("Reduction (%)")
    plt.xlabel("Maximum ratio")<jupyter_output><empty_output><jupyter_text>Well, that's not very efficient. As the ratio increases, the computation takes an exponentially longer time. Checking up to 24:1 takes us almost 4 minutes, with almost 55 seconds needed for the last iteration. Even early on, the best improvement was about 3.5%, and that stayed consistent. It's not worth keeping the entire list in memory just for this tiny gain.<jupyter_code>combo_min = 1
combo_max = 10
combo_len = 5
param1_names = ["centrality", "direction", "distance", "direction_with_current", "distance_with_current"]
param2_names = ["centrality2", "direction", "distance", "direction_with_current", "distance_with_current"]
params1 = combo_dicts(param1_names, combo_min, combo_max, combo_len)
params2 = combo_dicts(param2_names, combo_min, combo_max, combo_len)
combo = next(params1)
import rospy
rospy.init_node("selector", log_level=rospy.INFO)
rospy.set_param("~ref_distance", 1.5)
rospy.set_param("~image_queue_length", 60)
rospy.set_param("~eval_method", "Spirit")
rospy.set_param("~thresh_distance", 0.01)
rospy.set_param("~thresh_yaw", 0.02)
from ..src.ros.spirit.src.past_image_selector import Selector
from ..src.ros.spirit.src.evaluators import Spirit

my_selector = Selector(debug=True)
spirit = Spirit(my_selector)
p = Pose.from_components([0, 1, 2], [3, 4, 5, 6])
f = Frame(Pose.generate_stamped([0, 1, 3], [3, 4, 5, 6]), 1)
# Create first frame
my_selector.tracked = True
my_selector.pose_callback(p.pose_stamped)
my_selector.image_callback(1)

# Select current frame
my_selector.pose_callback(p.pose_stamped)

# Update current frame
my_selector.pose_callback(p.pose_stamped)
my_selector.frames
spirit.select_best_frame()
spirit._evaluate_frame(p, f)
sum(coeff * getattr(spirit, fn)(p, f) for fn, coeff in combo.iteritems())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12047440699126093, 'fraction_numerical': 0.026529338327091135, 'mean_word_length': 5.567622950819672, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '507042', 'license': 'MIT', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1109, 'n_words': 302, 'path': 'notebooks/01_parameter-selection.ipynb', 'repo_name': 'masasin/spirit', 'size': '3204'}