Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sab_pybasicbayes
Manage
Activity
Members
Labels
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
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
Show more breadcrumbs
Sebastian Bruijns
sab_pybasicbayes
Commits
73b8223f
Commit
73b8223f
authored
7 years ago
by
Scott Linderman
Browse files
Options
Downloads
Patches
Plain Diff
add color code to state usage
parent
2bdecbea
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pybasicbayes/models/factor_analysis.py
+21
-5
21 additions, 5 deletions
pybasicbayes/models/factor_analysis.py
with
21 additions
and
5 deletions
pybasicbayes/models/factor_analysis.py
+
21
−
5
View file @
73b8223f
...
@@ -26,9 +26,9 @@ class FactorAnalysisStates(object):
...
@@ -26,9 +26,9 @@ class FactorAnalysisStates(object):
def
__init__
(
self
,
model
,
data
,
mask
=
None
,
**
kwargs
):
def
__init__
(
self
,
model
,
data
,
mask
=
None
,
**
kwargs
):
self
.
model
=
model
self
.
model
=
model
self
.
X
=
data
self
.
X
=
data
self
.
mask
=
mask
if
mask
is
None
:
if
mask
is
None
:
mask
=
np
.
ones_like
(
data
,
dtype
=
bool
)
mask
=
np
.
ones_like
(
data
,
dtype
=
bool
)
self
.
mask
=
mask
assert
data
.
shape
==
mask
.
shape
and
mask
.
dtype
==
bool
assert
data
.
shape
==
mask
.
shape
and
mask
.
dtype
==
bool
assert
self
.
X
.
shape
[
1
]
==
self
.
D_obs
assert
self
.
X
.
shape
[
1
]
==
self
.
D_obs
...
@@ -58,8 +58,18 @@ class FactorAnalysisStates(object):
...
@@ -58,8 +58,18 @@ class FactorAnalysisStates(object):
def
log_likelihood
(
self
):
def
log_likelihood
(
self
):
mu
=
np
.
dot
(
self
.
Z
,
self
.
W
.
T
)
# mu = np.dot(self.Z, self.W.T)
return
-
0.5
*
np
.
sum
(((
self
.
X
-
mu
)
*
self
.
mask
)
**
2
/
self
.
sigmasq
)
# return -0.5 * np.sum(((self.X - mu) * self.mask) ** 2 / self.sigmasq)
# Compute the marginal likelihood, integrating out z
mu_x
=
np
.
zeros
(
self
.
D_obs
)
Sigma_x
=
self
.
W
.
dot
(
self
.
W
.
T
)
+
np
.
diag
(
self
.
sigmasq
)
if
not
np
.
all
(
self
.
mask
):
raise
Exception
(
"
Need to implement this!
"
)
else
:
from
scipy.stats
import
multivariate_normal
return
multivariate_normal
(
mu_x
,
Sigma_x
).
logpdf
(
self
.
X
)
## Gibbs
## Gibbs
def
resample
(
self
):
def
resample
(
self
):
...
@@ -184,10 +194,16 @@ class _FactorAnalysisBase(Model):
...
@@ -184,10 +194,16 @@ class _FactorAnalysisBase(Model):
data
.
Z
=
Z
data
.
Z
=
Z
if
keep
:
if
keep
:
self
.
data_list
.
append
(
data
)
self
.
data_list
.
append
(
data
)
return
data
return
data
.
X
,
data
.
Z
def
_log_likelihoods
(
self
,
x
,
mask
=
None
,
**
kwargs
):
self
.
add_data
(
x
,
mask
=
mask
,
**
kwargs
)
states
=
self
.
data_list
.
pop
()
return
states
.
log_likelihood
()
def
log_likelihood
(
self
):
def
log_likelihood
(
self
):
return
np
.
sum
([
d
.
log_likelihood
()
for
d
in
self
.
data_list
])
return
sum
([
d
.
log_likelihood
().
sum
()
for
d
in
self
.
data_list
])
def
log_probability
(
self
):
def
log_probability
(
self
):
lp
=
0
lp
=
0
...
...
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