Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

factored out packer

This commit is contained in:
Arnar Flatberg 2007-02-09 14:02:58 +00:00
parent 15c89fb9b5
commit fc33c2dbfc
1 changed files with 10 additions and 38 deletions

View File

@ -1,6 +1,7 @@
"""This module contains bilinear models(Functions)
"""
import os
import copy
import pygtk
import gtk
import gtk.glade
@ -9,13 +10,13 @@ from fluents.workflow import Function, OptionsDialog, Options
from fluents.dataset import Dataset
from fluents import plots, dataset, workflow, logger
import scipy
from engines import *
from engines import pca, pls
from cx_stats import leverage, variances, hotelling
from cx_utils import mat_center
from validation import *
from packer import Packer
import blmplots
import engines
import copy
class Model(Function):
"""Base class of bilinear models.
@ -194,7 +195,7 @@ class PLS(Model):
self._options = PlsOptions()
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
if m>n:
@ -229,8 +230,8 @@ class PLS(Model):
else:
self.model['w_tsq'] = None
def permutation_confidence(self, a, b, aopt, reg, n_iter, algo,
sim_method):
def permutation_confidence(self, a, b, aopt, reg,
n_iter, algo, sim_method):
"""Estimates cut off on significant vars by controlling fdr."""
if self._options['calc_qvals']==True:
@ -349,35 +350,6 @@ class PLS(Model):
#run with current data and options
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):
"""Options for Principal Component Analysis.
@ -389,7 +361,7 @@ class PcaOptions(Options):
def _set_default(self):
opt = {}
opt['algo'] = 'pca'
opt['engine'] = engines.pca
opt['engine'] = pca
opt['mode'] = 'normal' # how much info to calculate
opt['amax'] = 10
opt['aopt'] = 100
@ -460,7 +432,7 @@ class PlsOptions(Options):
def _set_default(self):
opt = {}
opt['algo'] = 'pls'
opt['engine'] = engines.pls
opt['engine'] = pls
opt['mode'] = 'normal' # how much info to calculate
opt['amax'] = 10
opt['aopt'] = 10
@ -501,7 +473,7 @@ class PlsOptions(Options):
opt['out_data'] = None
opt['pack'] = False
opt['pack'] = True
opt['calc_qvals'] = False
opt['q_pert_method'] = 'shuffle_rows'
opt['q_iter'] = 20