Skip to content

Changing gradient descent parameters for tolerance and maximum iterations #38

@TheBil99

Description

@TheBil99

Hey, I wanted to ask if there is someway to change the number of iterations and the tolerance of the gradient descent algorithm in LogNet. I saw that analogously to glmnet in R, LogNet class has an attribute control, so I tried to setting these parameters from the control attribute but they do not seem to change anything in the model result. This is an example of what I am running, for some random X and y. I tried for different combinations of eps and mxit and nothing changed at all.Am I doing something wrong? Is there another way of setting these parameters?

`n = 2000
p = 20
rng = np.random.default_rng(seed)

X = rng.normal(size=(n, p))
w = rng.normal(size=p)
logits = X @ w / np.sqrt(p)
probs = 1 / (1 + np.exp(-logits))
y = (rng.random(n) < probs).astype(int)

penalty_factors = np.ones(p)

base_model = LogNet(
alpha=0.0,
penalty_factor=penalty_factors,
lambda_values=10 ** np.linspace(-4, 4, 100),
)
base_model.control.eps = eps
base_model.control.mxit = mxit

base_model.fit(X, y.reshape(-1, 1))

cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=123).split(X, y)

_, cvpath = base_model.cross_validation_path(
X, y.reshape(-1, 1),
cv=cv,
n_jobs=1,
)

lambda_min = cvpath.index_best["AUC"]
coef_min, intercept_min = base_model.interpolate_coefs(lambda_min)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions