Skip to content

Commit

Permalink
Append new examples. Correct documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Audice committed Jan 26, 2024
1 parent 90f7880 commit c9cbbfe
Show file tree
Hide file tree
Showing 26 changed files with 1,025 additions and 26 deletions.
901 changes: 897 additions & 4 deletions docs/source/examples.rst

Large diffs are not rendered by default.

Binary file added docs/source/images/LL-regression3d.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/general_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/grid_search_up.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/hyperopt1000_1.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/hyperopt_11.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/iOpt_1000_1.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/iter500_1.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/ll_infograph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/optuna1000_1.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/optuna_11.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/prev2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/regression-3d.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions examples/Machine_learning/SVC/_2D/Example_2D_SVC.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ def load_breast_cancer_data():
x, y = load_breast_cancer_data()
regularization_value_bound = {'low': 1, 'up': 6}
kernel_coefficient_bound = {'low': -7, 'up': -3}

problem = SVC_2d.SVC_2D(x, y, regularization_value_bound, kernel_coefficient_bound)

method_params = SolverParameters(r=np.double(3.0), iters_limit=100)
solver = Solver(problem, parameters=method_params)

apl = AnimatePainterNDListener("svc2d_anim.png", "output", vars_indxs=[0, 1], to_paint_obj_func=False)
solver.add_listener(apl)

spl = StaticPainterNDListener("svc2d_stat.png", "output", vars_indxs=[0, 1], mode="surface", calc="interpolation")
solver.add_listener(spl)

cfol = ConsoleOutputListener(mode='full')
solver.add_listener(cfol)

solver_info = solver.solve()
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from iOpt.output_system.listeners.static_painters import StaticPainterNDListener
from iOpt.output_system.listeners.animate_painters import AnimatePainterNDListener
from iOpt.output_system.listeners.console_outputers import ConsoleOutputListener
from iOpt.output_system.listeners.static_painters import StaticDiscreteListener

from iOpt.solver import Solver
from iOpt.solver_parametrs import SolverParameters
Expand Down Expand Up @@ -30,7 +28,7 @@ def factory_dataset():
kernel_coefficient_bound = {'low': -3, 'up': 1}
problem = SVC_2D_Transformators_State.SVC_2D_Transformators_State(X, Y, regularization_value_bound,
kernel_coefficient_bound)
method_params = SolverParameters(r=np.double(2.0), iters_limit=2000, number_of_parallel_points=5,
method_params = SolverParameters(r=np.double(2.0), iters_limit=100, number_of_parallel_points=12,
evolvent_density=12)
solver = Solver(problem=problem, parameters=method_params)
spl1 = StaticPainterNDListener("svc2d_transformator_state_stat1.png", "output", vars_indxs=[0, 1], mode="surface",
Expand All @@ -39,9 +37,14 @@ def factory_dataset():
spl2 = StaticPainterNDListener("svc2d_transformator_state_stat2.png", "output", vars_indxs=[0, 1], mode="lines layers",
calc="by points")
solver.add_listener(spl2)
log = "SVC_2D_Transformators_2000"
solver.load_progress(log) # загружаем точки из файла в солвер
solver.release_all_listener() # запускаем подключенных слушаетей

cfol = ConsoleOutputListener(mode='full')
solver.add_listener(cfol)
solver_info = solver.solve()

#log = "SVC_2D_Transformators_2000"
#solver.load_progress(log) # загружаем точки из файла в солвер
#solver.release_all_listener() # запускаем подключенных слушаетей

'''
X, Y = factory_dataset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from sklearn.svm import SVC
from sklearn.model_selection import cross_val_score
from typing import Dict
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import StratifiedKFold

class SVC_2D_Transformators_State(Problem):
"""
Expand Down Expand Up @@ -43,6 +42,8 @@ def __init__(self, x_dataset: np.ndarray, y_dataset: np.ndarray,
self.upper_bound_of_float_variables = np.array([regularization_bound['up'], kernel_coefficient_bound['up']],
dtype=np.double)

self.cv = StratifiedKFold(shuffle=True, random_state=42)



def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValue:
Expand All @@ -54,5 +55,5 @@ def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValu
"""
cs, gammas = point.float_variables[0], point.float_variables[1]
clf = SVC(C=10 ** cs, gamma=10 ** gammas)
function_value.value = -cross_val_score(clf, self.x, self.y, scoring='f1_macro').mean()
function_value.value = -cross_val_score(clf, self.x, self.y, cv=self.cv, scoring='f1_macro').mean()
return function_value
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ def gasturbine_Dataset():
learning_rate_bound = {'low': 0.2, 'up': 0.4}
gamma_bound = {'low': 0.2, 'up': 0.3}
problem = XGBR_2d_Gasturbine(X, Y, learning_rate_bound, gamma_bound)
method_params = SolverParameters(r=np.double(2.0), iters_limit=200)
solver = Solver(problem, parameters=method_params)
apl = AnimatePainterNDListener("XGBR_2d_Gasturbine_anim.png", "output", vars_indxs=[0, 1])
solver.add_listener(apl)
spl = StaticPainterNDListener("XGBR_2d_Gasturbine_stat.png", "output", vars_indxs=[0, 1], mode="surface", calc="interpolation")
solver.add_listener(spl)
method_params = SolverParameters(r=np.double(2.0), iters_limit=1000, number_of_parallel_points=12,
evolvent_density=12)
solver = Solver(problem=problem, parameters=method_params)
spl1 = StaticPainterNDListener("gas_regr.png", "output", vars_indxs=[0, 1], mode="surface",
calc="by points")
solver.add_listener(spl1)
spl2 = StaticPainterNDListener("gas_regr2.png", "output", vars_indxs=[0, 1], mode="lines layers",
calc="by points")
solver.add_listener(spl2)

cfol = ConsoleOutputListener(mode='full')
solver.add_listener(cfol)
solver_info = solver.solve()
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValu
"""
learning_rate, gamma = point.float_variables[0], point.float_variables[1]
regr = xgb.XGBRegressor(learning_rate=learning_rate, gamma=gamma)
function_value.value = -cross_val_score(regr, self.x, self.y, scoring='r2').mean()
function_value.value = -cross_val_score(regr, self.x, self.y, scoring='r2', cv=5).mean()
return function_value
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from examples.Machine_learning.XGBoostRegression._3D.Problems import XGB_3D
from iOpt.output_system.listeners.console_outputers import ConsoleOutputListener
from iOpt.output_system.listeners.static_painters import StaticDiscreteListener
from iOpt.solver import Solver
from iOpt.solver_parametrs import SolverParameters
from sklearn.utils import shuffle
import numpy as np
import csv

def gasturbine_Dataset():
x = []
y = []
with open(r"../Datasets/no_predict.csv") as file:
file_reader = csv.reader(file, delimiter=";")
for row in file_reader:
x_row = []
for i in range(len(row)-1):
x_row.append(row[i])
x.append(x_row)
y.append(row[len(row)-1])
return shuffle(np.array(x, dtype=np.float32), np.array(y, dtype=np.float32), random_state=42)


if __name__ == "__main__":
X, Y = gasturbine_Dataset()
learning_rate_bound = {'low': 0.2, 'up': 0.4}
gamma_bound = {'low': 0.2, 'up': 0.3}
booster_type = {'booster': ['gblinear', 'gbtree', 'dart']}

problem = XGB_3D.XGB_3D(X, Y, learning_rate_bound, gamma_bound, booster_type)
method_params = SolverParameters(r=np.double(2.0), iters_limit=1000, number_of_parallel_points=16,
evolvent_density=12)
solver = Solver(problem, parameters=method_params)
apl = StaticDiscreteListener("experiment1.png", mode='analysis')
solver.add_listener(apl)
apl = StaticDiscreteListener("experiment2.png", mode='bestcombination', calc='interpolation', mrkrs=4)
solver.add_listener(apl)
cfol = ConsoleOutputListener(mode='full')
solver.add_listener(cfol)
solver_info = solver.solve()
64 changes: 64 additions & 0 deletions examples/Machine_learning/XGBoostRegression/_3D/Problems/XGB_3D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import numpy as np
import xgboost as xgb
from iOpt.trial import Point
from iOpt.trial import FunctionValue
from iOpt.problem import Problem
from sklearn.svm import SVC
from sklearn.model_selection import cross_val_score
from typing import Dict, List
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import r2_score

class XGB_3D(Problem):
"""
Класс XGB_3D представляет возможность поиска оптимального набора гиперпараметров алгоритма XGBoost regression
Найденные параметры являются оптимальными при варьировании параматра скорости обучения
(learning_rate), коэфицента определения минимального снижения потерь (gamma) и типа модели (booster)
"""

def __init__(self, x_dataset: np.ndarray, y_dataset: np.ndarray,
learning_rate_bound: Dict[str, float],
gamma_bound: Dict[str, float],
booster_type: Dict[str, List[str]]
):
"""
Конструктор класса SVC_3D
:param x_dataset: входные данные обучающе выборки метода SVC
:param y_dataset: выходные данные обучающе выборки метода SVC
:param learning_rate_bound: Границы изменения значений параметра скорости обучения
:param gamma_bound: Границы изменения значений параметра gамма, определяющего минимальное снижение потерь
:param booster_type: Тип модели, для каждой итерации алгоритма XGBoost
"""
super(XGB_3D, self).__init__()
self.dimension = 3
self.number_of_float_variables = 2
self.number_of_discrete_variables = 1
self.number_of_objectives = 1
self.number_of_constraints = 0
if x_dataset.shape[0] != y_dataset.shape[0]:
raise ValueError('The input and output sample sizes do not match.')
self.x = x_dataset
self.y = y_dataset
self.float_variable_names = np.array(["learning_rate", "gamma"], dtype=str)
self.lower_bound_of_float_variables = np.array([learning_rate_bound['low'], gamma_bound['low']],
dtype=np.double)
self.upper_bound_of_float_variables = np.array([learning_rate_bound['up'], gamma_bound['up']],
dtype=np.double)
self.discrete_variable_names.append('booster')
self.discrete_variable_values.append(booster_type['booster'])


def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValue:
"""
Метод расчёта значения целевой функции в точке
:param point: Точка испытания
:param function_value: объект хранения значения целевой функции в точке
"""
learning_rate, gamma = point.float_variables[0], point.float_variables[1]
booster = point.discrete_variables[0]
regr = xgb.XGBRegressor(learning_rate=learning_rate, gamma=gamma, booster=booster)
function_value.value = -cross_val_score(regr, self.x, self.y, scoring='r2', cv=5).mean()
return function_value
Empty file.
Empty file.

0 comments on commit c9cbbfe

Please sign in to comment.