예제 #1
0
파일: tutorial1.py 프로젝트: mducle/Testing
 def __init__(self, deployFile=None, session=None):
     self.isDeployed = False
     if session is None:
         if deployFile is not None:
             self.matlab = transplant.Matlab(executable=deployFile,
                                             arguments=['-nodisplay'])
             self.isDeployed = True
         else:
             self.matlab = transplant.Matlab()
     else:
         self.matlab = session
예제 #2
0
 def __init__(self,
              pde,
              theta=0.2,
              maxit=50,
              step=0,
              maxdof=1e5,
              n=3,
              p=1,
              q=3,
              sigma=None,
              multieigs=False,
              matlab=False,
              resultdir='~/'):
     self.multieigs = multieigs
     self.sigma = sigma
     self.pde = pde
     self.step = step
     self.theta = theta
     self.maxit = maxit
     self.maxdof = maxdof
     self.p = p
     self.q = q
     self.numrefine = n
     self.resultdir = resultdir
     self.picard = False
     if matlab is True:
         self.matlab = transplant.Matlab()
     else:
         self.matlab = False
예제 #3
0
 def __init__(self, root):
     super(ECO_H, self).__init__(name="ECO-H")
     self.root_path = root + "/external/ECO"
     self.eng = transplant.Matlab()
     genpath = self.eng.genpath(self.root_path)
     self.eng.addpath(genpath)
     self.eng.vl_setupnn()
예제 #4
0
 def __init__(self, matlab=None):
     if matlab is None:
         self.matlab = transplant.Matlab()
     else:
         self.matlab = matlab
예제 #5
0
 def restart_matlab(self, line):
     import transplant
     self.m = transplant.Matlab()
예제 #6
0
 def __init__(self, shell):
     super(MatlabMagic, self).__init__(shell)
     import transplant
     self.m = transplant.Matlab()
예제 #7
0
 def __init__(self, root):
     super(MCCT_H, self).__init__(name="MCCT-H")
     self.root_path = root + "/external/MCCT/TrackerMCCT-H"
     self.eng = transplant.Matlab()
     genpath = self.eng.genpath(self.root_path)
     self.eng.addpath(genpath)
예제 #8
0
import transplant
import numpy as np
matlab = transplant.Matlab()

matlab.addpath("/home/george/matlab_projects/code_nr_alg3_book/TabGenGam/")

g_dft, g_mag, mag2 = matlab.Tabulate_gain_functions(1, 0.6)

np.save("gain.npy", g_mag)
예제 #9
0
    def _collect_stats(self,
                       stats_loader,
                       cuda,
                       criterion=None,
                       stats_type='marginal',
                       run_logger=None):
        self.eval()

        if stats_type == 'jacobian':
            data, target = next(iter(stats_loader))
            if cuda:
                data, target = data.cuda(), target.cuda()
            data.requires_grad_()
            stats, _ = self(data, stats_type=stats_type)
            stats = tuple(map(lambda el: el.cpu().detach().numpy(), stats))
            stats = np.dstack(stats)
            stats = np.swapaxes(stats, 0, -1)
            stats = np.linalg.svd(stats, full_matrices=False, compute_uv=False)
        elif stats_type == 'smoothness':
            data, target = next(iter(stats_loader))
            if cuda:
                data, target = data.cuda(), target.cuda()
            x, output = self(data, stats_type=stats_type)
            loss = criterion(output, target)
            # Collect statistics
            lambda_max_Fisher = SmoothnessFisher(loss, output, self)
            lambda_max_AbsHessian = SmoothnessAbsHessian(loss, output, self)
            if run_logger is not None:
                run_logger.log_scalar("curvature.SmoothnessFisher",
                                      float(lambda_max_Fisher))
                run_logger.log_scalar("curvature.SmoothnessAbsHessian",
                                      float(lambda_max_AbsHessian))
            stats = [lambda_max_Fisher, lambda_max_AbsHessian]
        elif stats_type == 'condition_number':
            data, target = next(iter(stats_loader))
            if cuda:
                data, target = data.cuda(), target.cuda()
            x, output = self(data, stats_type=stats_type)
            loss = criterion(output, target)
            # Collect statistics
            lambda_max_AbsHessian = SmoothnessAbsHessian(loss, output, self)
            lambda_min_AbsHessian = StrongConvexity(
                loss, output, self, lambda_max=lambda_max_AbsHessian)
            if run_logger is not None:
                run_logger.log_scalar("curvature.SmoothnessAbsHessian",
                                      float(lambda_max_AbsHessian))
                run_logger.log_scalar("curvature.SCAbsHessian",
                                      float(lambda_min_AbsHessian))
                run_logger.log_scalar(
                    "curvature.ConditionNumber",
                    float(lambda_max_AbsHessian / lambda_min_AbsHessian))
            stats = [lambda_max_AbsHessian, lambda_min_AbsHessian]
        else:
            stats_temp = []
            stats = []
            for batch_idx, (data, target) in enumerate(
                    tqdm(stats_loader, desc='Stat batches', ascii=True)):
                data, target = data.cuda(), target.cuda()
                stat, _ = self(data, stats_type=stats_type)
                stats_temp += stat
            stats_temp = np.hstack(stats_temp)
            stats_temp = np.swapaxes(stats_temp, 1, 2)
            import transplant
            matlab = transplant.Matlab()
            matlab.addpath("/home/***/projects/isonetry/projectionpursuit")
            for i in range(stats_temp.shape[0]):
                _, projdata, _ = matlab.NGCA(
                    stats_temp[0].astype(np.double),
                    transplant.MatlabStruct({
                        "nbng": 1,
                        "sphered_proj": 0
                    }))
                stats += [projdata]
            matlab.exit()
            stats = np.vstack(stats)
        return stats