Skip to content

pyjuan91/Bayesian-Optimization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bayesian-Optimization

This is a numerical optimization template that can be used in experiments for a general Chinese medicine course. It utilizes principles similar to Bayesian Optimization and employs the Multilayer perceptron for machine learning.

All rights are reserved by my high school classmate and former college roommate, Colin.
所有權由我的高中同學兼大學前室友 Colin 所保留

Brief of Steps

1. Adjust the range of three parameters. (in experiment.py)

The default range is real numbers.
In this case [-10.0, $\pi$, ... , 9.9, 10.0] are inclusive.

class Params:
    PARAM1_RANGE = (-10, 10)
    PARAM2_RANGE = (-10, 10)
    PARAM3_RANGE = (-10, 10)

    def __init__(self, param1, param2, param3):
        if not (Params.PARAM1_RANGE[0] <= param1 <= Params.PARAM1_RANGE[1]):
            raise ValueError(f"param1 must be in the range {Params.PARAM1_RANGE}")
        self.param1 = param1
        if not (Params.PARAM2_RANGE[0] <= param2 <= Params.PARAM2_RANGE[1]):
            raise ValueError(f"param2 must be in the range {Params.PARAM2_RANGE}")
        self.param2 = param2
        if not (Params.PARAM3_RANGE[0] <= param3 <= Params.PARAM3_RANGE[1]):
            raise ValueError(f"param3 must be in the range {Params.PARAM3_RANGE}")
        self.param3 = param3

2. Determine Blackbox Function

Based on the experimental results generated by the three parameters, you need to give a score to these results. In this context, it could be the time it takes for the temperature to stop oscillating, the extent to which the temperature exceeds the upper limit, and so on...

You can convert the experimental MATLAB code to Python or use libraries to integrate the results.

class Experiment:
    def __init__(self, params: Params):
        self.params = params

    def run(self):
        # Selfdefined function
        # TODO: Implement the function
        x1 = self.params.param1
        x2 = self.params.param2
        x3 = self.params.param3
        return -(x1**2 + x2**2 + x3**2) + 10  # Example: maximized when x1=x2=x3=0

3. Run Main

Install the required packages.

pip install -r requirements.txt

Execute main.py.

python main.py

What are Main doing?

  1. Define the Problem and Blackbox Function: You need a clear definition of your three parameters and the blackbox function that evaluates them.

  2. Generate Initial Data: Create an initial set of data points by sampling the parameter space.

  3. Model the Evaluation Function: Use a machine learning model to approximate the blackbox function based on your initial data. A simple choice can be a linear regression or a neural network.

  4. Optimization Algorithm: Use an optimization algorithm to find the parameters that maximize the evaluation function. Bayesian Optimization is a good choice for blackbox optimization problems.

  5. Iterative Improvement: Iteratively update your model with new data points obtained by evaluating the blackbox function at the predicted optimal parameters.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages