samples4 = scaler.transform(
        np.random.multivariate_normal([5, -5], [[1, 0], [0, 1]], num_samples))
    y_sample = np.zeros((num_samples, 1))
    y_sample2 = np.zeros((num_samples, 1))
    y_sample3 = np.ones((num_samples, 1))
    y_sample4 = np.ones((num_samples, 1))

    x = np.vstack((samples, samples2, samples3, samples4))
    y = np.vstack((y_sample, y_sample2, y_sample3, y_sample4)).flatten()
    samplesA = np.vstack((samples, samples2))
    samplesB = np.vstack((samples3, samples4))
    x, y = shuffle(x, y)
    num_samples = len(x)

    split_id = int(holdout * num_samples / 100)
    x_test = x[:split_id]
    y_test = y[:split_id]
    x = x[split_id:]
    y = y[split_id:]
    return x, y, x_test, y_test


if __name__ == "__main__":

    # get dataset
    x_train, y_train, x_val, y_val = get_gaussians_dataset()
    dataset = DataSet().from_numpy(x_train, y_train, x_val=x_val, y_val=y_val)

    application = qnn.get_application("classification")
    application.solve(dataset)
Пример #2
0
import numpy as np
import matplotlib.pylab as plt

import prevision_quantum_nn as qnn

if __name__ == "__main__":

    # prepare data
    train_features = np.linspace(0, np.pi, 50)
    train_labels = np.asarray(np.sin(train_features))
    val_features = np.linspace(0, np.pi, 50)
    val_labels = np.asarray(np.sin(val_features))

    train_features = train_features.reshape((len(train_features), 1))
    val_features = val_features.reshape((len(val_features), 1))

    plt.plot(train_features, train_labels)
    plt.savefig("sinusoid.png")

    dataset = qnn.get_dataset_from_numpy(train_features,
                                         train_labels,
                                         val_features=val_features,
                                         val_labels=val_labels)
    # get application
    application = qnn.get_application("regression")
    application.solve(dataset)
Пример #3
0
        "encoding": "displacement",
        "snapshot_frequency": 5,
        "prefix": "sinusoid",
        "early_stopper_patience": 50,
        "use_early_stopper": True,
        "num_layers": 5,
        "interface": "autograd",
        "layer_type": "template",
    }

    # customize postprocessing
    postprocessing_params = {
        "phase_space_plotter": {
            "dim":
            1,
            "min_max_array": [[
                min(np.vstack([train_features, val_features])[:, 0]),
                max(np.vstack([train_features, val_features])[:, 0])
            ]]
        }
    }

    # get application
    application = qnn.get_application(
        "regression",
        prefix="sinusoid",
        model_params=model_params,
        postprocessing_params=postprocessing_params)

    application.solve(dataset)
Пример #4
0
    dataset_id = 1462

    # retrieve data
    dataset = oml.datasets.get_dataset(dataset_id)
    X, y, _, _ = dataset.get_data(dataset_format='array',
                                  target=dataset.default_target_attribute)

    # split train and validation
    train_features, val_features, train_labels, val_labels = \
        train_test_split(X, y, test_size=0.33, random_state=42)

    model_params = {
        "architecture": "qubit",
        "TYPE_problem": "classification",
        "num_q": 4,
        "encoding": "angle",
        "interface": "autograd",
        "num_layers": 3,
        "use_early_stopper": False,
        "val_verbose_period": 1,
    }

    dataset = qnn.get_dataset_from_numpy(train_features,
                                         train_labels,
                                         val_features=val_features,
                                         val_labels=val_labels)
    application = qnn.get_application("classification",
                                      prefix=f"openml_{dataset_id}",
                                      model_params=model_params)
    application.solve(dataset)
Пример #5
0
        "snapshot_frequency": 5,
        "verbose": True,
        "prefix": "moon",
        "num_layers": 4,
        "optimizer_name": "Adam",
        "learning_rate": 0.05,
    }

    # customize postprocessing
    postprocessing_params = {
        "phase_space_plotter": {
            "dim":
            2,
            "min_max_array": [[min(X[:, 0]), max(X[:, 0])],
                              [min(X[:, 1]), max(X[:, 1])]],
            "prefix":
            "moon"
        }
    }

    # build application
    application = qnn.get_application(
        "classification",
        prefix="moon",
        preprocessing_params=preprocessing_params,
        model_params=model_params,
        postprocessing_params=postprocessing_params)

    # solve application
    application.solve(dataset)
Пример #6
0
import gym
import prevision_quantum_nn as qnn

environment = gym.make("MountainCar-v0")

application = qnn.get_application("reinforcement_learning")
application.solve(environment, tqdm_verbose=True)
Пример #7
0
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import datasets

import prevision_quantum_nn as qnn

if __name__ == "__main__":

    # retrieve data and build dataset
    iris = datasets.load_iris()
    df = pd.DataFrame(iris.data)
    X = df.to_numpy()
    y = iris.target

    train_features, val_features, train_labels, val_labels = train_test_split(
        X, y, test_size=0.33, random_state=42)

    dataset = qnn.get_dataset_from_numpy(train_features,
                                         train_labels,
                                         val_features=val_features,
                                         val_labels=val_labels)

    application = qnn.get_application("multiclassification", prefix="iris")
    application.solve(dataset)
Пример #8
0
import gym
import prevision_quantum_nn as qnn

environment = gym.make("LunarLander-v2")

application = qnn.get_application("reinforcement_learning",
                                  prefix="lunar_lander_deep",
                                  rl_learner_type="deep")

application.solve(environment, render=True, tqdm_verbose=False)
Пример #9
0
import gym
import prevision_quantum_nn as qnn

environment = gym.make("LunarLander-v2")

model_params = {
    "architecture": "cv",
    "encoding": "displacement",
    "interface": "autograd",
    "num_layers": 3,
    "learning_rate": 0.001,
    "cutoff_dim": 4
}
application = qnn.get_application("reinforcement_learning",
                                  prefix="lunar_lander",
                                  model_params=model_params)

application.solve(environment, render=True, tqdm_verbose=False)
Пример #10
0
    # get dataset
    X, y = get_gaussians_dataset()

    x_train, x_val, y_train, y_val = train_test_split(X,
                                                      y,
                                                      test_size=0.25,
                                                      random_state=42)
    dataset = qnn.get_dataset_from_numpy(x_train,
                                         y_train,
                                         x_val=x_val,
                                         y_val=y_val)

    # get customized application
    preprocessing_params = {"polynomial_degree": 1}

    postprocessing_params = {
        "phase_space_plotter": {
            "dim":
            2,
            "min_max_array": [[min(X[:, 0]), max(X[:, 0])],
                              [min(X[:, 1]), max(X[:, 1])]]
        }
    }
    application = qnn.get_application(
        "classification",
        prefix="gaussians",
        preprocessing_params=preprocessing_params,
        postprocessing_params=postprocessing_params,
    )
    application.solve(dataset)