Exemple #1
0
    def fit(self, load_N=True, save_N=False, debug=False):
        """
        load_N: load the precomputed N matrices if possible (it reduce the actual running time for sampling sketches)
        save_N: save the computed N matrices for future use
        """

        if self.solver_type == 'low_precision':
            logger.info('Ready to start computing solutions!')
            x, time = comp_sketch(self.matrix_Ab, 'x', load_N, save_N,
                                  **self.params)

        elif self.solver_type == 'high_precision':
            num_iters = self.params.get('num_iters')
            sketch_type = self.params.get('sketch_type')

            # start computing a sketch
            if sketch_type is not None:
                N, time_proj = comp_sketch(self.matrix_Ab, 'N', load_N, save_N,
                                           **self.params)
            else:
                N = [np.eye(self.matrix_Ab.n)]
                self.k = 1
                time_proj = 0

            # start LSQR
            time = [time_proj for i in range(num_iters)]
            x = []

            for i in range(self.k):
                x_iter, y_iter, time_iter = lsqr_spark(self.matrix_Ab,
                                                       self.matrix_Ab.m,
                                                       self.matrix_Ab.n, N[i],
                                                       1e-10, num_iters)
                x.append(x_iter)
                time = [time[i] + time_iter[i] for i in range(num_iters)]

        else:
            raise ValueError("invalid solver_type")

        self.x = x
        self.time = time

        if debug:
            print self.x
    def fit(self, load_N=True, save_N=False, debug=False):
        """
        load_N: load the precomputed N matrices if possible (it reduce the actual running time for sampling sketches)
        save_N: save the computed N matrices for future use
        """

        if self.solver_type == 'low_precision':
            logger.info('Ready to start computing solutions!')
            x, time = comp_sketch(self.matrix_Ab, 'x', load_N, save_N, **self.params)

        elif self.solver_type == 'high_precision':
            num_iters = self.params.get('num_iters')
            sketch_type = self.params.get('sketch_type')

            # start computing a sketch
            if sketch_type is not None:
                N, time_proj = comp_sketch(self.matrix_Ab, 'N', load_N, save_N, **self.params)
            else:
                N = [np.eye(self.matrix_Ab.n-1)]
                self.k = 1
                time_proj = 0

            b = []

            # start lsqr
            time = [time_proj for i in range(num_iters)]
            x = []
 
            for i in range(self.k):
                x_iter, y_iter, time_iter = lsqr_spark(self.matrix_Ab,b,self.matrix_Ab.m,self.matrix_Ab.n-1,N[i],1e-10,num_iters)
                x.append(x_iter)
                time = [time[i] + time_iter[i] for i in range(num_iters)]
            
        else:
            raise ValueError("invalid solver_type")

        self.x = x
        self.time = time

        if debug:
            print self.x
 def test_sketch_projection_x(self):
     x, time = comp_sketch(self.matrix_Ab,
                           'x',
                           load_N=False,
                           save_N=False,
                           N_dire='N_file/',
                           sketch_type='projection',
                           projection_type='gaussian',
                           k=3,
                           c=1e2)
     self.assertEqual(len(x), 3)
     self.assertEqual(len(x[0]), self.matrix_Ab.n)
 def test_sketch_projection_N(self):
     N, time = comp_sketch(self.matrix_Ab,
                           'N',
                           load_N=False,
                           save_N=False,
                           N_dire='N_file/',
                           sketch_type='projection',
                           projection_type='gaussian',
                           k=3,
                           c=1e2)
     self.assertEqual(len(N), 3)
     self.assertEqual(N[0].shape, (self.matrix_Ab.n, self.matrix_Ab.n))
 def test_sketch_sampling_x3(self):
     x, time = comp_sketch(self.matrix_Ab,
                           'x',
                           load_N=True,
                           save_N=True,
                           N_dire='N_file/',
                           sketch_type='sampling',
                           projection_type='gaussian',
                           k=3,
                           c=1e2,
                           s=5e2)
     self.assertEqual(len(x), 3)
     self.assertEqual(len(x[0]), self.matrix_Ab.n)
 def test_sketch_sampling_N2(self):
     N, time = comp_sketch(self.matrix_Ab, 'N', load_N=True, save_N=False, N_dire='N_file/', sketch_type='projection', projection_type='gaussian', k=3, c=1e2, s=5e2)
     self.assertEqual(len(N), 3)
     self.assertEqual(N[0].shape, (self.matrix_Ab.n,self.matrix_Ab.n))
 def test_sketch_sampling_x3(self):
     x, time = comp_sketch(self.matrix_Ab, 'x', load_N=True, save_N=True, N_dire='N_file/', sketch_type='sampling', projection_type='gaussian', k=3, c=1e2, s=5e2)
     self.assertEqual(len(x), 3)
     self.assertEqual(len(x[0]), self.matrix_Ab.n)
 def test_sketch_projection_x(self):
     x, time = comp_sketch(self.matrix_Ab, 'x', load_N=False, save_N=False, N_dire='N_file/', sketch_type='projection', projection_type='gaussian', k=3, c=1e2)
     self.assertEqual(len(x), 3)
     self.assertEqual(len(x[0]), self.matrix_Ab.n)