Esempio n. 1
0
def test_polimorphic_interface():
    interface = algorithm(MatrixContinuousDense(), MatrixContinuousDense())
    assert interface.is_compatible(ExactAlgorithm)
    assert interface.is_compatible(HigherInputAlgorithm)

    interface = algorithm(MatrixContinuousDense(), MatrixContinuous())
    assert interface.is_compatible(LowerOutputAlgorithm)
Esempio n. 2
0
def test_simple_pipeline_graph():
    graph = build_pipeline_graph(input=MatrixContinuousDense()
                                 ,output= MatrixContinuousDense()
                                 ,registry=[ExactAlgorithm, HigherInputAlgorithm, LowerOutputAlgorithm]).graph
    assert_graph(graph, 3, 3, 6)
    
    graph = build_pipeline_graph(input=List(Text())
                                 ,output= Document()
                                 ,registry=[WordToWordAlgorithm, 
                                            TextToWordAlgorithm, 
                                            WordToWordListAlgorithm,
                                            WordListToSentenceAlgorithm,
                                            WordListToSentenceAlgorithm,
                                            SentenceListToDocumentAlgorithm,
                                            TextListToDocumentAlgorithm]).graph
    assert_graph(graph, 2, 2, 12)
    
    graph = build_pipeline_graph(input=List(Word())
                                 ,output=Document()
                                 ,registry=[WordToWordAlgorithm, 
                                            TextToWordAlgorithm, 
                                            WordToWordListAlgorithm,
                                            WordListToSentenceAlgorithm,
                                            WordListToSentenceAlgorithm,
                                            SentenceListToDocumentAlgorithm,
                                            TextListToDocumentAlgorithm]).graph
    assert_graph(graph, 2, 1, 10)
Esempio n. 3
0
def test_save_load_tuple():
    TupleClass = build_composite_tuple(
        1,
        input_type=Tuple(MatrixContinuousDense(), CategoricalVector()),
        output_type=Tuple(MatrixContinuousDense(), CategoricalVector()),
    )
    algorithm = TupleClass(DummyAlgorithm)

    fp = BytesIO()

    Pickler(fp).dump(algorithm)
    fp.seek(0)

    algorithm2 = Unpickler(fp).load()

    assert repr(algorithm) == repr(algorithm2)
Esempio n. 4
0
# import high-level API
from autogoal.ml import AutoML
from autogoal.kb import MatrixContinuousDense, CategoricalVector

# load data
from autogoal.datasets import cars
X, y = cars.load()

# instantiate AutoML class
automl = AutoML(
    input=MatrixContinuousDense(),
    output=CategoricalVector(),
    # ... other parameters and constraints
)

# fit the model
automl.fit(X, y)

# save the best model
with open("model.bin", "wb") as fp:
    automl.save(fp)
Esempio n. 5
0
 def run(self, input: List(MatrixContinuousDense())) -> Tensor3():
     return np.vstack([np.expand_dims(m, axis=0) for m in input])
Esempio n. 6
0
 def run(self, input: List(ContinuousVector())) -> MatrixContinuousDense():
     return np.vstack(input)
Esempio n. 7
0
 def run(
     self, input: Tuple(List(MatrixContinuousDense()), List(List(Postag())))
 ) -> List(List(Postag())):
     return super().run(input)
Esempio n. 8
0
 def run(
     self, input: Tuple(MatrixContinuousDense(), CategoricalVector())
 ) -> CategoricalVector():
     return super().run(input)
Esempio n. 9
0
 def run(
     self, input: Tuple(MatrixContinuousDense(), CategoricalVector())
 ) -> CategoricalVector():
     X, y = input
     return y
Esempio n. 10
0
 def run(self, input: List(Flags())) -> MatrixContinuousDense():
     return super().run(input)
Esempio n. 11
0
def test_matrix_hierarchy():
    assert conforms(MatrixContinuous(), Matrix())
    assert conforms(MatrixContinuousSparse(), Matrix())
    assert conforms(MatrixContinuousDense(), Matrix())
    assert conforms(MatrixContinuousSparse(), MatrixContinuous())
    assert conforms(MatrixContinuousDense(), MatrixContinuous())
Esempio n. 12
0
 def run(self, input: MatrixContinuousDense()) -> MatrixContinuousDense():
     pass