Exemplo n.º 1
0
def preprocessor_pca_modular (data):
	from modshogun import RealFeatures
	from modshogun import PCA

	features = RealFeatures(data)

	preprocessor = PCA()
	preprocessor.init(features)
	preprocessor.apply_to_feature_matrix(features)

	return features
Exemplo n.º 2
0
        def RunPCAShogun(q):
            totalTimer = Timer()

            # Load input dataset.
            Log.Info("Loading dataset", self.verbose)
            try:
                feat = RealFeatures(self.data.T)

                with totalTimer:
                    # Get the options for running PCA.
                    if "new_dimensionality" in options:
                        k = int(options.pop("new_dimensionality"))
                        if (k > self.data.shape[1]):
                            Log.Fatal("New dimensionality (" + str(k) +
                                      ") cannot be greater than" +
                                      "existing dimensionality (" +
                                      str(self.data.shape[1]) + ")!")
                            q.put(-1)
                            return -1
                    else:
                        k = self.data.shape[1]

                    if "whiten" in options:
                        s = True
                        options.pop("whiten")
                    else:
                        s = False

                    if len(options) > 0:
                        Log.Fatal("Unknown parameters: " + str(options))
                        raise Exception("unknown parameters")

                    # Perform PCA.
                    prep = ShogunPCA(s)
                    prep.set_target_dim(k)
                    prep.init(feat)
                    prep.apply_to_feature_matrix(feat)
            except Exception as e:
                q.put(-1)
                return -1

            time = totalTimer.ElapsedTime()
            q.put(time)
            return time
Exemplo n.º 3
0
        def RunPCAShogun(q):
            totalTimer = Timer()

            # Load input dataset.
            Log.Info("Loading dataset", self.verbose)
            try:
                feat = RealFeatures(self.data.T)

                with totalTimer:
                    # Find out what dimension we want.
                    match = re.search('-d (\d+)', options)

                    if not match:
                        k = self.data.shape[1]
                    else:
                        k = int(match.group(1))
                        if (k > self.data.shape[1]):
                            Log.Fatal("New dimensionality (" + str(k) +
                                      ") cannot be greater than" +
                                      "existing dimensionality (" +
                                      str(self.data.shape[1]) + ")!")
                            q.put(-1)
                            return -1

                    # Get the options for running PCA.
                    s = True if options.find("-s") > -1 else False

                    # Perform PCA.
                    prep = ShogunPCA(s)
                    prep.set_target_dim(k)
                    prep.init(feat)
                    prep.apply_to_feature_matrix(feat)
            except Exception as e:
                q.put(-1)
                return -1

            time = totalTimer.ElapsedTime()
            q.put(time)
            return time
Exemplo n.º 4
0
    def RunPCAShogun():
      totalTimer = Timer()

      # Load input dataset.
      Log.Info("Loading dataset", self.verbose)
      try:
        feat = RealFeatures(self.data.T)

        with totalTimer:
          # Get the options for running PCA.
          if "new_dimensionality" in options:
            k = int(options.pop("new_dimensionality"))
            if (k > self.data.shape[1]):
              Log.Fatal("New dimensionality (" + str(k) + ") cannot be greater than"
                  + "existing dimensionality (" + str(self.data.shape[1]) + ")!")
              return -1
          else:
            k = self.data.shape[1]

          if "whiten" in options:
            s = True
            options.pop("whiten")
          else:
            s = False

          if len(options) > 0:
            Log.Fatal("Unknown parameters: " + str(options))
            raise Exception("unknown parameters")

          # Perform PCA.
          prep = ShogunPCA(s)
          prep.set_target_dim(k)
          prep.init(feat)
          prep.apply_to_feature_matrix(feat)
      except Exception as e:
        return -1

      return totalTimer.ElapsedTime()
Exemplo n.º 5
0
    def RunPCAShogun(q):
      totalTimer = Timer()

      # Load input dataset.
      Log.Info("Loading dataset", self.verbose)
      try:
        feat = RealFeatures(self.data.T)

        with totalTimer:
          # Find out what dimension we want.
          match = re.search('-d (\d+)', options)

          if not match:
            k = self.data.shape[1]
          else:
            k = int(match.group(1))
            if (k > self.data.shape[1]):
              Log.Fatal("New dimensionality (" + str(k) + ") cannot be greater than"
                  + "existing dimensionality (" + str(self.data.shape[1]) + ")!")
              q.put(-1)
              return -1

          # Get the options for running PCA.
          s = True if options.find("-s") > -1 else False

          # Perform PCA.
          prep = ShogunPCA(s)
          prep.set_target_dim(k)
          prep.init(feat)
          prep.apply_to_feature_matrix(feat)
      except Exception as e:
        q.put(-1)
        return -1

      time = totalTimer.ElapsedTime()
      q.put(time)
      return time