hyperparams = { 'circuit': circuit, 'task': 'supervised', 'loss': myloss, 'optimizer': 'SGD', 'init_learning_rate': 0.5, 'decay': 0.01, 'print_log': True, 'log_every': 10, 'warm_start': False } learner = CircuitLearner(hyperparams=hyperparams) learner.train_circuit(X=X_train, Y=Y_train, steps=steps, batch_size=batch_size) test_score = learner.score_circuit( X=X_test, Y=Y_test, outputs_to_predictions=outputs_to_predictions) # The score_circuit() function returns a dictionary of different metrics. print("\nPossible scores to print: {}".format(list(test_score.keys()))) # We select the accuracy and loss. print("Accuracy on test set: ", test_score['accuracy']) print("Loss on test set: ", test_score['loss']) outcomes = learner.run_circuit(X=X_pred, outputs_to_predictions=outputs_to_predictions) # The run_circuit() function returns a dictionary of different outcomes. print("\nPossible outcomes to print: {}".format(list(outcomes.keys()))) # We select the predictions print("Predictions for new inputs: {}".format(outcomes['predictions']))
def get_cost(self, steps): learner = CircuitLearnerTF(hyperparams=self.hyperp) learner.train_circuit(X=self.X, Y=self.Y, steps=steps) evalu = learner.score_circuit(X=self.X, Y=self.Y) cost = evalu['loss'] return cost
hyperparams = {'circuit': circuit, 'task': 'supervised', 'loss': myloss, 'optimizer': 'SGD', 'init_learning_rate': 0.01, 'print_log': False} # Create a learner learner = CircuitLearner(hyperparams=hyperparams) # Train the learner print("Training on: X{0} Y{1}".format(X_train, Y_train)) learner.train_circuit(X=X_train, Y=Y_train, steps=steps) # Get the accuracy and loss for the test data test_score = learner.score_circuit(X=X_test, Y=Y_test, outputs_to_predictions=outputs_to_predictions) # The score_circuit() function returns a dictionary of different metrics. print("\nPossible scores to print: {}".format(list(test_score.keys()))) # We select the accuracy and loss. print("Accuracy on test set: ", test_score['accuracy']) print("Loss on test set: ", test_score['loss']) outcomes = learner.run_circuit(X=X_pred, outputs_to_predictions=outputs_to_predictions) print("Predicting based on X_Predict{0}".format(X_pred)) # The run_circuit() function returns a dictionary of different outcomes. print("\nPossible outcomes to print: {}".format(list(outcomes.keys()))) # We select the predictions print("Predictions for new inputs: {}".format(outcomes['predictions']))