Пример #1
0
def plot_gtm(config, pca_data, labels, ids):
    regul = 0.1
    niter = 1000
    gtm = ugtm.runGTM(
        data=pca_data,
        k=config.k,
        m=config.m,
        s=config.rbf_width_factor,
        regul=regul,
        niter=niter,
        doPCA=False,
        n_components=config.pca_n_components,
        missing=config.missing,
        missing_strategy=config.missing_strategy,
        random_state=config.random_state,
        verbose=config.verbose,
    )

    gtm.plot_html(
        labels=labels,
        ids=ids,
        discrete=config.discrete_labels,
        output=config.output + "_control_plot",
        cname=config.color_map,
        pointsize=config.pointsize,
        alpha=config.alpha,
        title="Control Graph (All Samples)",
        prior=config.gtm_prior,
        do_interpolate=config.interpolate,
    )
    return None
Пример #2
0
 def test_runGTM(self):
     gtm = ugtm.runGTM(data=self.data, k=self.k)
     self.assertEqual(gtm.converged, True)
     self.assertEqual(gtm.matR.shape, (self.n_individuals, self.n_nodes))
     self.assertAlmostEqual(sum(gtm.matR[0, :]), 1.0)
     self.assertEqual(gtm.matMeans.shape, (self.n_individuals, 2))
     self.assertEqual(gtm.matModes.shape, (self.n_individuals, 2))
Пример #3
0
 def test_transform(self):
     gtm = ugtm.runGTM(data=self.data, k=self.k, doPCA=True)
     transformed = ugtm.transform(
         optimizedModel=gtm, train=self.data, test=self.data, doPCA=True)
     self.assertEqual(transformed.converged, True)
     np.testing.assert_almost_equal(gtm.matR, transformed.matR, decimal=7)
     np.testing.assert_almost_equal(
         gtm.matMeans, transformed.matMeans, decimal=7)
Пример #4
0
 def setUp(self):
     np.random.seed(0)
     self.n_dimensions = 10
     self.n_individuals = 100
     self.n_nodes = 4
     self.k = 2
     self.n_rbf_centers = 4
     self.m = 2
     self.data = np.random.randn(self.n_individuals, self.n_dimensions)
     self.labels = np.random.choice([1, 2], size=self.n_individuals)
     self.gtm = ugtm.runGTM(self.data, k=self.k, m=self.m)
Пример #5
0
 def test_runWorkflow(self):
     train = np.random.randn(20, 10)
     test = np.random.randn(20, 10)
     labels = np.random.choice(["class1", "class2"], size=20)
     activity = np.random.randn(20)
     gtm = ugtm.runGTM(train)
     gtm.write("tests/output_tests/testout1")
     gtm_coordinates = gtm.matMeans
     gtm_modes = gtm.matModes
     gtm_responsibilities = gtm.matR
     gtm.plot_multipanel(output="tests/output_tests/testout2",
                         labels=labels,
                         discrete=True,
                         pointsize=20)
     gtm.plot_multipanel(output="tests/output_tests/testout3",
                         labels=activity,
                         discrete=False,
                         pointsize=20)
     gtm.plot_multipanel(output="tests/output_tests/testout4",
                         labels=labels,
                         discrete=True,
                         pointsize=20,
                         do_interpolate=False)
     gtm.plot_multipanel(output="tests/output_tests/testout5",
                         labels=activity,
                         discrete=False,
                         pointsize=20,
                         do_interpolate=False)
     gtm.plot(output="tests/output_tests/testout6", pointsize=20)
     gtm.plot(output="tests/output_tests/testout7",
              labels=labels,
              discrete=True,
              pointsize=20)
     gtm.plot(output="tests/output_tests/testout8",
              labels=activity,
              discrete=False,
              pointsize=20)
     gtm.plot_html(output="tests/output_tests/testout9", pointsize=20)
     gtm.plot_html(output="tests/output_tests/testout10",
                   labels=activity,
                   discrete=False,
                   pointsize=20)
     gtm.plot_html(output="tests/output_tests/testout11",
                   labels=labels,
                   discrete=True,
                   pointsize=20)
     gtm.plot_html(output="tests/output_tests/testout12",
                   labels=activity,
                   discrete=False,
                   pointsize=20,
                   do_interpolate=False,
                   ids=labels)
     gtm.plot_html(output="tests/output_tests/testout13",
                   labels=labels,
                   discrete=True,
                   pointsize=20,
                   do_interpolate=False)
     transformed = ugtm.transform(optimizedModel=gtm,
                                  train=train,
                                  test=test)
     transformed.plot_html(output="tests/output_tests/testout14",
                           pointsize=20)
     transformed.plot(output="tests/output_tests/testout15", pointsize=20)
     gtm.plot_html_projection(output="tests/output_tests/testout16",
                              projections=transformed,
                              labels=labels,
                              discrete=True,
                              pointsize=20)
     predicted_labels = ugtm.GTC(train=train, test=test, labels=labels)
     predicted_model = ugtm.advancedGTC(train=train,
                                        test=test,
                                        labels=labels)
     predicted_model = ugtm.advancedGTC(train=train,
                                        test=test,
                                        labels=labels,
                                        doPCA=True,
                                        n_components=-1)
     ugtm.printClassPredictions(predicted_model,
                                "tests/output_tests/testout17")
     predicted = ugtm.GTR(train=train, test=test, labels=activity)
     predicted = ugtm.GTC(train=train, test=test, labels=labels)
     ugtm.crossvalidateGTC(data=train,
                           labels=labels,
                           s=1,
                           regul=1,
                           n_repetitions=10,
                           n_folds=5)
     ugtm.crossvalidateGTR(data=train, labels=activity, s=1, regul=1)
     ugtm.crossvalidatePCAC(data=train, labels=labels, n_neighbors=7)
     ugtm.crossvalidateSVCrbf(data=train, labels=labels, C=1, gamma=1)
     ugtm.crossvalidateSVCrbf(data=train, labels=labels, C=1)
     ugtm.crossvalidateSVR(data=train, labels=activity, C=1, epsilon=1)
     ugtm.crossvalidatePCAR(data=train, labels=activity, n_neighbors=7)
     gtm = ugtm.runkGTM(train, doKernel=True, kernel="linear")
Пример #6
0
                       output=args.output,
                       cname=args.cname,
                       pointsize=args.pointsize,
                       alpha=args.alpha)
        np.savetxt(args.output + "_tsne.csv", data_r, delimiter=',')
        exit

    # if it's for GTM visualization
    elif args.model == 'GTM':
        start = time.time()
        gtm = ugtm.runGTM(data=data,
                          k=k,
                          m=m,
                          s=s,
                          l=l,
                          niter=niter,
                          doPCA=args.pca,
                          n_components=args.n_components,
                          missing=args.missing,
                          missing_strategy=args.missing_strategy,
                          random_state=args.random_state,
                          verbose=args.verbose)
        print("k:%s, m:%s, l:%s, s:%s" % (k, m, l, s))
        end = time.time()
        elapsed = end - start
        print("time taken for GTM: ", elapsed)
        np.savetxt(args.output + "_matmeans.csv", gtm.matMeans, delimiter=',')
        gtm.plot_multipanel(labels=labels,
                            output=args.output,
                            discrete=discrete,
                            cname=args.cname,
                            pointsize=args.pointsize,