# estimate the ground truth preferences from the real car data

from sklearn.linear_model import LogisticRegression
import numpy as np
import math


# read data, i.e., covariate x and response y
x0 = np.load("Car_x.npy")
y0 = np.load("Car_y.npy")


# apply penalized logistic regression, i.e., regularized MLE
logisticRegr = LogisticRegression(C = 0.01)
f = logisticRegr.fit(x0, y0)


# extract fitted coefficient and intercept
co = f.coef_
icpt = f.intercept_


# construct the preferences from the fitted coefficient and intercept
v_car = []
for i in range(len(y0)):
    v_car.append(icpt[0]+np.dot(co[0],x0[i]))

v = []
for i in range(len(v_car)):
    v.append(math.exp(v_car[i]))

v.sort(reverse = True)


# save the estimated preferences
np.save("Car_Pre",v)