Skip to content

Map

Map

Bases: _Generator_

This class is an implementation of Generator for maps generators.

Source code in phaseportrait/maps/map.py
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
class Map(_Generator_):
    """
    This class is an implementation of _Generator_ for maps generators.
    """
    def __init__(self, portrait, dF, dimension, max_values, *, dF_args=None, initial_values=None, thermalization=0, **kargs):
        """
        Args:
            portrait (Object) : Class that uses the RungeKutta objects.
            dF (callable) : A dF type funcion.
            dimension (int) : Number of dimensions in which it calculates the next values. Must equal the amount of outputs the `dF` funcion gives.
            max_values (int) : Max number of values saved.
            dF_args (dict) : If necesary, must contain the kargs for the `dF` funcion. By default, None.
            initial_values (float, list, optional) : Initial set of conditions, by default None. If None, random initial conditions are aplied in the interval [0,1) for each coordinate.
            thermalization (int, optional) : Thermalization steps before data is saved, by default None. If None, thermalization steps are set to 0.
        """
        super().__init__(portrait, dF, dimension, max_values, dF_args=dF_args,
                         initial_values=initial_values, thermalization=thermalization, **kargs)

        self.positions = self._create_values_array()
    @classmethod
    def _instance_and_compute_all(cls, tup):
        instance = cls(tup[0], tup[1], tup[2], tup[3], dF_args=tup[4], initial_values=tup[5], thermalization=tup[6])

        max_index = instance.compute_all(limit_cycle_check=tup[7], delta=tup[8])
        if max_index is not None:
            instance.positions = instance.positions[:,0:max_index-1]
        return instance
    @classmethod
    def instance_and_compute_all(cls, portrait, dF, dimension, max_values, dF_args, initial_values, save_freq, thermalization, **kargs):
        """Creates an instance of phase-portrait.maps.Map. 
        Computes all the data requested and returns the instance.

        Args:
            portrait (Object) : Class that uses the RungeKutta objects.
            dF (callable) : A dF type funcion.
            dimension (int) : Number of dimensions in which it calculates the next values. Must equal the amount of outputs the `dF` funcion gives.
            max_values (int) : Max number of values saved.
            dF_args (dict) : If necesary, must contain the kargs for the `dF` funcion. By default, None.
            initial_values (float, list, optional) : Initial set of conditions, by default None. If None, random initial conditions are aplied in the interval [0,1) for each coordinat
            save_freq (int, optional, by default 1) : Number of values computed before saving them.
            thermalization (int, optional) : Thermalization steps before data is saved, by default None. If None, thermalization steps are set to 0.
            limit_cycle_check (int, bool, optional, by default False) : Whenever to check it there os a limit cycle in the data.
            delta (float, optional, by default 0.01) : If `limit_cycle_check==True` is the distance between data elements to be considerated equal.

        Returns:
            (phaseportrait.maps.Map): The instance with all the data requested
        """

        instance = cls(portrait, dF, dimension, max_values, dF_args=dF_args,
                       initial_values=initial_values, save_freq=save_freq, thermalization=thermalization, **kargs)

        max_index = instance.compute_all(**kargs)
        if max_index is not None:
            instance.positions = instance.positions[:,0:max_index-1]
        return instance

    def _next(self): 
        """
        Generates from `self.position` its following value.
        """
        self.position[0] = self.dF(*(self.position), **self.dF_args)

    def save(self, i):
        """
        Saves `self.position` in the attribute `self.positions`.

        Args:
            i (int) : Index in which the data is saved.
        """
        try:
            self.positions[:, i] = self.position
        except IndexError:
            np.concatenate(self.positions, self._create_values_array(), axis=1)
            self.max_values *= 2
            self.save(i)

    def clear_values(self):
        """
        Clears the data arrays `self.positions`.
        """
        self.positions[:, 1:] = 0

    def _check_limit_cycle(self, delta):
        """Checks if there is a limit cycle in the data.

        Args:
            delta (float) : Difference between data values to be considerated equal.

        Returns:
            (bool): Whenever data reached a limit cylce.
        """
        for i in self.positions[0,0:-2]:
            if np.linalg.norm(i - self.position)<delta:
                return True
        return False    

__init__(portrait, dF, dimension, max_values, *, dF_args=None, initial_values=None, thermalization=0, **kargs)

Parameters:

Name Type Description Default
portrait Object)

Class that uses the RungeKutta objects.

required
dF callable)

A dF type funcion.

required
dimension int)

Number of dimensions in which it calculates the next values. Must equal the amount of outputs the dF funcion gives.

required
max_values int)

Max number of values saved.

required
dF_args dict)

If necesary, must contain the kargs for the dF funcion. By default, None.

None
initial_values float, list, optional)

Initial set of conditions, by default None. If None, random initial conditions are aplied in the interval [0,1) for each coordinate.

None
thermalization int, optional)

Thermalization steps before data is saved, by default None. If None, thermalization steps are set to 0.

0
Source code in phaseportrait/maps/map.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def __init__(self, portrait, dF, dimension, max_values, *, dF_args=None, initial_values=None, thermalization=0, **kargs):
    """
    Args:
        portrait (Object) : Class that uses the RungeKutta objects.
        dF (callable) : A dF type funcion.
        dimension (int) : Number of dimensions in which it calculates the next values. Must equal the amount of outputs the `dF` funcion gives.
        max_values (int) : Max number of values saved.
        dF_args (dict) : If necesary, must contain the kargs for the `dF` funcion. By default, None.
        initial_values (float, list, optional) : Initial set of conditions, by default None. If None, random initial conditions are aplied in the interval [0,1) for each coordinate.
        thermalization (int, optional) : Thermalization steps before data is saved, by default None. If None, thermalization steps are set to 0.
    """
    super().__init__(portrait, dF, dimension, max_values, dF_args=dF_args,
                     initial_values=initial_values, thermalization=thermalization, **kargs)

    self.positions = self._create_values_array()

clear_values()

Clears the data arrays self.positions.

Source code in phaseportrait/maps/map.py
82
83
84
85
86
def clear_values(self):
    """
    Clears the data arrays `self.positions`.
    """
    self.positions[:, 1:] = 0

instance_and_compute_all(portrait, dF, dimension, max_values, dF_args, initial_values, save_freq, thermalization, **kargs) classmethod

Creates an instance of phase-portrait.maps.Map. Computes all the data requested and returns the instance.

Parameters:

Name Type Description Default
portrait Object)

Class that uses the RungeKutta objects.

required
dF callable)

A dF type funcion.

required
dimension int)

Number of dimensions in which it calculates the next values. Must equal the amount of outputs the dF funcion gives.

required
max_values int)

Max number of values saved.

required
dF_args dict)

If necesary, must contain the kargs for the dF funcion. By default, None.

required
initial_values float, list, optional)

Initial set of conditions, by default None. If None, random initial conditions are aplied in the interval [0,1) for each coordinat

required
save_freq int, optional, by default 1)

Number of values computed before saving them.

required
thermalization int, optional)

Thermalization steps before data is saved, by default None. If None, thermalization steps are set to 0.

required
limit_cycle_check int, bool, optional, by default False)

Whenever to check it there os a limit cycle in the data.

required
delta float, optional, by default 0.01)

If limit_cycle_check==True is the distance between data elements to be considerated equal.

required

Returns:

Type Description
phaseportrait.maps.Map

The instance with all the data requested

Source code in phaseportrait/maps/map.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@classmethod
def instance_and_compute_all(cls, portrait, dF, dimension, max_values, dF_args, initial_values, save_freq, thermalization, **kargs):
    """Creates an instance of phase-portrait.maps.Map. 
    Computes all the data requested and returns the instance.

    Args:
        portrait (Object) : Class that uses the RungeKutta objects.
        dF (callable) : A dF type funcion.
        dimension (int) : Number of dimensions in which it calculates the next values. Must equal the amount of outputs the `dF` funcion gives.
        max_values (int) : Max number of values saved.
        dF_args (dict) : If necesary, must contain the kargs for the `dF` funcion. By default, None.
        initial_values (float, list, optional) : Initial set of conditions, by default None. If None, random initial conditions are aplied in the interval [0,1) for each coordinat
        save_freq (int, optional, by default 1) : Number of values computed before saving them.
        thermalization (int, optional) : Thermalization steps before data is saved, by default None. If None, thermalization steps are set to 0.
        limit_cycle_check (int, bool, optional, by default False) : Whenever to check it there os a limit cycle in the data.
        delta (float, optional, by default 0.01) : If `limit_cycle_check==True` is the distance between data elements to be considerated equal.

    Returns:
        (phaseportrait.maps.Map): The instance with all the data requested
    """

    instance = cls(portrait, dF, dimension, max_values, dF_args=dF_args,
                   initial_values=initial_values, save_freq=save_freq, thermalization=thermalization, **kargs)

    max_index = instance.compute_all(**kargs)
    if max_index is not None:
        instance.positions = instance.positions[:,0:max_index-1]
    return instance

save(i)

Saves self.position in the attribute self.positions.

Parameters:

Name Type Description Default
i int)

Index in which the data is saved.

required
Source code in phaseportrait/maps/map.py
68
69
70
71
72
73
74
75
76
77
78
79
80
def save(self, i):
    """
    Saves `self.position` in the attribute `self.positions`.

    Args:
        i (int) : Index in which the data is saved.
    """
    try:
        self.positions[:, i] = self.position
    except IndexError:
        np.concatenate(self.positions, self._create_values_array(), axis=1)
        self.max_values *= 2
        self.save(i)