Skip to content

Instantly share code, notes, and snippets.

def get_cost(target,Q,action_indices):
"""
Cost-function of the Q-matrix attempting to approximate the reward-function
:param tf.placeholder target: placeholder for the values of the registered rewards
:param tf.placeholder Q: output of the Q-matrix the registered state
:param tf.placeholder action_indices: placeholder for the indices of the registered actions
:return: tf.tensor mean_squared error the reward vs Q-matrix
"""
row_indices = tf.range(tf.shape(action_indices)[0])
full_indices = tf.stack([row_indices, action_indices], axis=1)
def define_Q(input_shape=(16,16)):
"""
Defines the Q-matrix and returns the input and output tensorflow tensors.
Args:
:param Tuple input_shape:
:return: Tuple[tf.tensor, tf.tensor]
"""
input = tf.placeholder(shape=(None,)+input_shape+(1,), dtype=tf.float32)
nn_1 = tf.layers.batch_normalization(input)

Keybase proof

I hereby claim:

  • I am benoitdescamps on github.
  • I am bendesc (https://keybase.io/bendesc) on keybase.
  • I have a public key ASCc_8P9Faka2-t-le6Gl-HtTVsKBjTMR_207ktVS57SOwo

To claim this, I am signing this object:

@benoitdescamps
benoitdescamps / randomSearch_lgbm
Created May 11, 2018 21:46
code snippet for Hyperparameters (part II): Random Search on Spark
import breeze.stats.distributions.{Gamma,Uniform,Poisson}
import com.microsoft.ml.spark.LightGBMClassifier
import tuning.RandomGridBuilder
object example_lgbm{
def main(args: Array[String]): Unit = {
val lgbm = new LightGBMClassifier()
val randomGrid = new RandomGridBuilder(5)
.addDistr(lgbm.learningRate,Gamma(1.0,0.1))
@benoitdescamps
benoitdescamps / randomSearch_RandomGridBuilder
Created May 11, 2018 21:44
code snippet for Hyperparameters (part II): Random Search on Spark
class RandomGridBuilder(n: Int) {
private val paramDistr = mutable.Map.empty[Param[_],Any]
def addDistr[T](param: Param[T], distr: Any ): this.type = distr match {
case _ : Rand[_] => {paramDistr.put(param, distr)
this}
case _ : Array[_] => { paramDistr.put(param, distr)
this}
case _ => throw new NotImplementedError("Distribution should be of type breeze.stats.distributions.Rand or an Array")
@benoitdescamps
benoitdescamps / randomSearch_logisticReg
Created May 11, 2018 21:43
code snippet for Hyperparameters (part II): Random Search on Spark
val lr = new LogisticRegression().setMaxIter(10)
val randomGrid = new RandomGridBuilder(10)
.addDistr(lr.regParam,Gamma(0.5,0.1))
.addDistr(lr.elasticNetParam,Gamma(0.5,0.1))
.addDistr(lr.threshold,Gaussian(0.5,0.05))
.addDistr(lr.standardization,Array(true,false))
.build()
@benoitdescamps
benoitdescamps / randomSearch_sparkml
Created May 11, 2018 21:41
code snippets for Hyperparameters (part II): Random Search on Spark
import org.apache.spark.ml.Pipeline
import org.apache.spark.ml.tuning.CrossValidatorModel
import org.apache.spark.ml.param.ParamMap
val pipeline: Pipeline = ...
val paramGrid: Array[ParamMap] = new ParamGridBuilder().
addGrid(...).
addGrid(...).
build
@benoitdescamps
benoitdescamps / SuccessiveHalving_illustration
Created May 8, 2018 16:47
code snippet for Tuning Hyperparameters (part I): SuccessiveHalving
class SuccessiveHalving(object):
"""Applies successhalving on a model for n configurations max r ressources.
Args:
estimator: object instance with subclass SHBaseEstimator:
estimator wrapper
n: integer:
number of hyperparameter configurations to explore
r: integer:
@benoitdescamps
benoitdescamps / SHSklearnEstimator_illustration
Created May 8, 2018 16:47
code snippet for Tuning Hyperparameters (part I): SuccessiveHalving
class SHSklearnEstimator(SHBaseEstimator):
def __init__(self,model,ressource_name=None):
self.model = model
self.ressource_name = ressource_name
self.env = None
def update(self,Xtrain,ytrain,Xval,yval,scoring,n_iterations):
self.set_params(**{'warm_start':True,self.ressource_name:n_iterations})
self.model.fit(Xtrain,ytrain)
@benoitdescamps
benoitdescamps / SHSklearnEstimato_illustration
Created May 8, 2018 16:46
code snippet for Tuning Hyperparameters (part I): SuccessiveHalving
class SHSklearnEstimator(SHBaseEstimator):
def __init__(self,model,ressource_name=None):
self.model = model
self.ressource_name = ressource_name
self.env = None
def update(self,Xtrain,ytrain,Xval,yval,scoring,n_iterations):
self.set_params(**{'warm_start':True,self.ressource_name:n_iterations})
self.model.fit(Xtrain,ytrain)