Skip to content

Commit

Permalink
Compute RMSE between two parameter vectors.
Browse files Browse the repository at this point in the history
Add a small utility function that enables to compute the root mean
squared error between two parameter vectors (i.e., the L2 norm of the
difference vector).
  • Loading branch information
lucasmaystre committed Aug 8, 2018
1 parent 83914b8 commit 4c964b0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions choix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .utils import (
footrule_dist,
kendalltau_dist,
rmse,
log_likelihood_pairwise,
log_likelihood_rankings,
log_likelihood_top1,
Expand Down
22 changes: 22 additions & 0 deletions choix/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,28 @@ def kendalltau_dist(params1, params2=None):
return round((n_pairs - n_pairs * tau) / 2)


def rmse(params1, params2):
r"""Compute the root-mean-squared error between two models.
Parameters
----------
params1 : array_like
Parameters of the first model.
params2 : array_like
Parameters of the second model.
Returns
-------
error : float
Root-mean-squared error.
"""
assert len(params1) == len(params2)
params1 = np.asarray(params1) - np.mean(params1)
params2 = np.asarray(params2) - np.mean(params2)
sqrt_n = math.sqrt(len(params1))
return np.linalg.norm(params1 - params2, ord=2) / sqrt_n


def log_likelihood_pairwise(data, params):
"""Compute the log-likelihood of model parameters."""
loglik = 0
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
# The short X.Y version.
version = '0.3'
# The full version, including alpha/beta/rc tags.
release = '0.3.1'
release = '0.3.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def readme():

setup(
name='choix',
version='0.3.1',
version='0.3.2',
author='Lucas Maystre',
author_email='[email protected]',
description="Inference algorithms for models based on Luce's choice axiom.",
Expand Down

0 comments on commit 4c964b0

Please sign in to comment.