<commit_before>import numpy as np
import warnings
warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)


class Kalman:
    def __init__(self, type, ncameras=4, observation=None):

        dt = 0.05
        self.type = type

        if self.type == 'friend':
            # Transition model
            self.F = np.array([[1, 0, dt,  0, 0, 0], # Position x
                               [0, 1,  0, dt, 0, 0], # Position y
                               [0, 0,  1,  0, 0, 0], # Speed x
                               [0, 0,  0,  1, 0, 0], # Speed y
                               [0, 0,  0,  0, 1, dt], # Orientation
                               [0, 0,  0,  0, 0, 1]]) # Speed w
            # Control input model
            self.B = np.array([[0, 0, 0],
                               [0, 0, 0],
                               [0, 0, 0], # Speed x
                               [0, 0, 0], # Speed y
                               [0, 0, 0],
                               [0, 0, 0]]) # Speed w
            # Observation model
            self.H = [[1, 0, 0, 0, 0, 0] for i in range(ncameras)] # Position x
            self.H += [[0, 1, 0, 0, 0, 0] for i in range(ncameras)] # Position y
            self.H += [[0, 0, 0, 0, 1, 0] for i in range(ncameras)] # Orientation
            self.H = np.array(self.H)
            # Process covariance
            values = np.array([10 ** (0), 10 ** (0), 10 ** (1), 10 ** (1), 10 ** (-2), 10 ** (0)])
            self.Q = np.diag(values)
            # Observation covariance
            values = [10 ** (0), 10 ** (0), 10 ** (-2)]
            for i in range(ncameras-1):
                values += values
            self.R = np.diag(values)  # Pose * ncameras
            # Initial state covariance
            self.P = 10 ** (3) * np.eye(6)

            self.x = np.array([9999, 9999, 9999, 9999, 9999, 9999])
            i = 0
            if observation is not None:
                for obs in observation:
                    if obs is not None:
                        self.x += [obs.x, obs.y, 0, 0, obs.orientation, 0]
                        i += 1
                if i > 0:
                    self.x = self.x / i
                else:
                    self.x = self.x

        elif self.type == 'enemi':
            # Transition model
            self.F = np.array([[1, 0, dt, 0, 0, 0],  # Position x
                               [0, 1, 0, dt, 0, 0],  # Position y
                               [0, 0, 1, 0, 0, 0],  # Speed x
                               [0, 0, 0, 1, 0, 0],  # Speed y
                               [0, 0, 0, 0, 1, dt],  # Orientation
                               [0, 0, 0, 0, 0, 1]])  # Speed w
            # Observation model
            self.H = [[1, 0, 0, 0, 0, 0] for i in range(ncameras)]  # Position x
            self.H += [[0, 1, 0, 0, 0, 0] for i in range(ncameras)]  # Position y
            self.H += [[0, 0, 0, 0, 1, 0] for i in range(ncameras)]  # Orientation
            self.H = np.array(self.H)
            # Process covariance
            values = np.array([10 ** (0), 10 ** (0), 10 ** (0), 10 ** (0), 10 ** (2),  10 ** (-1)])
            self.Q = np.diag(values)
            # Observation covariance
            values = [10 ** (0), 10 ** (0), 10 ** (-3)]
            for i in range(ncameras - 1):
                values += values
            self.R = np.diag(values)  # Pose * ncameras
            # Initial state covariance
            self.P = 10 ** (3) * np.eye(6)

            self.x = np.array([9999, 9999, 9999, 9999, 9999, 9999])
            i = 0
            if observation is not None:
                for obs in observation:
                    if obs is not None:
                        self.x += [obs.x, obs.y, 0, 0, obs.orientation, 0]
                        i += 1
                if i > 0:
                    self.x = self.x/i
                else:
                    self.x = self.x

        elif self.type == 'ball':
            # Transition model
            self.F = np.array([[1, 0, dt, 0],  # Position x
                               [0, 1, 0, dt],  # Position y
                               [0, 0, 1, 0],  # Speed x
                               [0, 0, 0, 1]])  # Speed y
            # Observation model
            self.H = [[1, 0, 0, 0] for i in range(ncameras)]  # Position x
            self.H += [[0, 1, 0, 0] for i in range(ncameras)]  # Position y
            self.H = np.array(self.H)
            # Process covariance
            values = np.array([10 ** (0), 10 ** (0), 10 ** (0), 10 ** (0)])
            self.Q = np.diag(values)
            # Observation covariance
            values = [10 ** (0), 10 ** (0)]
            for i in range(ncameras - 1):
                values += values
            self.R = np.diag(values)  # Pose * ncameras<commit_msg>Initialisation Kalman<commit_after>import numpy as np
import warnings
warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)


class Kalman:
    def __init__(self, type, ncameras=4, observation=None):

        dt = 0.05
        self.type = type

        if self.type == 'friend':
            # Transition model
            self.F = np.array([[1, 0, dt,  0, 0, 0], # Position x
                               [0, 1,  0, dt, 0, 0], # Position y
                               [0, 0,  1,  0, 0, 0], # Speed x
                               [0, 0,  0,  1, 0, 0], # Speed y
                               [0, 0,  0,  0, 1, dt], # Orientation
                               [0, 0,  0,  0, 0, 1]]) # Speed w
            # Control input model
            self.B = np.array([[0, 0, 0],
                               [0, 0, 0],
                               [0, 0, 0], # Speed x
                               [0, 0, 0], # Speed y
                               [0, 0, 0],
                               [0, 0, 0]]) # Speed w
            # Observation model
            self.H = [[1, 0, 0, 0, 0, 0] for i in range(ncameras)] # Position x
            self.H += [[0, 1, 0, 0, 0, 0] for i in range(ncameras)] # Position y
            self.H += [[0, 0, 0, 0, 1, 0] for i in range(ncameras)] # Orientation
            self.H = np.array(self.H)
            # Process covariance
            values = np.array([10 ** (0), 10 ** (0), 10 ** (1), 10 ** (1), 10 ** (-2), 10 ** (0)])
            self.Q = np.diag(values)
            # Observation covariance
            values = [10 ** (0), 10 ** (0), 10 ** (-2)]
            for i in range(ncameras-1):
                values += values
            self.R = np.diag(values)  # Pose * ncameras
            # Initial state covariance
            self.P = 10 ** (3) * np.eye(6)

            self.x = np.array([9999, 9999, 0, 0, 0, 0])
            i = 0
            if observation is not None:
                for obs in observation:
                    if obs is not None:
                        self.x += [obs.x, obs.y, 0, 0, obs.orientation, 0]
                        i += 1
                if i > 0:
                    self.x = self.x / i
                else:
                    self.x = self.x

        elif self.type == 'enemi':
            # Transition model
            self.F = np.array([[1, 0, dt, 0, 0, 0],  # Position x
                               [0, 1, 0, dt, 0, 0],  # Position y
                               [0, 0, 1, 0, 0, 0],  # Speed x
                               [0, 0, 0, 1, 0, 0],  # Speed y
                               [0, 0, 0, 0, 1, dt],  # Orientation
                               [0, 0, 0, 0, 0, 1]])  # Speed w
            # Observation model
            self.H = [[1, 0, 0, 0, 0, 0] for i in range(ncameras)]  # Position x
            self.H += [[0, 1, 0, 0, 0, 0] for i in range(ncameras)]  # Position y
            self.H += [[0, 0, 0, 0, 1, 0] for i in range(ncameras)]  # Orientation
            self.H = np.array(self.H)
            # Process covariance
            values = np.array([10 ** (0), 10 ** (0), 10 ** (0), 10 ** (0), 10 ** (2),  10 ** (-1)])
            self.Q = np.diag(values)
            # Observation covariance
            values = [10 ** (0), 10 ** (0), 10 ** (-3)]
            for i in range(ncameras - 1):
                values += values
            self.R = np.diag(values)  # Pose * ncameras
            # Initial state covariance
            self.P = 10 ** (3) * np.eye(6)

            self.x = np.array([9999, 9999, 0, 0, 0, 0])
            i = 0
            if observation is not None:
                for obs in observation:
                    if obs is not None:
                        self.x += [obs.x, obs.y, 0, 0, obs.orientation, 0]
                        i += 1
                if i > 0:
                    self.x = self.x/i
                else:
                    self.x = self.x

        elif self.type == 'ball':
            # Transition model
            self.F = np.array([[1, 0, dt, 0],  # Position x
                               [0, 1, 0, dt],  # Position y
                               [0, 0, 1, 0],  # Speed x
                               [0, 0, 0, 1]])  # Speed y
            # Observation model
            self.H = [[1, 0, 0, 0] for i in range(ncameras)]  # Position x
            self.H += [[0, 1, 0, 0] for i in range(ncameras)]  # Position y
            self.H = np.array(self.H)
            # Process covariance
            values = np.array([10 ** (0), 10 ** (0), 10 ** (0), 10 ** (0)])
            self.Q = np.diag(values)
            # Observation covariance
            values = [10 ** (0), 10 ** (0)]
            for i in range(ncameras - 1):
                values += values
            self.R = np.diag(values)  # Pose * ncameras
{'fraction_non_alphanumeric': 0.14208333333333334, 'fraction_numerical': 0.057708333333333334, 'mean_word_length': 1.0541292255027814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '892396', 'n_tokens_mistral': 3418, 'n_tokens_neox': 2929, 'n_words': 984}