Exemple #1
0
    def __init__(self, activation_type="Relu", polynom_type="polyfit"):
        self.counter = 0
        self.bytes = 0
        self.activation_type = activation_type
        self.polynom_type = polynom_type
        self.ready_jobs = queue.Queue()
        if activation_type == "Relu":
            if polynom_type == "polyfit":
                self.activation = relu_activation.get_approx_func_polyfit()
                self.coefficients = self.activation.get_polyfit_coefficients()
                self.func = sigmoid.eval_polyfit_extern
            elif polynom_type == "chebyshev":
                self.activation = relu_activation.get_approx_func(
                    settings.max_degree)
                self.coefficients = self.activation.get_coefficients()
                self.func = chebyshev.eval_extern
        elif activation_type == "Sigmoid":
            if polynom_type == "chebyshev":
                self.activation = sigmoid_activation.get_approx_func_chebyshev(
                    settings.max_degree)
                self.coefficients = self.activation.get_coefficients()
                self.func = chebyshev.eval_extern

        # create n threads and assign them coefficients
        self.coefs = divide_coefficients(self.coefficients,
                                         settings.num_threads)
        self.threads = []
        self.threads_created = False
Exemple #2
0
def get_relu_activation_numpy(max_degree=settings.max_degree):
    if not max_degree:
        max_degree = settings.max_degree
    if not get_relu_activation_numpy.activation:
        get_relu_activation_numpy.activation = relu_activation.get_approx_func(
            max_degree)
    return get_relu_activation_numpy.activation
Exemple #3
0
    elif activation_name == "sigmoid":
        return _apply_activation_model(
            model,
            sigmoid_cheb_mediator,
            "Sigmoid",
            custom_objects={"sigmoid_cheb_mediator": sigmoid_cheb_mediator})
    else:
        print("Unknown activation option: " + activation_name)
        return model


if __name__ == "__main__":
    register_activations()
    print("test polyfit")
    dummy = relu_activation.get_approx_func_polyfit()
    print(dummy(10))
    mediator = MultiPartyMediator()
    print(mediator.start(10))

    print("test chebyshev Relu")
    dummy = relu_activation.get_approx_func(settings.max_degree)
    print(dummy(10))
    mediator = MultiPartyMediator("Relu", "chebyshev")
    print(mediator.start(10))

    print("test chebyshev Sigmoid")
    dummy = sigmoid_activation.get_approx_func_chebyshev(settings.max_degree)
    print(dummy(10))
    mediator = MultiPartyMediator("Sigmoid", "chebyshev")
    print(mediator.start(10))
Exemple #4
0
def test_relu():
    test_set = create_test_set(num_examples, max_value)
    run_test(test_set, relu_activation.get_approx_func(), relu_activation.get_real_func(), "Relu")
Exemple #5
0
def test_range_relu(min_degree, max_degree, step):
    test_set = settings.create_test_set(settings.num_examples, max_value)
    approx_funcs = []
    for degree in range(min_degree, max_degree, step):
        approx_funcs.append( (relu_activation.get_approx_func(degree), "Poly Degree: %s" % (degree)) )
    run_multi_test(test_set, approx_funcs, relu_activation.get_real_func(), "Relu-Chebyshev")
Exemple #6
0
def test_relu(max_degree):
    test_set = settings.create_test_set(settings.num_examples, max_value)
    run_test(test_set, relu_activation.get_approx_func(max_degree), relu_activation.get_real_func(), "Relu-Chabyshev")