Skip to content

Commit

Permalink
Added test for combining preference data types
Browse files Browse the repository at this point in the history
  • Loading branch information
ianran committed Dec 11, 2023
1 parent 9499e45 commit 85ffae3
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions tests/models/test_preference_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
def f_sin(x, data=None):
return 2 * np.cos(np.pi * (x-2)) * np.exp(-(0.9*x))

def f_sq(x, data=None):
return (x/10.0)**2


def test_preference_model_add_pairs():
pm = lop.PreferenceModel()
Expand Down Expand Up @@ -90,10 +93,10 @@ def test_adding_multiple_types():
pm = lop.PreferenceModel(other_probits={'abs': lop.AbsBoundProbit()})

X_pref = np.array([0,1,2,3])
y_pref = lop.generate_fake_pairs(X_pref, f_sin, 0) + lop.generate_fake_pairs(X_pref, f_sin, 1)
y_pref = lop.generate_fake_pairs(X_pref, f_sq, 0) + lop.generate_fake_pairs(X_pref, f_sq, 1)

X_abs = np.array([1.5, 2.5])
y_abs = f_sin(X_abs)
y_abs = f_sq(X_abs)

pm.add(X_pref, y_pref)

Expand All @@ -104,6 +107,30 @@ def test_adding_multiple_types():
assert pm is not None


def test_preference_model_likelyhood_multiple():
pm = lop.PreferenceModel()

X_train = np.array([0,1,2,3,4.2,6,7])
pairs = lop.generate_fake_pairs(X_train, f_sq, 0) + \
lop.generate_fake_pairs(X_train, f_sq, 1) + \
lop.generate_fake_pairs(X_train, f_sq, 2) + \
lop.generate_fake_pairs(X_train, f_sq, 3) + \
lop.generate_fake_pairs(X_train, f_sq, 4)


pm.add(X_train, pairs)

X_train = np.array([0.2,1.5,2.3,3.2,4.2,6.2,7.3])
y_train = f_sq(X_train)

pm.add(X_train, y_train, type='abs')


with pytest.raises(TypeError):
log_like = pm.log_likelyhood_training()
log_like = pm.log_likelyhood_training(np.array([0,0,0,1,1,1,0.5,0.1,0.05,0.2,0.8,0.9,0.9,0.5]))

assert not np.isnan(log_like)



Expand Down

0 comments on commit 85ffae3

Please sign in to comment.