def sweep_intercept(
        self,
        intercept_start: float = None,
        intercept_stop: float = None,
        duration: float = 9,
    ) -> None:
        """
        Animate a sweep through the values for the intercept.
        """
        if intercept_start is None:
            intercept_start = self.ymin
        if intercept_stop is None:
            intercept_stop = self.ymax
        clear_pngs(self.frame_dir)
        intercepts = tools.make_trajectory(
            duration=duration,
            reverse=True,
            waypoints=[
                intercept_start, intercept_stop,
                intercept_start, intercept_stop,
                intercept_start, intercept_stop,
            ],
        )

        azimuths = tools.make_trajectory(
            duration=duration,
            max_submovement_duration=2,
            reverse=True,
            waypoints=[self.azim_min, self.azim_max],
        )

        frame_base = 10000
        slope = 1
        for i_frame, intercept in enumerate(intercepts):
            frame_number = frame_base + i_frame

            self.render_frame_with_line(
                intercept=intercept,
                slope=slope,
                frame_number=frame_number,
            )

            self.loss_surface(azim=azimuths[i_frame])
            self.loss_ax.scatter(
                slope, intercept, self.zmin + 1,
                color="blue",
                marker=".",
                s=self.marker_large,
            )

            filename = "mnm_count_by_weight_" + str(int(frame_number)) + ".png"
            pathname = os.path.join(self.frame_dir, filename)
            self.finalize_plot(filename=pathname)

        render_movie(
            filename="mnm_weights_intercept_sweep.mp4",
            frame_dirname=self.frame_dir,
            output_dirname=self.output_dir,
        )
        return
Ejemplo n.º 2
0
    def sweep_shift(
        self,
        shift_start: float = None,
        shift_stop: float = None,
        weight_before: float = .912,
        weight_after: float = .932,
        duration: float = 32,
    ) -> None:
        """
        Animate a sweep through the values for the weight after.
        """
        if shift_start is None:
            shift_start = np.min(self.data[:, 0]) + 1
        if shift_stop is None:
            shift_stop = np.max(self.data[:, 0]) - 1
        clear_pngs(self.frame_dir)
        shifts = tools.make_trajectory(
            duration=duration,
            waypoints=[
                shift_start + 0 * (shift_stop - shift_start),
                shift_start + 1 * (shift_stop - shift_start),
                shift_start + .33 * (shift_stop - shift_start),
                shift_start + .66 * (shift_stop - shift_start),
                shift_start + .4 * (shift_stop - shift_start),
                shift_start + .6 * (shift_stop - shift_start),
                shift_start + .45 * (shift_stop - shift_start),
                shift_start + .55 * (shift_stop - shift_start),
            ],
        )

        azimuths = tools.make_trajectory(
            duration=duration,
            max_submovement_duration=2,
            waypoints=[self.azim_min, self.azim_max],
        )

        frame_base = 10000
        for i_frame, shift_day in enumerate(shifts):
            frame_number = frame_base + i_frame

            self.render_frame_with_line(
                weight_before=weight_before,
                weight_after=weight_after,
                shift_day=shift_day,
                frame_number=frame_number,
            )

            self.initialize_loss_function(shift_day=shift_day)
            self.loss_surface(azim=azimuths[i_frame])
            self.loss_ax.scatter(
                weight_before,
                weight_after,
                self.zmin - (self.zmax - self.zmin) * .01,
                color="blue",
                marker=".",
                s=self.marker_large,
            )

            filename = "mnm_weight_by_time_" + str(int(frame_number)) + ".png"
            pathname = os.path.join(self.frame_dir, filename)
            self.finalize_plot(filename=pathname)

        filename = "mnm_shift_sweep.mp4"
        tools.render_movie(
            filename=filename,
            frame_dirname=self.frame_dir,
            output_dirname=self.output_dir,
        )

        tools.convert_to_gif(
            filename=filename,
            dirname=self.output_dir,
        )
        return
Ejemplo n.º 3
0
    def sweep_after(
        self,
        after_start: float = None,
        after_stop: float = None,
        weight_before: float = .912,
        shift_day: float = 56,
        duration: float = 16,
    ) -> None:
        """
        Animate a sweep through the values for the weight after.
        """
        if after_start is None:
            after_start = self.xmin
        if after_stop is None:
            after_stop = self.xmax
        clear_pngs(self.frame_dir)
        weights_after = tools.make_trajectory(
            duration=duration,
            reverse=False,
            waypoints=[
                after_start + 0 * (after_stop - after_start),
                after_start + 1 * (after_stop - after_start),
                after_start + .33 * (after_stop - after_start),
                after_start + .66 * (after_stop - after_start),
                after_start + .4 * (after_stop - after_start),
                after_start + .6 * (after_stop - after_start),
                after_start + .45 * (after_stop - after_start),
                after_start + .55 * (after_stop - after_start),
            ],
        )

        azimuths = tools.make_trajectory(
            duration=duration,
            max_submovement_duration=2,
            reverse=False,
            waypoints=[self.azim_max, self.azim_min],
        )

        frame_base = 10000
        self.initialize_loss_function(shift_day=shift_day)
        for i_frame, weight_after in enumerate(weights_after):
            frame_number = frame_base + i_frame

            self.render_frame_with_line(
                weight_before=weight_before,
                weight_after=weight_after,
                shift_day=shift_day,
                frame_number=frame_number,
            )

            self.loss_surface(azim=azimuths[i_frame])
            self.loss_ax.scatter(
                weight_before,
                weight_after,
                self.zmin - (self.zmax - self.zmin) * .01,
                color="blue",
                marker=".",
                s=self.marker_large,
            )

            filename = "mnm_weight_by_time_" + str(int(frame_number)) + ".png"
            pathname = os.path.join(self.frame_dir, filename)
            self.finalize_plot(filename=pathname)

        tools.render_movie(
            filename="mnm_after_weights_sweep.mp4",
            frame_dirname=self.frame_dir,
            output_dirname=self.output_dir,
        )
        return
Ejemplo n.º 4
0
    def sweep_intercept_slope(
        self,
        intercept_min: float = None,
        intercept_max: float = None,
        slope_min: float = None,
        slope_max: float = None,
        duration: float = 9,
        n_waypoints: int = 10,
    ) -> None:
        """
        Animate a sweep through the values for the slope.
        """
        if intercept_min is None:
            intercept_min = self.ymin
        if intercept_max is None:
            intercept_max = self.ymax
        if slope_min is None:
            slope_min = self.xmin
        if slope_max is None:
            slope_max = self.xmax
        clear_pngs(self.frame_dir)
        slope_waypoints = []
        intercept_waypoints = []
        for _ in range(n_waypoints):
            intercept_waypoints.append(np.random.sample() *
                                       (intercept_max - intercept_min) +
                                       intercept_min)
            slope_waypoints.append(np.random.sample() *
                                   (slope_max - slope_min) + slope_min)

        slopes = tools.make_trajectory(
            duration=duration,
            loop=True,
            waypoints=slope_waypoints,
        )
        intercepts = tools.make_trajectory(
            duration=duration,
            loop=True,
            waypoints=intercept_waypoints,
        )

        azimuths = tools.make_trajectory(
            duration=duration,
            max_submovement_duration=2,
            reverse=True,
            waypoints=[self.azim_min, self.azim_max],
        )

        frame_base = 10000
        for i_frame, slope in enumerate(slopes):
            local_intercept = intercepts[i_frame]
            frame_number = frame_base + i_frame
            # This keeps the line passing through the middle of the data.
            intercept = local_intercept + 56 * (1 - slope)

            self.render_frame_with_line(
                intercept=intercept,
                slope=slope,
                frame_number=frame_number,
            )

            self.loss_surface(azim=azimuths[i_frame])
            self.loss_ax.scatter(
                slope,
                intercept,
                self.zmin + 1,
                color="blue",
                marker=".",
                s=self.marker_large,
            )

            filename = "mnm_count_by_weight_" + str(int(frame_number)) + ".png"
            pathname = os.path.join(self.frame_dir, filename)
            self.finalize_plot(filename=pathname)

        render_movie(
            filename="mnm_weights_random_sweep.mp4",
            frame_dirname=self.frame_dir,
            output_dirname=self.output_dir,
        )
        return
Ejemplo n.º 5
0
    def sweep_slope(
        self,
        slope_start: float = None,
        slope_stop: float = None,
        duration: float = 9,
    ) -> None:
        """
        Animate a sweep through the values for the slope.
        """
        if slope_start is None:
            slope_start = self.xmin
        if slope_stop is None:
            slope_stop = self.xmax
        clear_pngs(self.frame_dir)
        slopes = tools.make_trajectory(
            duration=duration,
            reverse=True,
            waypoints=[
                slope_start,
                slope_stop,
                slope_start,
                slope_stop,
                slope_start,
                slope_stop,
            ],
        )

        azimuths = tools.make_trajectory(
            duration=duration,
            max_submovement_duration=2,
            reverse=True,
            waypoints=[self.azim_min, self.azim_max],
        )

        frame_base = 10000
        for i_frame, slope in enumerate(slopes):
            frame_number = frame_base + i_frame
            # This keeps the line passing through the middle of the data.
            intercept = 50 * (1 - slope)

            self.render_frame_with_line(
                intercept=intercept,
                slope=slope,
                frame_number=frame_number,
            )

            self.loss_surface(azim=azimuths[i_frame])
            self.loss_ax.scatter(
                slope,
                intercept,
                self.zmin + 1,
                color="blue",
                marker=".",
                s=self.marker_large,
            )

            filename = "mnm_count_by_weight_" + str(int(frame_number)) + ".png"
            pathname = os.path.join(self.frame_dir, filename)
            self.finalize_plot(filename=pathname)

        render_movie(
            filename="mnm_weights_slope_sweep.mp4",
            frame_dirname=self.frame_dir,
            output_dirname=self.output_dir,
        )
        return
    def sweep_intercept_slope(
        self,
        intercept_min: float = None,
        intercept_max: float = None,
        slope_min: float = None,
        slope_max: float = None,
        duration: float = 9,
        n_waypoints: int = 10,
    ) -> None:
        """
        Animate a sweep through the values for the slope.
        """
        if intercept_min is None:
            intercept_min = self.ymin
        if intercept_max is None:
            intercept_max = self.ymax
        if slope_min is None:
            slope_min = self.xmin
        if slope_max is None:
            slope_max = self.xmax
        clear_pngs(self.frame_dir)
        slope_waypoints = []
        intercept_waypoints = []
        for _ in range(n_waypoints):
            intercept_waypoints.append(
                np.random.sample() * (intercept_max - intercept_min)
                + intercept_min)
            slope_waypoints.append(
                np.random.sample() * (slope_max - slope_min)
                + slope_min)

        slopes = tools.make_trajectory(
            duration=duration,
            loop=True,
            waypoints=slope_waypoints,
        )
        intercepts = tools.make_trajectory(
            duration=duration,
            loop=True,
            waypoints=intercept_waypoints,
        )

        azimuths = tools.make_trajectory(
            duration=duration,
            max_submovement_duration=2,
            reverse=True,
            waypoints=[self.azim_min, self.azim_max],
        )

        frame_base = 10000
        for i_frame, slope in enumerate(slopes):
            local_intercept = intercepts[i_frame]
            frame_number = frame_base + i_frame
            # This keeps the line passing through the middle of the data.
            intercept = local_intercept + 56 * (1 - slope)

            self.render_frame_with_line(
                intercept=intercept,
                slope=slope,
                frame_number=frame_number,
            )

            self.loss_surface(azim=azimuths[i_frame])
            self.loss_ax.scatter(
                slope, intercept, self.zmin + 1,
                color="blue",
                marker=".",
                s=self.marker_large,
            )

            filename = "mnm_count_by_weight_" + str(int(frame_number)) + ".png"
            pathname = os.path.join(self.frame_dir, filename)
            self.finalize_plot(filename=pathname)

        render_movie(
            filename="mnm_weights_random_sweep.mp4",
            frame_dirname=self.frame_dir,
            output_dirname=self.output_dir,
        )
        return
Ejemplo n.º 7
0
    def sweep_shift(
        self,
        shift_start: float = None,
        shift_stop: float = None,
        weight_before: float = .912,
        weight_after: float = .932,
        duration: float = 32,
    ) -> None:
        """
        Animate a sweep through the values for the weight after.
        """
        if shift_start is None:
            shift_start = np.min(self.data[:, 0]) + 1
        if shift_stop is None:
            shift_stop = np.max(self.data[:, 0]) - 1
        clear_pngs(self.frame_dir)
        shifts = tools.make_trajectory(
            duration=duration,
            waypoints=[
               shift_start + 0 * (shift_stop - shift_start),
               shift_start + 1 * (shift_stop - shift_start),
               shift_start + .33 * (shift_stop - shift_start),
               shift_start + .66 * (shift_stop - shift_start),
               shift_start + .4 * (shift_stop - shift_start),
               shift_start + .6 * (shift_stop - shift_start),
               shift_start + .45 * (shift_stop - shift_start),
               shift_start + .55 * (shift_stop - shift_start),
            ],
        )

        azimuths = tools.make_trajectory(
            duration=duration,
            max_submovement_duration=2,
            waypoints=[self.azim_min, self.azim_max],
        )

        frame_base = 10000
        for i_frame, shift_day in enumerate(shifts):
            frame_number = frame_base + i_frame

            self.render_frame_with_line(
                weight_before=weight_before,
                weight_after=weight_after,
                shift_day=shift_day,
                frame_number=frame_number,
            )

            self.initialize_loss_function(shift_day=shift_day)
            self.loss_surface(azim=azimuths[i_frame])
            self.loss_ax.scatter(
                weight_before, weight_after,
                self.zmin - (self.zmax - self.zmin) * .01,
                color="blue",
                marker=".",
                s=self.marker_large,
                zorder=1e6,
            )

            filename = "mnm_weight_by_time_" + str(int(frame_number)) + ".png"
            pathname = os.path.join(self.frame_dir, filename)
            self.finalize_plot(filename=pathname)

        filename = "mnm_shift_sweep.mp4"
        tools.render_movie(
            filename=filename,
            frame_dirname=self.frame_dir,
            output_dirname=self.output_dir,
        )

        tools.convert_to_gif(
            filename=filename,
            dirname=self.output_dir,
        )
        return
Ejemplo n.º 8
0
    def sweep_after(
        self,
        after_start: float = None,
        after_stop: float = None,
        weight_before: float = .912,
        shift_day: float = 56,
        duration: float = 16,
    ) -> None:
        """
        Animate a sweep through the values for the weight after.
        """
        if after_start is None:
            after_start = self.xmin
        if after_stop is None:
            after_stop = self.xmax
        clear_pngs(self.frame_dir)
        weights_after = tools.make_trajectory(
            duration=duration,
            reverse=False,
            waypoints=[
               after_start + 0 * (after_stop - after_start),
               after_start + 1 * (after_stop - after_start),
               after_start + .33 * (after_stop - after_start),
               after_start + .66 * (after_stop - after_start),
               after_start + .4 * (after_stop - after_start),
               after_start + .6 * (after_stop - after_start),
               after_start + .45 * (after_stop - after_start),
               after_start + .55 * (after_stop - after_start),
            ],
        )

        azimuths = tools.make_trajectory(
            duration=duration,
            max_submovement_duration=2,
            reverse=False,
            waypoints=[self.azim_max, self.azim_min],
        )

        frame_base = 10000
        self.initialize_loss_function(shift_day=shift_day)
        for i_frame, weight_after in enumerate(weights_after):
            frame_number = frame_base + i_frame

            self.render_frame_with_line(
                weight_before=weight_before,
                weight_after=weight_after,
                shift_day=shift_day,
                frame_number=frame_number,
            )

            self.loss_surface(azim=azimuths[i_frame])
            self.loss_ax.scatter(
                weight_before, weight_after,
                self.zmin - (self.zmax - self.zmin) * .01,
                color="blue",
                marker=".",
                s=self.marker_large,
            )

            filename = "mnm_weight_by_time_" + str(int(frame_number)) + ".png"
            pathname = os.path.join(self.frame_dir, filename)
            self.finalize_plot(filename=pathname)

        tools.render_movie(
            filename="mnm_after_weights_sweep.mp4",
            frame_dirname=self.frame_dir,
            output_dirname=self.output_dir,
        )
        return