-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from FlorianPfaff/restructure/manifold_vs_type
Differentiate between manifold (e.g., torus) and type (e.g., mixture)
- Loading branch information
Showing
45 changed files
with
533 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
pyrecest/distributions/abstract_bounded_domain_distribution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from .abstract_non_conditional_distribution import AbstractNonConditionalDistribution | ||
from .abstract_manifold_specific_distribution import ( | ||
AbstractManifoldSpecificDistribution, | ||
) | ||
|
||
|
||
class AbstractBoundedDomainDistribution(AbstractNonConditionalDistribution): | ||
class AbstractBoundedDomainDistribution(AbstractManifoldSpecificDistribution): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import copy | ||
import warnings | ||
from abc import abstractmethod | ||
|
||
from .abstract_distribution_type import AbstractDistributionType | ||
|
||
|
||
class AbstractCustomDistribution(AbstractDistributionType): | ||
def __init__(self, f, scale_by=1): | ||
self.f = f | ||
self.scale_by = scale_by | ||
|
||
def pdf(self, xs): | ||
# Shifting is something for subclasses | ||
return self.scale_by * self.f(xs) | ||
|
||
@abstractmethod | ||
def integrate(self, integration_boundaries=None): | ||
pass | ||
|
||
def normalize(self, verify=None): | ||
cd = copy.deepcopy(self) | ||
|
||
integral = self.integrate() | ||
cd.scale_by = cd.scale_by / integral | ||
|
||
if verify and abs(cd.integrate()[0] - 1) > 0.001: | ||
warnings.warn("Density is not yet properly normalized.", UserWarning) | ||
|
||
return cd |
8 changes: 8 additions & 0 deletions
8
pyrecest/distributions/abstract_custom_nonperiodic_distribution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .abstract_custom_distribution import AbstractCustomDistribution | ||
from .abstract_nonperiodic_distribution import AbstractNonperiodicDistribution | ||
|
||
|
||
class AbstractCustomNonPeriodicDistribution( | ||
AbstractCustomDistribution, AbstractNonperiodicDistribution | ||
): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class AbstractDistributionType: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
pyrecest/distributions/abstract_non_conditional_distribution.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .abstract_manifold_specific_distribution import ( | ||
AbstractManifoldSpecificDistribution, | ||
) | ||
|
||
|
||
class AbstractNonperiodicDistribution(AbstractManifoldSpecificDistribution): | ||
pass |
40 changes: 40 additions & 0 deletions
40
pyrecest/distributions/abstract_orthogonal_basis_distribution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import copy | ||
from abc import abstractmethod | ||
|
||
import numpy as np | ||
|
||
from .abstract_distribution_type import AbstractDistributionType | ||
|
||
|
||
class AbstractOrthogonalBasisDistribution(AbstractDistributionType): | ||
def __init__(self, coeff_mat, transformation): | ||
self.transformation = transformation | ||
self.coeff_mat = coeff_mat | ||
self.normalize_in_place() | ||
|
||
@abstractmethod | ||
def normalize_in_place(self): | ||
pass | ||
|
||
@abstractmethod | ||
def value(self, xa): | ||
pass | ||
|
||
def normalize(self): | ||
result = copy.deepcopy(self) | ||
return result.normalize_in_place() | ||
|
||
def pdf(self, xa): | ||
val = self.value(xa) | ||
if self.transformation == "sqrt": | ||
assert all(np.imag(val) < 0.0001) | ||
return np.real(val) ** 2 | ||
|
||
if self.transformation == "identity": | ||
return val | ||
|
||
if self.transformation == "log": | ||
print("Warning: Density may not be normalized") | ||
return np.exp(val) | ||
|
||
raise ValueError("Transformation not recognized or unsupported") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 15 additions & 7 deletions
22
pyrecest/distributions/circle/custom_circular_distribution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
from .abstract_circular_distribution import AbstractCircularDistribution | ||
from ..custom_distribution import CustomDistribution | ||
import numpy as np | ||
|
||
class CustomCircularDistribution(CustomDistribution, AbstractCircularDistribution): | ||
def __init__(self, f_): | ||
from ..abstract_custom_distribution import AbstractCustomDistribution | ||
from .abstract_circular_distribution import AbstractCircularDistribution | ||
|
||
|
||
class CustomCircularDistribution( | ||
AbstractCustomDistribution, AbstractCircularDistribution | ||
): | ||
def __init__(self, f_, scale_by=1, shift_by=0): | ||
""" | ||
It is the user's responsibility to ensure that f is a valid | ||
circular density, i.e., 2pi-periodic, nonnegative and | ||
normalized. | ||
""" | ||
AbstractCircularDistribution.__init__(self) | ||
CustomDistribution.__init__(self, f_, 1) | ||
|
||
def integrate(self, integration_boundaries=np.array([0, 2*np.pi])): | ||
AbstractCustomDistribution.__init__(self, f_, scale_by) | ||
self.shift_by = shift_by | ||
|
||
def pdf(self, xs): | ||
super().pdf(np.mod(xs + self.shift_by, 2 * np.pi)) | ||
|
||
def integrate(self, integration_boundaries=np.array([0, 2 * np.pi])): | ||
return AbstractCircularDistribution.integrate(self, integration_boundaries) |
Oops, something went wrong.