Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gorgonina hyperparameter optimization #118

Merged
merged 2 commits into from
Apr 19, 2020
Merged

Gorgonina hyperparameter optimization #118

merged 2 commits into from
Apr 19, 2020

Conversation

c-bata
Copy link
Owner

@c-bata c-bata commented Apr 19, 2020

Add an example to optimize hyperparameters for Gorgonia Iris example.

Result
(venv) $ go build -o /Users/a14737/go/src/github.com/c-bata/goptuna/bin/gorgonia_iris /Users/a14737/go/src/github.com/c-bata/goptuna/_examples/gorgonia_iris/main.go
(venv) $ ./bin/gorgonia_iris -dataset ./_examples/gorgonia_iris/iris.csv 
2020/04/20 01:47:01 [INFO] Trial finished: trialID=1 state=Complete evaluation=0.000000
2020/04/20 01:47:01 [INFO] Trial finished: trialID=2 state=Complete evaluation=0.813333
2020/04/20 01:47:02 [INFO] Trial finished: trialID=3 state=Complete evaluation=0.960000
2020/04/20 01:47:02 [INFO] Trial finished: trialID=4 state=Complete evaluation=0.626667
2020/04/20 01:47:03 [INFO] Trial finished: trialID=5 state=Complete evaluation=0.600000
2020/04/20 01:47:03 [INFO] Trial finished: trialID=6 state=Complete evaluation=0.880000
2020/04/20 01:47:04 [INFO] Trial finished: trialID=7 state=Complete evaluation=0.833333
2020/04/20 01:47:05 [INFO] Trial finished: trialID=8 state=Complete evaluation=0.980000
2020/04/20 01:47:05 [INFO] Trial finished: trialID=9 state=Complete evaluation=0.000000
2020/04/20 01:47:06 [INFO] Trial finished: trialID=10 state=Complete evaluation=0.826667
2020/04/20 01:47:06 [INFO] Trial finished: trialID=11 state=Complete evaluation=0.953333
2020/04/20 01:47:07 [INFO] Trial finished: trialID=12 state=Complete evaluation=0.873333
2020/04/20 01:47:07 [INFO] Trial finished: trialID=13 state=Complete evaluation=0.953333
2020/04/20 01:47:08 [INFO] Trial finished: trialID=14 state=Complete evaluation=0.953333
2020/04/20 01:47:09 [INFO] Trial finished: trialID=15 state=Complete evaluation=0.833333
2020/04/20 01:47:09 [INFO] Trial finished: trialID=16 state=Complete evaluation=0.906667
2020/04/20 01:47:10 [INFO] Trial finished: trialID=17 state=Complete evaluation=0.960000
2020/04/20 01:47:10 [INFO] Trial finished: trialID=18 state=Complete evaluation=0.693333
2020/04/20 01:47:11 [INFO] Trial finished: trialID=19 state=Complete evaluation=0.840000
2020/04/20 01:47:11 [INFO] Trial finished: trialID=20 state=Complete evaluation=0.966667
2020/04/20 01:47:12 [INFO] Trial finished: trialID=21 state=Complete evaluation=0.966667
2020/04/20 01:47:13 [INFO] Trial finished: trialID=22 state=Complete evaluation=0.960000
2020/04/20 01:47:13 [INFO] Trial finished: trialID=23 state=Complete evaluation=0.000000
2020/04/20 01:47:14 [INFO] Trial finished: trialID=24 state=Complete evaluation=0.973333
2020/04/20 01:47:14 [INFO] Trial finished: trialID=25 state=Complete evaluation=0.840000
2020/04/20 01:47:15 [INFO] Trial finished: trialID=26 state=Complete evaluation=0.953333
2020/04/20 01:47:15 [INFO] Trial finished: trialID=27 state=Complete evaluation=0.966667
2020/04/20 01:47:16 [INFO] Trial finished: trialID=28 state=Complete evaluation=0.960000
2020/04/20 01:47:17 [INFO] Trial finished: trialID=29 state=Complete evaluation=0.920000
2020/04/20 01:47:17 [INFO] Trial finished: trialID=30 state=Complete evaluation=0.960000
2020/04/20 01:47:18 [INFO] Trial finished: trialID=31 state=Complete evaluation=0.960000
2020/04/20 01:47:18 [INFO] Trial finished: trialID=32 state=Complete evaluation=0.000000
2020/04/20 01:47:19 [INFO] Trial finished: trialID=33 state=Complete evaluation=0.966667
2020/04/20 01:47:19 [INFO] Trial finished: trialID=34 state=Complete evaluation=0.953333
2020/04/20 01:47:20 [INFO] Trial finished: trialID=35 state=Complete evaluation=0.973333
2020/04/20 01:47:21 [INFO] Trial finished: trialID=36 state=Complete evaluation=0.000000
2020/04/20 01:47:21 [INFO] Trial finished: trialID=37 state=Complete evaluation=0.973333
2020/04/20 01:47:22 [INFO] Trial finished: trialID=38 state=Complete evaluation=0.000000
2020/04/20 01:47:22 [INFO] Trial finished: trialID=39 state=Complete evaluation=0.833333
2020/04/20 01:47:23 [INFO] Trial finished: trialID=40 state=Complete evaluation=0.966667
2020/04/20 01:47:24 [INFO] Trial finished: trialID=41 state=Complete evaluation=0.960000
2020/04/20 01:47:24 [INFO] Trial finished: trialID=42 state=Complete evaluation=0.966667
2020/04/20 01:47:25 [INFO] Trial finished: trialID=43 state=Complete evaluation=0.000000
2020/04/20 01:47:25 [INFO] Trial finished: trialID=44 state=Complete evaluation=0.960000
2020/04/20 01:47:26 [INFO] Trial finished: trialID=45 state=Complete evaluation=0.973333
2020/04/20 01:47:26 [INFO] Trial finished: trialID=46 state=Complete evaluation=0.000000
2020/04/20 01:47:27 [INFO] Trial finished: trialID=47 state=Complete evaluation=0.960000
2020/04/20 01:47:28 [INFO] Trial finished: trialID=48 state=Complete evaluation=0.966667
2020/04/20 01:47:28 [INFO] Trial finished: trialID=49 state=Complete evaluation=0.000000
2020/04/20 01:47:29 [INFO] Trial finished: trialID=50 state=Complete evaluation=0.960000
2020/04/20 01:47:29 Best evaluation=0.980000 (learning_rate=0.004181)

Comment on lines +110 to +111
learnRate, _ := trial.SuggestLogFloat("learning_rate", 1e-5, 1e-1)
solver := gorgonia.NewVanillaSolver(gorgonia.WithLearnRate(learnRate))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize learning rate.

Copy link
Owner Author

@c-bata c-bata Apr 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following suggestion seems to be more interesting as an Goptuna example.

	var solver gorgonia.Solver
	solverName, _ := trial.SuggestCategorical("solver", []string{"Adam", "Vanilla"})
	if solverName == "Adam" {
		solver = gorgonia.NewAdamSolver()
	} else if solverName == "Vanilla" {
		learnRate, _ := trial.SuggestLogFloat("vanilla_learning_rate", 1e-5, 1e-1)
		solver = gorgonia.NewVanillaSolver(gorgonia.WithLearnRate(learnRate))
	}

I created a pull request: #119

acc = accuracy(predicted.Data().([]float64), Y.Value().Data().([]float64))
machine.Reset() // Reset is necessary in a loop like this
}
return acc, nil
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maximize accuracy.

@c-bata c-bata changed the title Add example of gorgonia iris Gorgonina hyperparameter optimization Apr 19, 2020
study, err := goptuna.CreateStudy(
"gorgonia-iris",
goptuna.StudyOptionStorage(storage),
goptuna.StudyOptionSampler(tpe.NewSampler()),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize parameters using TPE.

@c-bata c-bata merged commit fc15fb1 into master Apr 19, 2020
@c-bata c-bata deleted the gorgonia-iris branch April 19, 2020 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant