Example #1
0
    def inverse_transform(self, X):
        """inverse_transform"""
        if self.pca_res_ is None:
            raise AttributeError(\
                "inverse_transform: PCA object is not fitted!")
        inp_data = FrovedisFeatureData(X, dense_kind='rowmajor',\
                                       dtype=self.__dtype)
        input_x = inp_data.get()
        x_dtype = inp_data.get_dtype()
        if x_dtype != self.pca_res_.get_dtype():
            raise TypeError(\
            "inverse_transform: model dtype differs from input matrix dtype!")

        pc_ptr = self.pca_res_._components.get()
        exp_var_ptr = self.pca_res_._explained_variance.get()
        mean_ptr = self.pca_res_._mean.get()
        (host, port) = FrovedisServer.getServerInstance()
        dummy_res = pca_inverse_transform(host, port, input_x.get(), pc_ptr,
                                          exp_var_ptr,
                                          mean_ptr, x_dtype, self.whiten)
        excpt = check_server_exception()
        if excpt["status"]:
            raise RuntimeError(excpt["info"])
        res = FrovedisRowmajorMatrix(mat=dummy_res, dtype=self.__dtype)

        if inp_data.is_movable(): # input was a python data
            return res.to_numpy_array()
        else:
            return res
Example #2
0
desc = "Testing fit_transform for FrovedisRowmajorMatrix : "

# initializing the frovedis server
argvs = sys.argv
argc = len(argvs)
if (argc < 2):
    print('Please give frovedis_server calling command as the first argument\n\
           (e.g. "mpirun -np 2 -x /opt/nec/nosupport/frovedis/ve/bin/frovedis_server")'
          )
    quit()
FrovedisServer.initialize(argvs[1])

# sample numpy dense data (3x3)
mat = np.matrix(
    [[0, 0, 0, 0], [0, 1, 1, 1], [1, 0, 1, 0], [1, 1, 1, 0], [1, 1, 1, 1]],
    dtype=np.float64)
mat = FrovedisRowmajorMatrix(mat)
tsne = TSNE(n_components=2)

try:
    emb = tsne.fit_transform(mat)
    if (type(emb).__name__ == "FrovedisRowmajorMatrix"):
        print(desc, "Passed")
        emb.release()
    else:
        print(desc, "Failed")
except:
    print(desc, "Failed")

FrovedisServer.shut_down()
Example #3
0
from frovedis.exrpc.server import FrovedisServer
from frovedis.matrix.dense import FrovedisRowmajorMatrix
from frovedis.mllib.cluster import SpectralClustering
import sys
import numpy as np

# initializing the Frovedis server
argvs = sys.argv
argc = len(argvs)
if (argc < 2):
    print ('Please give frovedis_server calling command as the first argument \n(e.g. "mpirun -np 2 -x /opt/nec/nosupport/frovedis/ve/bin/frovedis_server")')
    quit()
FrovedisServer.initialize(argvs[1])

train_mat = FrovedisRowmajorMatrix(dtype=np.float64).load("./input/spectral_data.txt")

# creating spectral clustering object
spec = SpectralClustering(n_clusters=2, verbose=0)

# fitting the training matrix on spectral clustering object
spec.fit(train_mat)
spec.debug_print()

# extracting the affinity matrix from created model
aff = spec.get_affinity_matrix()
#aff.debug_print()

# fitting the precomputed affinity matrix for new model creation
spec.affinity = 'precomputed'
spec.fit(aff)
Example #4
0
import os
import numpy as np
from frovedis.exrpc.server import FrovedisServer
from frovedis.matrix.dense import FrovedisRowmajorMatrix
#from frovedis.matrix.dense import FrovedisColmajorMatrix

# sample 4x4 numpy matrix creation
mat = np.matrix([[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
                dtype=np.float64)

FrovedisServer.initialize("mpirun -np 2 {}".format(
    os.environ['FROVEDIS_SERVER']))
print("-- matrix created from np.matrix --")
fmat = FrovedisRowmajorMatrix(mat)
#fmat = FrovedisColmajorMatrix(mat)
fmat.debug_print()
fmat.save("./result")
fmat.release()
print("\n-- matrix loaded from text file --")
fmat2 = FrovedisRowmajorMatrix().load_text("./result")
#fmat2 = FrovedisColmajorMatrix().load_text("./result")
fmat2.debug_print()
fmat2.release()
FrovedisServer.shut_down()