Commit cb368dc9 authored by Leon Pyka's avatar Leon Pyka
Browse files

playing around with composite features

parent 99e1b5f9
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
#How to use main.cpp to generate an edge list

compile:
>clang++ -O3 -std=c++17 -I ./ main.cpp  -o i
execute:
>./i steps=7 type=s seed=1 precr=4

steps: how many layers of hierarchically repeating structure
type: s = shuffled hierarchichal, n = non-hierarchichal (otherwise called density reference)
seed: seed for rng
precrack: length of precrack 
+1 −0
Original line number Diff line number Diff line
import mechnet as mn
+42 −1
Original line number Diff line number Diff line
%% Cell type:code id:56124a84-9241-4223-8b6a-6b597edb02df tags:

``` python
import numpy as np
import scipy.sparse as ssp
import scipy.sparse.linalg as sspla
import matplotlib.pyplot as plt
```

%% Cell type:code id:c8851736-5c0d-43bc-8eaf-7738f7896fd7 tags:

``` python
def xc(i):
    return (i%NxNy)%Nx
def yc(i):
    return (i%NxNy)//Nx
def zc(i):
    return i//NxNy
```

%% Cell type:code id:edafae36-06e9-4e31-8a60-abeb06264b8a tags:

``` python
#el = np.loadtxt('./comp_det', dtype=int)
#el = np.loadtxt('./comp_shu', dtype=int)
el = np.loadtxt('./comp_nhi', dtype=int)
#el = np.loadtxt('./comp_nhi', dtype=int)
el = np.loadtxt('../composite/edgelist_0_seed1_0', dtype=int)
steps = 6
Nx = 2**steps
Ny = Nx
Nz = 2*(steps+2)-2
NxNy = Nx*Ny
N = NxNy*Nz
```

%% Output

    ---------------------------------------------------------------------------
    FileNotFoundError                         Traceback (most recent call last)
    Cell In[23], line 4
          1 #el = np.loadtxt('./comp_det', dtype=int)
          2 #el = np.loadtxt('./comp_shu', dtype=int)
          3 #el = np.loadtxt('./comp_nhi', dtype=int)
    ----> 4 el = np.loadtxt('../edgelist_0_seed1_0', dtype=int)
          5 steps = 6
          6 Nx = 2**steps
    File ~/mechnet_env/lib64/python3.12/site-packages/numpy/lib/_npyio_impl.py:1395, in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin, encoding, max_rows, quotechar, like)
       1392 if isinstance(delimiter, bytes):
       1393     delimiter = delimiter.decode('latin1')
    -> 1395 arr = _read(fname, dtype=dtype, comment=comment, delimiter=delimiter,
       1396             converters=converters, skiplines=skiprows, usecols=usecols,
       1397             unpack=unpack, ndmin=ndmin, encoding=encoding,
       1398             max_rows=max_rows, quote=quotechar)
       1400 return arr
    File ~/mechnet_env/lib64/python3.12/site-packages/numpy/lib/_npyio_impl.py:1022, in _read(fname, delimiter, comment, quote, imaginary_unit, usecols, skiplines, max_rows, converters, ndmin, unpack, dtype, encoding)
       1020     fname = os.fspath(fname)
       1021 if isinstance(fname, str):
    -> 1022     fh = np.lib._datasource.open(fname, 'rt', encoding=encoding)
       1023     if encoding is None:
       1024         encoding = getattr(fh, 'encoding', 'latin1')
    File ~/mechnet_env/lib64/python3.12/site-packages/numpy/lib/_datasource.py:192, in open(path, mode, destpath, encoding, newline)
        155 """
        156 Open `path` with `mode` and return the file object.
        157
       (...)    188
        189 """
        191 ds = DataSource(destpath)
    --> 192 return ds.open(path, mode, encoding=encoding, newline=newline)
    File ~/mechnet_env/lib64/python3.12/site-packages/numpy/lib/_datasource.py:529, in DataSource.open(self, path, mode, encoding, newline)
        526     return _file_openers[ext](found, mode=mode,
        527                               encoding=encoding, newline=newline)
        528 else:
    --> 529     raise FileNotFoundError(f"{path} not found.")
    FileNotFoundError: ../edgelist_0_seed1_0 not found.

%% Cell type:code id:51c78c6d-139c-4d9a-b58d-cdca843511e1 tags:

``` python
nhs = el//NxNy
maxh = np.max(nhs)
levs = (nhs[:,0]+nhs[:,1])/2
```

%% Cell type:code id:0e0489da-fd8a-485e-90ed-88717c4d4411 tags:

``` python
levs
```

%% Output

    array([ 0.5,  0.5,  0.5, ..., 12.5, 12. , 12.5], shape=(135424,))

%% Cell type:code id:04df0fec-a353-49dd-aef6-622369fad2d0 tags:

``` python
subnets = []
for l in range(maxh+1):
    subnets.append(el[levs==l])
```

%% Cell type:code id:cbf72919-b5b1-4c4f-a5f5-20539e2fe334 tags:

``` python
def plot_layer(l):
    f, ax = plt.subplots()
    ax.set_aspect('equal')
    el0 = subnets[l]
    for e in el0:
        x0,x1 = xc(e)
        y0,y1 = yc(e)
        if (x1==x0+1) and (y1==y0):
            ax.plot([x0,x1],[y0,y1],'k-')
        if (y1==y0+1) and (x1==x0):
            ax.plot([x0,x1],[y0,y1],'k-')
        #now pbc
        if (x1==x0+Nx-1) and (y1==y0):
            ax.plot([x1+1,x1],[y0,y1],'k-')
        if (y1==y0+Nx-1) and (x1==x0):
            ax.plot([x0,x1],[y1+1,y1],'k-')

```

%% Cell type:code id:602aa246-8780-47f8-bedb-3d885e9921bf tags:

``` python
plot_layer(5)
```

%% Output


%% Cell type:code id:93028a58-1774-4bb1-9d63-f20f89d30a5f tags:

``` python
plot_layer(6)
```

%% Output


%% Cell type:code id:57b9ef9e-59fb-4c6e-a75e-3108a9b96ca3 tags:

``` python
plot_layer(7)
```

%% Output


%% Cell type:code id:4c6cbdbb-7ecc-42dc-91d2-5a936d755508 tags:

``` python
plot_layer(8)
```

%% Output


%% Cell type:code id:d283a28d-b65e-4e13-a588-cd7d81b47b0f tags:

``` python
plot_layer(9)
```

%% Output


%% Cell type:code id:96223e90-bc98-4c7d-b17e-d9e508c073aa tags:

``` python
verticals = []
for l in range(maxh):
    verticals.append(el[levs==l+0.5])
```

%% Cell type:code id:66ceef79-9186-4c6f-8bd7-9e1e1a097117 tags:

``` python
def plot_verticals(l):
    f, ax = plt.subplots()
    ax.set_aspect('equal')
    el0 = verticals[l]
    for e in el0:
        x0,x1 = xc(e)
        y0,y1 = yc(e)
        if x0!=x1 or y0!=y1:
            print('Error')
        else:
            ax.plot([x0],[y0], 'k.', ms=0.2)


```

%% Cell type:code id:558bced5-9d0c-4738-95d6-276b3ecbb53f tags:

``` python
plot_verticals(6)
```

%% Output


%% Cell type:code id:58fa4708-c12a-483f-92d8-f13d37931632 tags:

``` python
[len(v) for v in verticals]
```

%% Output

    [4096, 4096, 4096, 4096, 4096, 4096, 3840, 4096, 4096, 4096, 4096, 4096, 4096]

%% Cell type:code id:18e37510-a164-43d4-8653-bc92080b0a3c tags:

``` python
xx = xc(el)
```

%% Cell type:code id:8ea5d1d5-9c6e-46eb-9b0d-7bb728645dec tags:

``` python
yy = yc(el)
zz = zc(el)
```

%% Cell type:code id:3a2780ea-cd9d-4bba-b05a-b842f0ff5110 tags:

``` python
np.sum((zz[:,0]-zz[:,1])**2  >1)
```

%% Output

    0

%% Cell type:code id:139fced5-3684-4a94-97ea-3c0eeb4654c0 tags:

``` python
```

%% Cell type:code id:71fbaa1c-c8b4-45c6-92cb-ed7a459450d0 tags:

``` python
```