```python
import sympy.parsing.sympy_parser

# dfdw = 'x * exp(-w * x - b)/ (1+exp(-w * x - b))**2'
# sample_expr = '(x*((exp(b)*y-exp(b))*exp(x*w)+y))/(exp(w * x + b)+1)'
sampe_expr = '-(y - 1/(1+exp(-w*x-b))) * x'
sample_expr = sympy.parsing.sympy_parser.parse_expr(sample_expr_str)
sample_value = sample_expr.evalf(subs=dict(x=0.5, y=1, w=4, b=1))
print(sample_value)
```

    0.0225883298654561



```python
import sympy.parsing.sympy_parser

sample_expr_str = '(1/(1+exp(-w*x-b)) - y)'
sample_expr = sympy.parsing.sympy_parser.parse_expr(sample_expr_str)
sample_value = sample_expr.evalf(subs=dict(x=0.5, y=1, w=4, b=1))
print(sample_value)
```

    -0.0474258731775668



```python
import sympy.parsing.sympy_parser

sample_expr_str = '(1/(1+exp(-w*x-b))-y)*x + 2*c*w'
sample_expr = sympy.parsing.sympy_parser.parse_expr(sample_expr_str)
sample_value = sample_expr.evalf(subs=dict(x=0.5, y=1, w=4, b=1, c=1))
print(sample_value)
```

    7.97628706341122



```python
s=2
N=1000
```


```python
import numpy as np
```


```python
z = (np.arange(1, N+1).astype(float) ** (-s)).sum()
```


```python
zapf = lambda r: 1 / (z * r ** s)
```


```python
t = 1/1000
t
```




    0.001




```python
sum([1 if zapf(i) < t else 0 for i in np.arange(1, 1001)])
```




    976




```python
def calculate_pmi(a, b):
    pab = (a[b==1] == 1).sum() / len(a)
    pa = a.sum() / len(a)
    pb = b.sum() / len(b)
    print(pab, pa, pb, pa * pb, pab / (pa * pb))
    return np.log(pab / (pa * pb))
```


```python
a = np.array([1, 0, 0, 1, 1, 0])
b = np.array([1, 0, 0, 0, 1, 0])
```


```python
calculate_pmi(a, b)
```

    0.3333333333333333 0.5 0.3333333333333333 0.16666666666666666 2.0





    0.6931471805599453



2e2c47c95bd32b04e047371ddde54dc3f638d828
ipynb
Jupyter Notebook
sng_nlp_23.ipynb
ptyshevs/stepik-dl-nlp
daf63c32afe2b877da253dcd84560d4624bcfe8d
MIT
sng_nlp_23.ipynb
ptyshevs/stepik-dl-nlp
daf63c32afe2b877da253dcd84560d4624bcfe8d
MIT
sng_nlp_23.ipynb
ptyshevs/stepik-dl-nlp
daf63c32afe2b877da253dcd84560d4624bcfe8d
MIT
Qwen/Qwen-72B
1. YES
2. YES