Skip to content

space_mapping

Implementation of an aggressive space mapping algorithm for RF-design

cost_calc(perf_list, goal_list, weight_list=None) cached

return the normalize standard deviation between the perf_list and the goal_list

Parameters:

Name Type Description Default
perf_list tuple of float

list of the performances achieved.

required
goal_list tuple of float

list of the goal to be achieved. If one value is given, the goal is a point. If two, the goal is an interval.

required
weight_list tuple of float, optional

weightning of the goals. If set to None, all the weight are set to one.

None

Returns:

Name Type Description
cost float

cost value

Source code in passive_auto_design\space_mapping.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
@functools.lru_cache()
def cost_calc(perf_list, goal_list, weight_list=None):
    """
    return the normalize standard deviation between the perf_list and the goal_list

    Parameters
    ----------
    perf_list : tuple of float
        list of the performances achieved.
    goal_list : tuple of float
        list of the goal to be achieved. If one value is given, the goal is a point. If two, the goal is an interval.
    weight_list : tuple of float, optional
        weightning of the goals. If set to None, all the weight are set to one.

    Returns
    -------
    cost : float
        cost value

    """
    if weight_list is None:
        weight_list = [1] * len(goal_list)
    cost = 0
    for itern, goal in enumerate(goal_list):
        perf = perf_list[itern]
        goal = goal_list[itern]
        if isinstance(goal, tuple):
            err_min = max((perf - goal[0]) / (goal[0] if goal[0] != 0 else 1), 0)
            err_max = max((goal[1] - perf) / (goal[1] if goal[1] != 0 else 1), 0)
            err = err_min + err_max
        else:
            err = (perf - goal) / (goal if goal != 0 else 1)
        cost += weight_list[itern] * err**2
    return cost

space_map(coarse_model, dim0, fine_model, par0, goal, maxiter=5)

Optimization function for space mapping algorithm.

Parameters:

Name Type Description Default
coarse_model fun

function evaluating the coarse model goals for a set of dimensions (dim) and parameters (par)

required
dim0 dict

initial dimensions of the component

required
fine_model fun

function evaluating the fine model goals for a set of dimensions (dim)

required
par0 dict

initial parameters of the component coarse model

required
goal dict

set of goal targeted by the algorithm

required
maxiter int, optional

maximal number of iteration. The default is 5.

5

Returns:

Name Type Description
dim dict

final dimension of the component.

par dict

final parameters of the component model.

fine_mod dict

achieved goal.

Source code in passive_auto_design\space_mapping.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def space_map(coarse_model, dim0, fine_model, par0, goal, maxiter=5):
    """
    Optimization function for space mapping algorithm.

    Parameters
    ----------
    coarse_model : fun
        function evaluating the coarse model goals
        for a set of dimensions (dim) and parameters (par)
    dim0 : dict
        initial dimensions of the component
    fine_model : fun
        function evaluating the fine model goals
        for a set of dimensions (dim)
    par0 : dict
        initial parameters of the component coarse model
    goal : dict
        set of goal targeted by the algorithm
    maxiter : int, optional
        maximal number of iteration. The default is 5.

    Returns
    -------
    dim : dict
        final dimension of the component.
    par : dict
        final parameters of the component model.
    fine_mod : dict
        achieved goal.

    """
    dim = dim0
    par = par0
    achieved_goal = goal
    for i in range(maxiter):
        # evaluate exact value using fine model
        achieved_goal = fine_model(dim)
        # alter coarse model parameters to better match fine model results
        res = minimize(
            __refresh_coarse,
            __totuple(par),
            method="L-BFGS-B",
            args=(par0.keys(), dim, coarse_model, achieved_goal),
        )
        par = __todict(par0.keys(), res.x)
        # find best solution according to coarse model
        res = minimize(
            __cost_coarse,
            __totuple(dim),
            method="Powell",
            args=(dim0.keys(), par, coarse_model, goal),
        )
        dim = __todict(dim0.keys(), res.x)
    return dim, par, achieved_goal