Embeddings generator

class embedded_voting.EmbeddingsGenerator(n_voters, n_dim)[source]

This abstract class creates Embeddings from scratch using some function.

Parameters:
  • n_voters (int) – Number of voters in the embeddings.
  • n_dim (int) – Number of dimensions for the embeddings.

Random Embeddings

class embedded_voting.EmbeddingsGeneratorUniform(n_voters, n_dim)[source]

Create random embeddings uniformly on the non-negative orthant.

The embedding of each voter is a unit vector that is uniformly drawn on the intersection of the unit sphere with the non-negative orthant.

Examples

>>> np.random.seed(42)
>>> generator = EmbeddingsGeneratorUniform(10, 2)
>>> generator()
Embeddings([[0.96337365, 0.26816265],
            [0.39134578, 0.92024371],
            [0.70713157, 0.70708199],
            [0.89942118, 0.43708299],
            [0.65433791, 0.75620229],
            [0.70534506, 0.70886413],
            [0.1254653 , 0.99209801],
            [0.95076   , 0.30992809],
            [0.95508537, 0.29633078],
            [0.54080587, 0.84114744]])

From correlations

class embedded_voting.EmbeddingsCorrelation[source]

Embeddings based on correlation, dedicated to RuleFast.

Parameters:
  • positions (np.ndarray or list or Embeddings) – The embeddings of the voters. Its dimensions are n_voters, n_dim.
  • n_sing_val (int) – “Effective” number of singular values.
  • ratings_means (np.ndarray) – Mean rating for each voter.
  • ratings_stds (np.ndarray) – Standard deviation of the ratings for each voter.
  • norm (bool) – If True, normalize the embeddings.

Examples

>>> embeddings = EmbeddingsCorrelation([[1, 2], [3, 4]], n_sing_val=2, ratings_means=[.1, .2],
...                                    ratings_stds=[.3, .4], norm=True)
>>> embeddings
EmbeddingsCorrelation([[0.4472136 , 0.89442719],
                       [0.6       , 0.8       ]])
>>> embeddings.n_sing_val
2
>>> embeddings.ratings_means
[0.1, 0.2]
>>> embeddings2 = embeddings.copy()
>>> embeddings2.n_sing_val
2