Completed
Pull Request — master (#43)
by Wojtek
06:19
created

Particle.update_input_vectors()   A

Complexity

Conditions 3

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 3
1
"""Representation of a particle in swarm."""
2
3
import numpy as np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4
5
from grortir.main.pso.position_updater import PositionUpdater
6
from grortir.main.pso.velocity_calculator import VelocityUpdater
0 ignored issues
show
Bug introduced by
The name velocity_calculator does not seem to exist in module grortir.main.pso.
Loading history...
Configuration introduced by
The import grortir.main.pso.velocity_calculator could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
7
8
9
class Particle(object):
10
    """Implementation of https://gitlab.com/OPUS/matlabs-simulations/blob/master/src/PSO_G.m loop from 24th line"""
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (115/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
11
12
    def __init__(self, stages, process):
13
        self.stages = stages
14
        self.process = process
15
        self.position_updaters = {}
16
        self.current_velocities = {}
17
        self.current_quality = {}
18
        self.best_quality = np.inf
19
        self.best_positions = {}
20
21
    def initialize(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
22
        for stage in self.stages:
23
            self.position_updaters[stage] = PositionUpdater(stage)
24
            self.velocity_updaters[stage] = VelocityUpdater(stage)
0 ignored issues
show
Bug introduced by
The Instance of Particle does not seem to have a member named velocity_updaters.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
25
        self._set_initial_positions()
26
        self._set_initial_velocities()
27
28
    def _set_initial_positions(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
29
        for stage in self.stages:
30
            self.position_updaters[stage].set_initial_control_params()
31
32
    def _set_initial_velocities(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
33
        for stage in self.stages:
34
            self.velocity_updaters[stage].set_initial_velocity()
0 ignored issues
show
Bug introduced by
The Instance of Particle does not seem to have a member named velocity_updaters.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
35
36
    def update_values(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
37
        self.update_input_vectors()
38
        self.calculate_current_quality()
39
        self._update_best_position()
40
41
    def _update_best_position(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
42
        current_quality = self.get_the_overall_quality()
43
        if current_quality < self.best_quality:
44
            self.best_quality = current_quality
45
            for stage in self.stages:
46
                self.best_positions[stage] = stage.control_params
47
48
    def update_input_vectors(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
49
        for stage in self.stages:
50
            current_output = stage.get_output_of_stage()
51
            successors = self.process.successors(stage)
52
            for successor in successors:
53
                successor.input_vector = current_output
54
55
    def calculate_current_quality(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
56
        for stage in self.stages:
57
            self.current_quality[stage] = stage.get_quality()
58
59
    def get_the_overall_quality(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
60
        stage = max(self.current_quality, key=self.current_quality.get)
61
        return self.current_quality[stage]
62
63
    def move(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
64
        for stage in self.stages:
65
            velocity = self.velocity_updaters[stage].update()
0 ignored issues
show
Bug introduced by
The Instance of Particle does not seem to have a member named velocity_updaters.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
66
            self.position_updaters[stage].update_position(velocity)
67
        pass
0 ignored issues
show
Unused Code introduced by
Unnecessary pass statement
Loading history...
68
69
    def update_velocieties(self, best_particle):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
70
71
        pass
72