-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from cmjiang/tuner
Add hyper-parameter tuner interface
- Loading branch information
Showing
13 changed files
with
357 additions
and
91 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
photon-api/src/main/scala/com/linkedin/photon/ml/hyperparameter/tuner/AtlasTuner.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2018 LinkedIn Corp. All rights reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linkedin.photon.ml.hyperparameter.tuner | ||
|
||
import breeze.linalg.DenseVector | ||
|
||
import com.linkedin.photon.ml.HyperparameterTuningMode | ||
import com.linkedin.photon.ml.HyperparameterTuningMode.HyperparameterTuningMode | ||
import com.linkedin.photon.ml.evaluation.Evaluator | ||
import com.linkedin.photon.ml.hyperparameter.EvaluationFunction | ||
import com.linkedin.photon.ml.hyperparameter.search.{GaussianProcessSearch, RandomSearch} | ||
|
||
/** | ||
* A hyper-parameter tuner which depends on an internal LinkedIn library. | ||
*/ | ||
class AtlasTuner[T] extends HyperparameterTuner[T] { | ||
|
||
/** | ||
* Search hyper-parameters to optimize the model | ||
* | ||
* @param n The number of points to find | ||
* @param dimension Numbers of hyper-parameters to be tuned | ||
* @param mode Hyper-parameter tuning mode (random or Bayesian) | ||
* @param evaluationFunction Function that evaluates points in the space to real values | ||
* @param evaluator the original evaluator | ||
* @param observations Observations made prior to searching, from this data set (not mean-centered) | ||
* @param priorObservations Observations made prior to searching, from past data sets (mean-centered) | ||
* @param discreteParams Map that specifies the indices of discrete parameters and their numbers of discrete values | ||
* @return A Seq of the found results | ||
*/ | ||
def search( | ||
n: Int, | ||
dimension: Int, | ||
mode: HyperparameterTuningMode, | ||
evaluationFunction: EvaluationFunction[T], | ||
evaluator: Evaluator, | ||
observations: Seq[(DenseVector[Double], Double)], | ||
priorObservations: Seq[(DenseVector[Double], Double)] = Seq(), | ||
discreteParams: Map[Int, Int] = Map()): Seq[T] = { | ||
|
||
val searcher = mode match { | ||
case HyperparameterTuningMode.BAYESIAN => | ||
new GaussianProcessSearch[T](dimension, evaluationFunction, evaluator) | ||
|
||
case HyperparameterTuningMode.RANDOM => | ||
new RandomSearch[T](dimension, evaluationFunction) | ||
} | ||
|
||
searcher.findWithPriors(n, observations, priorObservations) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
photon-api/src/main/scala/com/linkedin/photon/ml/hyperparameter/tuner/DummyTuner.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2018 LinkedIn Corp. All rights reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linkedin.photon.ml.hyperparameter.tuner | ||
|
||
import breeze.linalg.DenseVector | ||
|
||
import com.linkedin.photon.ml.HyperparameterTuningMode.HyperparameterTuningMode | ||
import com.linkedin.photon.ml.evaluation.Evaluator | ||
import com.linkedin.photon.ml.hyperparameter.EvaluationFunction | ||
|
||
/** | ||
* A dummy hyper-parameter tuner which runs an empty operation. | ||
*/ | ||
class DummyTuner[T] extends HyperparameterTuner[T] { | ||
|
||
/** | ||
* Search hyper-parameters to optimize the model | ||
* | ||
* @param n The number of points to find | ||
* @param dimension Numbers of hyper-parameters to be tuned | ||
* @param mode Hyper-parameter tuning mode (random or Bayesian) | ||
* @param evaluationFunction Function that evaluates points in the space to real values | ||
* @param evaluator the original evaluator | ||
* @param observations Observations made prior to searching, from this data set (not mean-centered) | ||
* @param priorObservations Observations made prior to searching, from past data sets (mean-centered) | ||
* @param discreteParams Map that specifies the indices of discrete parameters and their numbers of discrete values | ||
* @return A Seq of the found results | ||
*/ | ||
def search( | ||
n: Int, | ||
dimension: Int, | ||
mode: HyperparameterTuningMode, | ||
evaluationFunction: EvaluationFunction[T], | ||
evaluator: Evaluator, | ||
observations: Seq[(DenseVector[Double], Double)], | ||
priorObservations: Seq[(DenseVector[Double], Double)] = Seq(), | ||
discreteParams: Map[Int, Int] = Map()): Seq[T] = Seq() | ||
} |
50 changes: 50 additions & 0 deletions
50
...-api/src/main/scala/com/linkedin/photon/ml/hyperparameter/tuner/HyperparameterTuner.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2018 LinkedIn Corp. All rights reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linkedin.photon.ml.hyperparameter.tuner | ||
|
||
import breeze.linalg.DenseVector | ||
|
||
import com.linkedin.photon.ml.HyperparameterTuningMode.HyperparameterTuningMode | ||
import com.linkedin.photon.ml.evaluation.Evaluator | ||
import com.linkedin.photon.ml.hyperparameter.EvaluationFunction | ||
|
||
/** | ||
* Interface for hyper-parameter tuner. | ||
*/ | ||
trait HyperparameterTuner[T] { | ||
|
||
/** | ||
* Search hyper-parameters to optimize the model | ||
* | ||
* @param n The number of points to find | ||
* @param dimension Numbers of hyper-parameters to be tuned | ||
* @param mode Hyper-parameter tuning mode (random or Bayesian) | ||
* @param evaluationFunction Function that evaluates points in the space to real values | ||
* @param evaluator the original evaluator | ||
* @param observations Observations made prior to searching, from this data set (not mean-centered) | ||
* @param priorObservations Observations made prior to searching, from past data sets (mean-centered) | ||
* @param discreteParams Map that specifies the indices of discrete parameters and their numbers of discrete values | ||
* @return A Seq of the found results | ||
*/ | ||
def search( | ||
n: Int, | ||
dimension: Int, | ||
mode: HyperparameterTuningMode, | ||
evaluationFunction: EvaluationFunction[T], | ||
evaluator: Evaluator, | ||
observations: Seq[(DenseVector[Double], Double)], | ||
priorObservations: Seq[(DenseVector[Double], Double)] = Seq(), | ||
discreteParams: Map[Int, Int] = Map()): Seq[T] | ||
} |
52 changes: 52 additions & 0 deletions
52
...c/main/scala/com/linkedin/photon/ml/hyperparameter/tuner/HyperparameterTunerFactory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2018 LinkedIn Corp. All rights reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linkedin.photon.ml.hyperparameter.tuner | ||
|
||
import com.linkedin.photon.ml.HyperparameterTunerName.{ATLAS, DUMMY, HyperparameterTunerName} | ||
|
||
object HyperparameterTunerFactory { | ||
|
||
// Use DUMMY_TUNER for photon-ml, which does an empty operation for hyper-parameter tuning | ||
val DUMMY_TUNER = "com.linkedin.photon.ml.hyperparameter.tuner.DummyTuner" | ||
|
||
// TODO: Move AtlasTuner into atlas-ml for the auto-tuning system migration: | ||
// TODO: val ATLAS_TUNER = "com.linkedin.atlas.ml.hyperparameter.tuner.AtlasTuner". | ||
// TODO: Temporarily stay in photon-ml for test purpose. | ||
val ATLAS_TUNER = "com.linkedin.photon.ml.hyperparameter.tuner.AtlasTuner" | ||
|
||
/** | ||
* Factory for different packages of [[HyperparameterTuner]]. | ||
* | ||
* @param tunerName The name of the auto-tuning package | ||
* @return The hyper-parameter tuner | ||
*/ | ||
def apply[T](tunerName: HyperparameterTunerName): HyperparameterTuner[T] = { | ||
|
||
val className = tunerName match { | ||
case DUMMY => DUMMY_TUNER | ||
case ATLAS => ATLAS_TUNER | ||
case other => throw new IllegalArgumentException(s"Invalid HyperparameterTuner name: ${other.toString}") | ||
} | ||
|
||
try { | ||
Class.forName(className) | ||
.newInstance | ||
.asInstanceOf[HyperparameterTuner[T]] | ||
} catch { | ||
case ex: Exception => | ||
throw new IllegalArgumentException(s"Invalid HyperparameterTuner class: $className", ex) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.