Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 54e25f88 authored by hhakim's avatar hhakim
Browse files

Review the doc and fix imports.

parent 15e6582e
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,8 @@
%> @param 'tol', number [optional if nGivens is set] the tolerance error at which the algorithm stops. The default value is zero so that stopping is based on reaching the targeted nGivens.
%> @param 'order', char [optional, default is ‘ascend’] order of eigenvalues, possible choices are ‘ascend, 'descend' or 'undef' (to avoid a sorting operation and save some time).
%> @param 'nGivens_per_fac', integer [optional, default is <code>floor(size(M, 1)/2)</code>] targeted number of Givens rotations per factor of V. Must be an integer between 1 to <code>floor(size(M, 1)/2)</code>.
%> @param 'relerr', bool [optional, default is True] the type of error used as stopping criterion. (true) for the relative error norm(V*D*V'-M, 'fro')/norm(M, 'fro'), (false) for the absolute error norm(V*D*V'-M, 'fro').
%> @param 'relerr', bool [optional, default is true] the type of error used as stopping criterion. (true) for the relative error norm(V*D*V'-M, 'fro')/norm(M, 'fro'), (false) for the absolute error norm(V*D*V'-M, 'fro').
%> @param 'enable_large_Faust', bool [optional, default is false] if true, it allows to compute a transform that doesn't worth it regarding its complexity relatively to the matrix M. Otherwise, by default, an exception is raised before the algorithm starts.
%> @param 'verbosity', integer [optional] verbosity level. The greater the value the more info is displayed. It can be helpful to understand for example why the algorithm stopped before reaching the tol error or the number of Givens (nGivens).
%>
%>
......@@ -45,7 +46,7 @@
%> % get a Laplacian to diagonalize
%> load('Laplacian_256_community.mat')
%> % do it
%> [Uhat, Dhat] = eigtj(Lap, 'nGivens', size(Lap,1)*100, 'nGivens_per_fac', size(Lap, 1)/2, 'verbosity', 2)
%> [Uhat, Dhat] = eigtj(Lap, 'nGivens', size(Lap,1)*100, 'nGivens_per_fac', size(Lap, 1)/2, 'verbosity', 2, 'enable_large_Faust', true)
%> % Uhat is the Fourier matrix/eigenvectors approximation as a Faust (200 factors)
%> % Dhat the eigenvalues diagonal matrix approx.
%> % Computing the decomposition of the same matrix but targeting a precise relative error
......
......@@ -50,7 +50,7 @@
%> import matfaust.*
%> import matfaust.fact.hierarchical
%> % generate a Hadamard Faust of size 32x32
%> FH = wh(32);
%> FH = wht(32);
%> H = full(FH); % the full matrix version
%> % factorize it
%> FH2 = hierarchical(H, 'squaremat');
......
......@@ -19,6 +19,7 @@
%> @param 'tol', number see fact.eigtj (NB: as described below, the error tolerance is not exactly for the approximate SVD but for the subsequent eigtj calls).
%> @param 'relerr', bool see fact.eigtj
%> @param 'nGivens_per_fac',integer see fact.eigtj
%> @param 'enable_large_Faust',bool see fact.eigtj
%>
%> @retval [U,S,V]: such that U*S*V' is the approximate of M with:
%> - S: (sparse real diagonal matrix) the singular values in descendant order.
......
......@@ -102,6 +102,7 @@ def svdtj(M, nGivens=None, tol=0, order='ascend', relerr=True,
the svd but for the subsequent eigtj calls).
relerr: see fact.eigtj
nGivens_per_fac: see fact.eigtj
enable_large_Faust: see fact.eigtj
Returns:
......@@ -208,7 +209,9 @@ def eigtj(M, nGivens=None, tol=0, order='ascend', relerr=True,
info is displayed. It can be helpful to understand for example why the
algorithm stopped before reaching the tol error or the number of Givens
(nGivens).
enable_large_Faust: (bool) if true, it allows to compute a transform
that doesn't worth it regarding its complexity compared to the matrix
M. Otherwise by default, an exception is raised before the algorithm starts.
Returns:
......@@ -248,7 +251,7 @@ def eigtj(M, nGivens=None, tol=0, order='ascend', relerr=True,
demo_path = sep.join((get_data_dirpath(),'Laplacian_256_community.mat'))
data_dict = loadmat(demo_path)
Lap = data_dict['Lap'].astype(np.float)
Dhat, Uhat = eigtj(Lap, nGivens=Lap.shape[0]*100)
Dhat, Uhat = eigtj(Lap, nGivens=Lap.shape[0]*100, enable_large_Faust=True)
# Uhat is the Fourier matrix/eigenvectors approximation as a Faust
# (200 factors)
# Dhat the eigenvalues diagonal matrix approx.
......@@ -260,8 +263,7 @@ def eigtj(M, nGivens=None, tol=0, order='ascend', relerr=True,
# and then asking for an absolute error
Dhat3, Uhat3 = eigtj(Lap, tol=0.1, relerr=False)
assert(norm(Lap-Uhat3*np.diag(Dhat3)*Uhat3.H) < .11)
# now recompute Uhat2, Dhat2 but asking a descending order of
eigenvalues
# now recompute Uhat2, Dhat2 but asking a descending order of eigenvalues
Dhat4, Uhat4 = eigtj(Lap, tol=0.01)
assert((Dhat4[::-1] == Dhat2[::]).all())
# and now with no sort
......@@ -572,6 +574,7 @@ def hierarchical(M, p, ret_lambda=False, ret_params=False):
<b> 3. Simplified Parameters for a Rectangular Matrix Factorization
(the BSL demo MEG matrix)</b>
>>> from pyfaust import *
>>> from pyfaust.fact import hierarchical
>>> from scipy.io import loadmat
>>> from pyfaust.demo import get_data_dirpath
>>> d = loadmat(get_data_dirpath()+'/matrix_MEG.mat')
......
......@@ -540,6 +540,7 @@ class ParamsFact(ABC):
self.is_update_way_R2L = is_update_way_R2L
self.init_lambda = init_lambda
self.step_size = step_size
import pyfaust.proj
if((isinstance(constraints, list) or isinstance(constraints, tuple))
and np.array([isinstance(constraints[i],pyfaust.proj.proj_gen) for i in
range(0,len(constraints))]).all()):
......@@ -578,6 +579,7 @@ class ParamsHierarchical(ParamsFact):
is_fact_side_left=False,
is_verbose=False,
grad_calc_opt_mode=ParamsFact.EXTERNAL_OPT):
import pyfaust.proj
if((isinstance(fact_constraints, list) or isinstance(fact_constraints, tuple))
and np.array([isinstance(fact_constraints[i],pyfaust.proj.proj_gen) for i in
range(0,len(fact_constraints))]).all()):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment