Beispiel #1
0
    def draw_gradient(self, x):
        """
        Draws the gradient as an offset vector from the trajectory

        Parameters
        ----------
        x : array
            the trajectory vector
        """
        g = self.objective.objective.gradient(x)
        q_init = self.objective.q_init
        self.draw(Trajectory(q_init=q_init, x=x),
                  Trajectory(q_init=q_init, x=-0.01 * g + x))
Beispiel #2
0
 def hessian(self, x):
     if self.viewer is not None:
         if self._draw_hessian:
             self.draw_gradient(x)
         else:
             self.draw(Trajectory(q_init=self.objective.q_init, x=x))
     return self.objective.objective.hessian(x)
Beispiel #3
0
def load_trajectories_from_file(filename='trajectories_1k_small.hdf5'):
    """ Load data from an hdf5 file """
    data = dict_to_object(load_dictionary_from_file(filename))
    print((" -- trajectories * n : {}".format(data.n[0])))
    print((" -- trajectories * l : {}".format(len(data.datasets))))
    n = data.n[0]
    trajectories = [None] * len(data.datasets)
    for k, trj in enumerate(data.datasets):
        trajectories[k] = Trajectory(q_init=trj[:n], x=trj)
    return trajectories
Beispiel #4
0
    def hessian(self, x):
        """
        Calculates the hessian after drawing the trajectory
        and draws optionaly the gradient

        Parameters
        ----------
        x : array
            the trajectory vector
        """
        if self.viewer is not None:
            if self._draw_hessian:
                self.draw_gradient(x)
            else:
                self.draw(Trajectory(q_init=self.objective.q_init, x=x))
        return self.objective.objective.hessian(x)
Beispiel #5
0
 def draw_gradient(self, x):
     g = self.objective.objective.gradient(x)
     q_init = self.objective.q_init
     self.draw(
         Trajectory(q_init=q_init, x=x),
         Trajectory(q_init=q_init, x=-0.01 * g + x))