KindXiaoming / pykan

Kolmogorov Arnold Networks
MIT License
15.03k stars 1.39k forks source link

Early Stop in Grid Search #357

Open zixiqin opened 3 months ago

zixiqin commented 3 months ago

Hi there,

I'm a beginner with KAN, and I'm trying to use grid search to find the best parameters. Everything is going well using a simple for loop to handle the grid search. However, I'm stuck on choosing the right value for "Step" for each grid search experiment. I'm trying to find a way to implement an early stopping mechanism, where the model will capture the best step when its performance does not improve for a certain number of steps (for example, at least 5 steps without improvement).

Does anyone know how to apply early stopping, similar to what most neural network models can do, in KAN?

Thank you so much!

seyidcemkarakas commented 3 months ago

@zixiqin Hi

Can you provide your code for Grid Seach ?

zixiqin commented 3 months ago

Thank you for your response. Here is the code snippet.

The 'Step' parameter has been fixed as a constant within the model.fit() method. For example, model.fit(..., step = 40, ...) will continue until all 40 steps are completed.

I am wondering if there is a way to check if the model has already reached the lowest loss (particularly the test loss) and stop the training early.

dataset = { 'train_input': train_input_tensor, 'train_label': train_label_tensor, 'test_input': test_input_tensor, 'test_label': test_label_tensor }

grids = { 'first_hl': np.array([32,16,8]), 'G': np.array([5,10,20]), 'k' : np.array([3,4,5]), 'lamb' : np.array([0, 0.1, 0.01]), 'lamb_ent': np.array([10, 0, 0.1]), 'seed' :np.array([1,2,3]) }

result = { 'first_hl': [], 'G': [], 'k' : [], 'lamb' : [], 'lamb_ent': [], 'train_loss_detail': [], 'test_loss_detail': [] }

grid_search_for_loop