numpy.trim_zeros

Here are the examples of the python api numpy.trim_zeros taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

Example 1

Project: deer Source File: agent.py
    def avgEpisodeVValue(self):
        """ Returns the average V value on the episode (on time steps where a non-random action has been taken)
        """
        if (len(self._Vs_on_last_episode) == 0):
            return -1
        if(np.trim_zeros(self._Vs_on_last_episode)!=[]):
            return np.average(np.trim_zeros(self._Vs_on_last_episode))
        else:
            return 0

Example 2

Project: pyflux Source File: gasrank.py
    def plot_abilities_one_components(self, team_ids, **kwargs):
        import matplotlib.pyplot as plt

        figsize = kwargs.get('figsize',(15,5))

        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            plt.figure(figsize=figsize)

            if type(team_ids) == type([]):
                if type(team_ids[0]) == str:
                    for team_id in team_ids:
                        plt.plot(np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[self.team_dict[team_id]],
                            trim='b'), label=self.team_strings[self.team_dict[team_id]])
                else:
                    for team_id in team_ids:
                        plt.plot(np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[team_id],
                            trim='b'), label=self.team_strings[team_id])
            else:
                if type(team_ids) == str:
                    plt.plot(np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[self.team_dict[team_ids]],
                        trim='b'), label=self.team_strings[self.team_dict[team_ids]])
                else:
                    plt.plot(np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[team_ids],
                        trim='b'), label=self.team_strings[team_ids])

            plt.legend()
            plt.ylabel("Power")
            plt.xlabel("Games")
            plt.show()

Example 3

Project: pyflux Source File: gasrank.py
    def plot_abilities_two_components(self, team_ids, component_id=0, **kwargs):
        import matplotlib.pyplot as plt

        figsize = kwargs.get('figsize',(15,5))

        if component_id == 0:
            name_strings = self.team_strings
            name_dict = self.team_dict
        else:
            name_strings = self.team_strings_2
            name_dict = self.team_dict_2

        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            plt.figure(figsize=figsize)

            if type(team_ids) == type([]):
                if type(team_ids[0]) == str:
                    for team_id in team_ids:
                        plt.plot(np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[component_id].T[name_dict[team_id]],
                            trim='b'), label=name_strings[name_dict[team_id]])
                else:
                    for team_id in team_ids:
                        plt.plot(np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[component_id].T[team_id],
                            trim='b'), label=name_strings[team_id])
            else:
                if type(team_ids) == str:
                    plt.plot(np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[component_id].T[name_dict[team_ids]],
                        trim='b'), label=name_strings[name_dict[team_ids]])
                else:
                    plt.plot(np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[component_id].T[team_ids],
                        trim='b'), label=name_strings[team_ids])
            plt.legend()
            plt.ylabel("Power")
            plt.xlabel("Games")
            plt.show()

Example 4

Project: pyflux Source File: gasrank.py
    def predict_one_component(self, team_1, team_2, neutral=False):
        """
        Returns team 1's probability of winning
        """
        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            if type(team_1) == str:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[self.team_dict[team_1]], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[self.team_dict[team_2]], trim='b')[-1]
 
            else:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[team_1], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[team_2], trim='b')[-1]

        t_z = self.transform_z()

        if neutral is False:
            return self.link(t_z[0] + team_1_ability - team_2_ability)
        else:
            return self.link(team_1_ability - team_2_ability)

Example 5

Project: pyflux Source File: gasrank.py
    def predict_two_components(self, team_1, team_2, team_1b, team_2b, neutral=False):
        """
        Returns team 1's probability of winning
        """
        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            if type(team_1) == str:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[self.team_dict[team_1]], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[self.team_dict[team_2]], trim='b')[-1]
                team_1_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[self.team_dict[team_1]], trim='b')[-1]
                team_2_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[self.team_dict[team_2]], trim='b')[-1]
  
            else:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[team_1], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[team_2], trim='b')[-1]
                team_1_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[team_1_b], trim='b')[-1]
                team_2_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[team_2_b], trim='b')[-1]

        t_z = self.transform_z()

        if neutral is False:
            return self.link(t_z[0] + team_1_ability - team_2_ability + team_1_b_ability - team_2_b_ability)
        else:
            return self.link(team_1_ability - team_2_ability + team_1_b_ability - team_2_b_ability)