factored out packer
This commit is contained in:
parent
15c89fb9b5
commit
fc33c2dbfc
|
@ -1,6 +1,7 @@
|
||||||
"""This module contains bilinear models(Functions)
|
"""This module contains bilinear models(Functions)
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import copy
|
||||||
import pygtk
|
import pygtk
|
||||||
import gtk
|
import gtk
|
||||||
import gtk.glade
|
import gtk.glade
|
||||||
|
@ -9,13 +10,13 @@ from fluents.workflow import Function, OptionsDialog, Options
|
||||||
from fluents.dataset import Dataset
|
from fluents.dataset import Dataset
|
||||||
from fluents import plots, dataset, workflow, logger
|
from fluents import plots, dataset, workflow, logger
|
||||||
import scipy
|
import scipy
|
||||||
from engines import *
|
from engines import pca, pls
|
||||||
from cx_stats import leverage, variances, hotelling
|
from cx_stats import leverage, variances, hotelling
|
||||||
from cx_utils import mat_center
|
from cx_utils import mat_center
|
||||||
from validation import *
|
from validation import *
|
||||||
|
from packer import Packer
|
||||||
import blmplots
|
import blmplots
|
||||||
import engines
|
|
||||||
import copy
|
|
||||||
|
|
||||||
class Model(Function):
|
class Model(Function):
|
||||||
"""Base class of bilinear models.
|
"""Base class of bilinear models.
|
||||||
|
@ -194,7 +195,7 @@ class PLS(Model):
|
||||||
self._options = PlsOptions()
|
self._options = PlsOptions()
|
||||||
|
|
||||||
def validation(self, amax, n_sets, cv_val_method):
|
def validation(self, amax, n_sets, cv_val_method):
|
||||||
"""Returns rmsec,rmsep for model.
|
"""Returns rmsep for pls model.
|
||||||
"""
|
"""
|
||||||
m, n = self.model['E0'].shape
|
m, n = self.model['E0'].shape
|
||||||
if m>n:
|
if m>n:
|
||||||
|
@ -229,8 +230,8 @@ class PLS(Model):
|
||||||
else:
|
else:
|
||||||
self.model['w_tsq'] = None
|
self.model['w_tsq'] = None
|
||||||
|
|
||||||
def permutation_confidence(self, a, b, aopt, reg, n_iter, algo,
|
def permutation_confidence(self, a, b, aopt, reg,
|
||||||
sim_method):
|
n_iter, algo, sim_method):
|
||||||
"""Estimates cut off on significant vars by controlling fdr."""
|
"""Estimates cut off on significant vars by controlling fdr."""
|
||||||
|
|
||||||
if self._options['calc_qvals']==True:
|
if self._options['calc_qvals']==True:
|
||||||
|
@ -349,35 +350,6 @@ class PLS(Model):
|
||||||
#run with current data and options
|
#run with current data and options
|
||||||
return self.run_o(a, b)
|
return self.run_o(a, b)
|
||||||
|
|
||||||
class Packer:
|
|
||||||
"""A compression object used to speed up model calculations.
|
|
||||||
|
|
||||||
Often used in conjunction with crossvalidation and perturbations
|
|
||||||
analysis.
|
|
||||||
"""
|
|
||||||
def __init__(self,array):
|
|
||||||
self._shape = array.shape
|
|
||||||
self._array = array
|
|
||||||
self._packed_data = None
|
|
||||||
|
|
||||||
def expand(self,a):
|
|
||||||
if self._inflater!=None:
|
|
||||||
return dot(self._inflater,a)
|
|
||||||
|
|
||||||
def collapse(self,axis=None,mode='svd'):
|
|
||||||
if not axis:
|
|
||||||
axis = argmin(self._array.shape) # default is the smallest dim
|
|
||||||
|
|
||||||
if axis == 1:
|
|
||||||
self._array = self._array.T
|
|
||||||
u, s, vt = svd(self._array,full_matrices=0)
|
|
||||||
self._inflater = vt.T
|
|
||||||
self._packed_data = u*s
|
|
||||||
return self._packed_data
|
|
||||||
|
|
||||||
def get_packed_data(self):
|
|
||||||
return self._packed_data
|
|
||||||
|
|
||||||
|
|
||||||
class PcaOptions(Options):
|
class PcaOptions(Options):
|
||||||
"""Options for Principal Component Analysis.
|
"""Options for Principal Component Analysis.
|
||||||
|
@ -389,7 +361,7 @@ class PcaOptions(Options):
|
||||||
def _set_default(self):
|
def _set_default(self):
|
||||||
opt = {}
|
opt = {}
|
||||||
opt['algo'] = 'pca'
|
opt['algo'] = 'pca'
|
||||||
opt['engine'] = engines.pca
|
opt['engine'] = pca
|
||||||
opt['mode'] = 'normal' # how much info to calculate
|
opt['mode'] = 'normal' # how much info to calculate
|
||||||
opt['amax'] = 10
|
opt['amax'] = 10
|
||||||
opt['aopt'] = 100
|
opt['aopt'] = 100
|
||||||
|
@ -460,7 +432,7 @@ class PlsOptions(Options):
|
||||||
def _set_default(self):
|
def _set_default(self):
|
||||||
opt = {}
|
opt = {}
|
||||||
opt['algo'] = 'pls'
|
opt['algo'] = 'pls'
|
||||||
opt['engine'] = engines.pls
|
opt['engine'] = pls
|
||||||
opt['mode'] = 'normal' # how much info to calculate
|
opt['mode'] = 'normal' # how much info to calculate
|
||||||
opt['amax'] = 10
|
opt['amax'] = 10
|
||||||
opt['aopt'] = 10
|
opt['aopt'] = 10
|
||||||
|
@ -501,7 +473,7 @@ class PlsOptions(Options):
|
||||||
|
|
||||||
opt['out_data'] = None
|
opt['out_data'] = None
|
||||||
|
|
||||||
opt['pack'] = False
|
opt['pack'] = True
|
||||||
opt['calc_qvals'] = False
|
opt['calc_qvals'] = False
|
||||||
opt['q_pert_method'] = 'shuffle_rows'
|
opt['q_pert_method'] = 'shuffle_rows'
|
||||||
opt['q_iter'] = 20
|
opt['q_iter'] = 20
|
||||||
|
|
Reference in New Issue