Passed
Push — master ( 7ebd63...8bd9a3 )
by Simon
06:11
created

gradient_free_optimizers.optimizers.global_opt.powells_method.direction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Direction.get_new_position() 0 17 2
A Direction.__init__() 0 9 1
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
class Direction:
7
    def __init__(self, position_1, position_2) -> None:
8
        """
9
        Parameters:
10
        - position_1: dict, starting point in the search-space
11
        - position_2: dict, end point in the search-space
12
        """
13
14
        self.position_1 = position_1
15
        self.position_2 = position_2
16
17
    def get_new_position(self, t):
18
        """
19
        Calculate a position on the line (vector) between two positions using parameter t.
20
21
        Parameters:
22
        - t: float, parameter indicating the position along the line (0 <= t <= 1 for within the line segment)
23
24
        Returns:
25
        - dict representing the new position in the search-space coordinate system
26
        """
27
        new_position = {}
28
        for dim in self.position_1:
29
            # Calculate the position along the line in each dimension
30
            new_position[dim] = self.position_1[dim] + t * (
31
                self.position_2[dim] - self.position_1[dim]
32
            )
33
        return new_position
34