# Training a numpy function with hyperopt

**URL:** <https://discuss.ray.io/t/training-a-numpy-function-with-hyperopt/4009>\
**Category:** Ray Tune\
**Created:** [November 1, 2021, 1:31pm UTC](https://discuss.ray.io/t/training-a-numpy-function-with-hyperopt/4009 "2021-11-01T13:31:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anurag\_Ranjak](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/anurag_ranjak/32/697_2.png) [@Anurag\_Ranjak](https://discuss.ray.io/u/Anurag_Ranjak)\
**Post date:** [November 1, 2021, 1:31pm UTC](https://discuss.ray.io/t/training-a-numpy-function-with-hyperopt/4009/1 "2021-11-01T13:31:46Z")

</div>

I am optimizing the hyperparameters for a numpy function that performs some template matching.

My function looks like -

```auto
def img_reg(im1, im2, config):
    hype1 = config["hype1"]
    hype2 = config["hype2"]
    ###. some computation ###
    return {"loss": loss, "status": STATUS_OK}

def trainable_hyperopt(config):
     for i in range(config["iterations"]):
         score = img_reg(im1, im2, config)
         tune.report(iterations = i, loss = score)

hyperopt_search = HyperOptSearch( metric="loss/loss", mode="min", n_initial_points = 20)

space = {"grad_step": hp.loguniform("grad_step",np.log(1e-4), np.log(1e-1)),
          "gc_metric_weight": hp.normal("gc_metric_weight", .1, 1e-2),
          "update_field_variance": hp.normal("update_field_variance", 10, 2)
        }
config = {
        "num_samples": 2,
        "config": {
            "iterations": 10
        }
    }
algo = HyperOptSearch(
        space,
       
        metric="loss/loss",
        mode="min",
        )

analysis = tune.run(trainable_hyperopt, search_alg=algo, **config, metric = "loss/loss", mode = "min")

```

When i run this code. It fires up two samples with some initial values but no optimization of those values with hyperopt happens. At the end of the run it just returns one of the two values with the lower scores. Can you please help me with what might be going wrong.
