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)
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)
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)
# 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)
def run(self, input: List(MatrixContinuousDense())) -> Tensor3(): return np.vstack([np.expand_dims(m, axis=0) for m in input])
def run(self, input: List(ContinuousVector())) -> MatrixContinuousDense(): return np.vstack(input)
def run( self, input: Tuple(List(MatrixContinuousDense()), List(List(Postag()))) ) -> List(List(Postag())): return super().run(input)
def run( self, input: Tuple(MatrixContinuousDense(), CategoricalVector()) ) -> CategoricalVector(): return super().run(input)
def run( self, input: Tuple(MatrixContinuousDense(), CategoricalVector()) ) -> CategoricalVector(): X, y = input return y
def run(self, input: List(Flags())) -> MatrixContinuousDense(): return super().run(input)
def test_matrix_hierarchy(): assert conforms(MatrixContinuous(), Matrix()) assert conforms(MatrixContinuousSparse(), Matrix()) assert conforms(MatrixContinuousDense(), Matrix()) assert conforms(MatrixContinuousSparse(), MatrixContinuous()) assert conforms(MatrixContinuousDense(), MatrixContinuous())
def run(self, input: MatrixContinuousDense()) -> MatrixContinuousDense(): pass