<commit_before>import cv2
import networkx as nx
import numpy as np

from sft import Rectangle, normalize, get_path_bbox, sample_int_normal_bounded
from sft.Scenario import Scenario
from sft.sim.PathGenerator import PathGenerator
from sft.sim.ScenarioGenerator import ScenarioGenerator
from sft.sim.Simulator import Simulator


class PathWorldGenerator(ScenarioGenerator):
	DEF_PATH_LENGTH_MIN = 3
	DEF_PATH_LENGTH_MAX = 5
	PATH_THICKNESS = 1
	PATH_COLOR = 150

	TARGET_COLOR = int(Simulator.TARGET_VALUE * 255)
	TARGET_RADIUS = 1

	def __init__(self, logger, view_size, world_size, sampler, path_length_min=-1, path_length_max=-1,
				 path_step_length_min=-1, path_step_length_max=-1, path_in_init_view=False,
				 target_not_in_init_view=False):
		self.logger = logger
		self.view_size = view_size
		self.world_size = world_size
		self.bbox = get_path_bbox(world_size, view_size)
		self.sampler = sampler
		self.path_length_min = path_length_min
		self.path_length_max = path_length_max
		self.generator = PathGenerator(self.view_size, self.bbox, path_step_length_min, path_step_length_max)
		self.path_in_init_view = path_in_init_view
		self.target_not_in_init_view = target_not_in_init_view

	def get_next(self):
		world, target_pos = self.init_world()
		view_pos = self.init_pos(world, target_pos)
		return Scenario(world, view_pos)

	def init_world(self):
		world = np.full(self.world_size.tuple(), 0., dtype=np.float32)
		graph = nx.Graph()
		self.init_path(world, graph)
		target_pos = self.init_target(world, graph)
		world = np.array(world, np.float)
		# normalize world image to [0, 1]
		normalize(world)
		return world, target_pos

	def init_path(self, world, graph):
		# only add one path for now
		# sample length for path
		self.generator.generate_path(self.sample_path_length(), graph, path_id=0)
		nodes = sorted(graph.nodes(), key=lambda n: n.id)
		self.logger.log_parameter("Generated path", [str(n.pos) for n in nodes])
		self.render_paths(world, graph)
<commit_msg>Fix float64 conversion<commit_after>import cv2
import networkx as nx
import numpy as np

from sft import Rectangle, normalize, get_path_bbox, sample_int_normal_bounded
from sft.Scenario import Scenario
from sft.sim.PathGenerator import PathGenerator
from sft.sim.ScenarioGenerator import ScenarioGenerator
from sft.sim.Simulator import Simulator


class PathWorldGenerator(ScenarioGenerator):
	DEF_PATH_LENGTH_MIN = 3
	DEF_PATH_LENGTH_MAX = 5
	PATH_THICKNESS = 1
	PATH_COLOR = 150

	TARGET_COLOR = int(Simulator.TARGET_VALUE * 255)
	TARGET_RADIUS = 1

	def __init__(self, logger, view_size, world_size, sampler, path_length_min=-1, path_length_max=-1,
				 path_step_length_min=-1, path_step_length_max=-1, path_in_init_view=False,
				 target_not_in_init_view=False):
		self.logger = logger
		self.view_size = view_size
		self.world_size = world_size
		self.bbox = get_path_bbox(world_size, view_size)
		self.sampler = sampler
		self.path_length_min = path_length_min
		self.path_length_max = path_length_max
		self.generator = PathGenerator(self.view_size, self.bbox, path_step_length_min, path_step_length_max)
		self.path_in_init_view = path_in_init_view
		self.target_not_in_init_view = target_not_in_init_view

	def get_next(self):
		world, target_pos = self.init_world()
		view_pos = self.init_pos(world, target_pos)
		return Scenario(world, view_pos)

	def init_world(self):
		world = np.full(self.world_size.tuple(), 0., dtype=np.float32)
		graph = nx.Graph()
		self.init_path(world, graph)
		target_pos = self.init_target(world, graph)
		# normalize world image to [0, 1]
		normalize(world)
		return world, target_pos

	def init_path(self, world, graph):
		# only add one path for now
		# sample length for path
		self.generator.generate_path(self.sample_path_length(), graph, path_id=0)
		nodes = sorted(graph.nodes(), key=lambda n: n.id)
		self.logger.log_parameter("Generated path", [str(n.pos) for n in nodes])
		self.render_paths(world, graph)

{'fraction_non_alphanumeric': 0.08973384030418251, 'fraction_numerical': 0.011153358681875792, 'mean_word_length': 5.500823723228995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '1051950', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1383, 'n_words': 303}