Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
faust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
GitLab upgrade completed. Current version is 17.11.4.
Show more breadcrumbs
faust group
faust
Commits
281ebfe8
Commit
281ebfe8
authored
7 years ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
Update py. wrapper code doc.
parent
765f513c
Branches
Branches containing commit
Tags
3.38.4
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wrapper/python/FaustPy.py
+42
-26
42 additions, 26 deletions
wrapper/python/FaustPy.py
with
42 additions
and
26 deletions
wrapper/python/FaustPy.py
+
42
−
26
View file @
281ebfe8
...
...
@@ -55,11 +55,24 @@ class Faust:
"""
def
__init__
(
F
,
list_factors
=
None
,
filepath
=
None
,
core_obj
=
None
):
"""
Creates a Faust from a list of factors or a file.
"""
Creates a Faust from a list of factors or alternatively from a file.
Another easy way to create a Faust is to call the static method Faust.randFaust().
Args:
list_factors
: list/tuple of numpy matrices or filepath of the Faust in
list_factors: list/tuple of numpy matrices or filepath of the Faust in
matlab binary format (.mat).
filepath: the file in Matlab format (.mat) from which a Faust will
be created (the file must have been saved before with
Faust.save()).
core_obj: for internal purpose only. Please don
'
t fill this argument.
Examples:
>>>
from
FaustPy
import
Faust
>>>
F
=
Faust
(
filepath
=
"
myFaust.mat
"
)
>>>
import
numpy
as
np
>>>
G
=
Faust
(
list_factors
=
[
np
.
random
.
rand
(
5
,
5
)
*
10
for
i
in
range
(
0
,
5
)])
"""
if
(
core_obj
):
F
.
m_faust
=
core_obj
...
...
@@ -76,7 +89,7 @@ class Faust:
def
randFaust
(
faust_type
,
field
,
min_num_factors
,
max_num_factors
,
min_dim_size
,
max_dim_size
,
density
=
0.1
):
"""
Generates a random Faust.
Generates a random Faust.
Args:
faust_type: must be one of RandFaustType.DENSE, RandFaustType.SPARSE or RandFaustType.MIXTE.
...
...
@@ -86,7 +99,14 @@ class Faust:
min_dim_size: the minimal size of column and row dimensions.
max_dim_size: the maximal size of column and row dimensions.
density: the approximate density of factors.
"""
Returns:
the random generated Faust.
Examples:
>>>
from
FaustPy
import
Faust
,
RandFaustType
>>>
F
=
Faust
.
randFaust
(
RandFaustType
.
MIXTE
,
RandFaustType
.
COMPLEX
,
2
,
3
,
10
,
20
,.
5
)
"""
if
(
not
isinstance
(
faust_type
,
int
)
or
faust_type
not
in
[
RandFaustType
.
SPARSE
,
RandFaustType
.
DENSE
,
RandFaustType
.
MIXTE
]):
...
...
@@ -108,7 +128,7 @@ class Faust:
Gives the Faust
'
s number of rows.
Returns:
T
he
Faust
number of rows.
t
he number of rows.
"""
return
F
.
m_faust
.
shape
()[
0
]
...
...
@@ -117,7 +137,7 @@ class Faust:
Gives the Faust
'
s number of columns.
Returns:
T
he
Faust
number of columns.
t
he number of columns.
"""
return
F
.
m_faust
.
shape
()[
1
]
...
...
@@ -126,7 +146,7 @@ class Faust:
Gives the size of the Faust.
Returns:
T
he Faust size tuple: get_nb_rows(), get_nb_cols().
t
he Faust size tuple: get_nb_rows(), get_nb_cols().
"""
#return F.shape[0], F.shape[1]
return
F
.
m_faust
.
shape
()
...
...
@@ -170,7 +190,7 @@ class Faust:
np.ndararray() must be equal
'
F
'
).
Returns:
T
he result of the multiplication as a numpy matrix.
t
he result of the multiplication as a numpy matrix.
Raises:
ValueError
...
...
@@ -198,14 +218,14 @@ class Faust:
"""
Returns a coefficient of the Faust by its indices.
This function
overloads the
Python built-in.
This function
is a
Python built-in
overload
.
Args:
indices: array of length 2, its elements must be of kind: slice, integer or
Ellipsis (...).
Returns:
T
he float element requested.
t
he float element requested.
Examples:
>>>
F
[
2
,
3
]
...
...
@@ -243,7 +263,7 @@ class Faust:
computed at Faust creation time and kept in cache.
Returns:
T
he number of non-zero elements as an integer.
t
he number of non-zero elements as an integer.
Examples:
>>>
F
.
nnz
()
...
...
@@ -255,12 +275,11 @@ class Faust:
Calculates the normalized rate of non-zero coefficients.
Returns:
T
he density value
as a
float.
t
he density value
(
float
)
.
Examples:
>>>
F
.
density
()
"""
#return float(F.nnz())/(F.shape[0]*F.shape[1])
return
float
(
F
.
nnz
()
/
(
F
.
get_nb_cols
()
*
F
.
get_nb_rows
()))
def
RCG
(
F
):
...
...
@@ -268,7 +287,7 @@ class Faust:
Computes the Relative Complexity Gain (inverse of the density).
Returns:
T
he RCG value
as a
float.
t
he RCG value
(
float
)
.
If the density is zero it will be float(
"
inf
"
).
If the density is negative it will be -1.
...
...
@@ -285,16 +304,14 @@ class Faust:
def
norm
(
F
,
ord
=
2
):
"""
Computes the norm of the Faust. Several types of norm are available:
L1, L2 and Frobenius.
Computes the norm of the Faust. Several types of norm are available: 1-norm, 2-norm and Frobenius norm.
Args:
ord: (Optional) Set it to 1 for L1, 2 for L2 and
"
fro
"
for
Frobenius norm.
(by default the computed norm is L2).
ord: (Optional) the norm order (1 or 2) or
"
fro
"
for
Frobenius norm (by default the 2-norm is computed).
Returns:
T
he norm
as a
float.
t
he norm
(
float
)
.
Raises:
ValueError.
...
...
@@ -306,8 +323,7 @@ class Faust:
>>>
F
.
norm
(
'
fro
'
)
"""
if
(
ord
not
in
[
1
,
2
,
"
fro
"
]):
raise
ValueError
(
"
Only L1, L2 and Frobenius norms are supported (values 1,
"
"
2 or
'
fro
'
expected.
"
)
raise
ValueError
(
"
ord must have the value 1, 2 or
'
fro
'
.
"
)
return
F
.
m_faust
.
norm
(
ord
)
def
get_nb_factors
(
F
):
...
...
@@ -315,7 +331,7 @@ class Faust:
Gives the Faust
'
s number of factors.
Returns:
T
he number of factors.
t
he number of factors.
Examples:
>>>
F
.
get_nb_factors
()
...
...
@@ -327,10 +343,10 @@ class Faust:
Returns the Faust
'
s i-th factor as a numpy.ndarray.
Args:
i:
T
he integer index of the factor to get back.
i:
t
he integer index of the factor to get back.
Returns:
T
he i-th factor as a dense matrix (of type numpy.ndarray).
t
he i-th factor as a dense matrix (of type numpy.ndarray).
Raises:
ValueError.
...
...
@@ -351,7 +367,7 @@ class Faust:
if Matlab format used). It can be either an absolute or relative path.
format: (Optional) It designates the format to use for
writing. By default, it
'
s
"
Matlab
"
to save the Faust in a .mat
file (
and it
'
s
currently
the
only format available).
file (currently only
that
format
is
available).
Raises:
ValueError.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment