File g_models.py changed (mode: 100644) (index e8d9b92..3daee87) |
... |
... |
class CosExp2D: |
846 |
846 |
g = np.cos( ( np.exp(-sample[:,0] - s ) )*sample[:,0]) * np.exp( -(sample[:,0] + s )/3 ) |
g = np.cos( ( np.exp(-sample[:,0] - s ) )*sample[:,0]) * np.exp( -(sample[:,0] + s )/3 ) |
847 |
847 |
return SampleBox(input_sample, g, repr(self)) |
return SampleBox(input_sample, g, repr(self)) |
848 |
848 |
|
|
|
849 |
|
def pf_expression(self, f): |
|
850 |
|
xs, rad_max = self._get_x() |
|
851 |
|
sign = np.sign(np.cos(rad_max)) |
|
852 |
|
#sign = (k_max + 1) // 2 - 1 |
|
853 |
|
xs.reverse() |
|
854 |
|
print(xs) |
|
855 |
|
cdfs = f.marginals[0].cdf(xs) |
|
856 |
|
print(cdfs) |
|
857 |
|
if sign > 0: |
|
858 |
|
pf = 0 |
|
859 |
|
else: |
|
860 |
|
pf = 1 |
|
861 |
|
for cdf in cdfs: |
|
862 |
|
pf += cdf * sign |
|
863 |
|
sign *= -1 |
|
864 |
|
|
|
865 |
|
#print(pf) |
|
866 |
|
return pf, "series calculation" |
|
867 |
|
|
|
868 |
|
def _get_x(self, n=10, steps=10): |
|
869 |
|
## log(np.pi/4) == -x - s + log(x) |
|
870 |
|
## log(rad) + s == -x + log(x) |
|
871 |
|
## x-log(x) = -log(rad) - s |
|
872 |
|
|
|
873 |
|
#rad = exp(-x-s)*x |
|
874 |
|
#log(rad/x) = -x -s |
|
875 |
|
#x = -log(rad/x) - s |
|
876 |
|
|
|
877 |
|
# d_rad/dx = -exp(-x-s)*x + exp(-x-s) |
|
878 |
|
# d_rad/dx = exp(-x-s) * (1-x) |
|
879 |
|
|
|
880 |
|
## d2/dx2 = exp(-x-s) * (x-1) - exp(-x-s) |
|
881 |
|
## d2/dx2 = exp(-x-s) * (x-2) |
|
882 |
|
|
|
883 |
|
rad_max = np.exp(-self._s - 1) |
|
884 |
|
#print(rad_max) |
|
885 |
|
k_max = np.floor(rad_max / np.pi - 1/2) |
|
886 |
|
k = k_max |
|
887 |
|
#x = f.marginals[0].ppf(1e-200) |
|
888 |
|
rad = (k - n - 1 + 1/2) * np.pi |
|
889 |
|
#x = rad / np.exp(-self._s) |
|
890 |
|
x = -np.log(abs(rad)) - self._s |
|
891 |
|
xs = [] |
|
892 |
|
|
|
893 |
|
for i in range(-n, 2): |
|
894 |
|
#print(rad) |
|
895 |
|
for __ in range(steps): # 10 out to be enough for everybody |
|
896 |
|
x = x + (rad / np.exp(-x-self._s) - x) / (1-x) |
|
897 |
|
#print(x) |
|
898 |
|
xs.append(x) |
|
899 |
|
rad = (k+i + 1/2) * np.pi |
|
900 |
|
return xs, rad_max |
|
901 |
|
|
849 |
902 |
# Fence off! |
# Fence off! |
850 |
903 |
def get_2D_R_boundary(self, nrod=100, xlim=(-5,5), ylim=(-5,5)): |
def get_2D_R_boundary(self, nrod=100, xlim=(-5,5), ylim=(-5,5)): |
851 |
904 |
""" |
""" |
|
... |
... |
class CosExp2D: |
853 |
906 |
nrod - number of rods in fencing |
nrod - number of rods in fencing |
854 |
907 |
""" |
""" |
855 |
908 |
|
|
856 |
|
if self._s == 5: |
|
857 |
|
# it is not mine |
|
858 |
|
xa = -4.05229846333861 |
|
859 |
|
xb = -4.95067172463682 |
|
860 |
|
xc = -5.37859367619679 |
|
861 |
|
xd = -5.66345816541508 |
|
862 |
|
xe = -5.87765022259327 |
|
863 |
|
xf = -6.04950202015156 |
|
864 |
|
xg = -6.19309680892552 |
|
865 |
|
|
|
866 |
|
# ikska |
|
867 |
|
xes = (xa, xb, xc, xd, xe, xf, xg) |
|
868 |
|
|
|
869 |
|
boundaries = [] |
|
870 |
|
ymin, ymax = ylim |
|
871 |
|
|
|
872 |
|
for x in xes: |
|
873 |
|
xbound = np.full(nrod, x) |
|
874 |
|
ybound = np.linspace(ymin, ymax, nrod, endpoint=True) |
|
875 |
|
# sample compatible |
|
876 |
|
# малы транспонировать кароно? Озьы кулэ! |
|
877 |
|
bound_R = np.vstack((xbound, ybound)).T |
|
878 |
|
boundaries.append(Ingot(bound_R)) |
|
879 |
|
|
|
880 |
|
|
|
881 |
|
return boundaries |
|
|
909 |
|
# it is not mine |
|
910 |
|
#xa = -4.05229846333861 |
|
911 |
|
#xb = -4.95067172463682 |
|
912 |
|
#xc = -5.37859367619679 |
|
913 |
|
#xd = -5.66345816541508 |
|
914 |
|
#xe = -5.87765022259327 |
|
915 |
|
#xf = -6.04950202015156 |
|
916 |
|
#xg = -6.19309680892552 |
|
917 |
|
|
|
918 |
|
# ikska |
|
919 |
|
#xes = (xa, xb, xc, xd, xe, xf, xg) |
|
920 |
|
xes, __rad_max = self._get_x() |
|
921 |
|
|
|
922 |
|
boundaries = [] |
|
923 |
|
ymin, ymax = ylim |
|
924 |
|
|
|
925 |
|
for x in xes: |
|
926 |
|
xbound = np.full(nrod, x) |
|
927 |
|
ybound = np.linspace(ymin, ymax, nrod, endpoint=True) |
|
928 |
|
# sample compatible |
|
929 |
|
# малы транспонировать кароно? Озьы кулэ! |
|
930 |
|
bound_R = np.vstack((xbound, ybound)).T |
|
931 |
|
boundaries.append(Ingot(bound_R)) |
882 |
932 |
|
|
|
933 |
|
|
|
934 |
|
return boundaries |
883 |
935 |
|
|
884 |
|
|
|
885 |
|
else: |
|
886 |
|
# jako kdyby .get_2D_R_boundary nebyla vůbec definována. |
|
887 |
|
raise AttributeError("Hranice poruchy pro s!=5 není spočitana") |
|
888 |
936 |
|
|
889 |
937 |
|
|
890 |
938 |
|
|