Esempio n. 1
0
def copy_to_cpp(indvs_python):
    indvs_cpp = []
    for indv in indvs_python:
        agraph_cpp = bingocpp.AGraph()
        agraph_cpp.genetic_age = indv.genetic_age
        agraph_cpp.fitness = indv.fitness if indv.fitness != None else 1e9
        agraph_cpp.fit_set = indv.fit_set
        agraph_cpp.set_local_optimization_params(indv.constants)
        agraph_cpp.command_array = indv.command_array
        indvs_cpp.append(agraph_cpp)
    return indvs_cpp
Esempio n. 2
0
def sample_agraph_1_cpp():
    if bingocpp == None:
        return None
    test_graph = bingocpp.AGraph()
    test_graph.command_array = np.array([
        [0, 0, 0],  # sin(X_0 + 1.0) + 1.0
        [1, 0, 0],
        [2, 0, 1],
        [6, 2, 2],
        [2, 0, 1],
        [2, 3, 1]
    ])
    test_graph.genetic_age = 10
    test_graph.set_local_optimization_params([
        1.0,
    ])
    test_graph.fitness = 1
    return test_graph
Esempio n. 3
0
def sample_agraph_2_cpp():
    if bingocpp == None:
        return None
    test_graph = bingocpp.AGraph()
    return _set_sample_agraph_2_data(test_graph)
Esempio n. 4
0
def all_funcs_agraph_cpp():
    if bingocpp == None:
        return None
    test_graph = bingocpp.AGraph()
    return _set_all_funcs_agraph_data(test_graph)
Esempio n. 5
0
def invalid_agraph_cpp(sample_agraph_1_cpp):
    if bingocpp == None:
        return None
    test_graph = bingocpp.AGraph()
    test_graph.command_array = sample_agraph_1_cpp.command_array
    return test_graph
Esempio n. 6
0
def test_cpp_agraph_could_be_imported():
    assert CPP_LOADED and bingocpp.AGraph() is not None
Esempio n. 7
0
# Ignoring some linting rules in tests
# pylint: disable=redefined-outer-name
# pylint: disable=missing-docstring
from collections import namedtuple
import pytest
import numpy as np

from bingo.symbolic_regression.agraph import agraph, backend as py_backend
try:
    from bingocpp.build import bingocpp as bingocpp
    cpp_agraph = bingocpp.AGraph()
    CPP_LOADED = True
except ImportError:
    bingocpp = None
    CPP_LOADED = False
    cpp_agraph = None

agraph.Backend = py_backend
EVALUATE = "bingo.symbolic_regression.agraph.agraph.Backend.evaluate"
EVALUATE_WTIH_DERIV = ("bingo.symbolic_regression.agraph.agraph.Backend."
                       "evaluate_with_derivative")


@pytest.fixture
def invalid_agraph(sample_agraph_1):
    test_graph = agraph.AGraph()
    test_graph.command_array = sample_agraph_1.command_array
    return test_graph


@pytest.fixture
Esempio n. 8
0
 def _cpp_generator_function(self):
     return bingocpp.AGraph(self._manual_constants)