Ejemplo n.º 1
0
'''
import mpslib as mps
import time
import numpy as np
import os
import copy

#%% Initialize the MPS object, using a specific algorithm (def='mps_snesim_tree')
# for windows users :
# IT IS SUPER IMPOERTANT TO ADD THE MEXT LINE IN ORDER TO PREVENT
# PYTHON ENTERING AN INFINITE LOOP DOING PRALLEL SIMULATION!
if __name__ == '__main__':

    #%% Setup MPSlib
    O = mps.mpslib(method='mps_snesim_tree',
                   simulation_grid_size=(80, 70, 1),
                   origin=(0, 0, 0))
    #O=mps.mpslib(method='mps_genesim', simulation_grid_size=(80,70,1), origin=(0,0,0))

    O.par['n_real'] = 50
    O.par['n_cond'] = 4
    # Set training image
    O.ti = mps.trainingimages.strebelle()[0]
    #O.plot_ti()

    # Set hard and soft data
    O.delete_local_files()  # Make sure no hard/soft data are conditioned to
    d_hard = np.array([[25, 10, 0, 0], [28, 13, 0, 1]])
    d_soft = np.array([[10, 10, 0, 0.1, 0.9], [10, 13, 0, .1, 0.9],
                       [30, 53, 0, .01, 0.99]])
    O.d_hard = d_hard
#%%
import matplotlib.pyplot as plt
import mpslib as mps
import numpy as np


#%% MPS_SNESIM_TREE
O1=mps.mpslib(method='mps_snesim_tree')
O1=mps.mpslib(method='mps_genesim')
O1.delete_local_files()
O1.par['debug_level']=-1


# when debug_level>-1 and the text output from mpslib increase, the mpslib exe file is detached from 
# python before it has finished running!!!
#TI, TI_filename=mps.trainingimages.lines()
#TI, TI_filename=mps.trainingimages.bangladesh()
#TI, TI_filename=mps.trainingimages.checkerboard()
#TI, TI_filename=mps.trainingimages.checkerboard2()
#TI, TI_filename=mps.trainingimages.checkerboard2(nx=40, ny=50, cell_x=8, cell_y=4, cell_2=10)
TI, TI_filename=mps.trainingimages.checkerboard2(nx=100, ny=100, cell_x=4, cell_y=4, cell_2=3)
#TI, TI_filename=mps.trainingimages.checkerboard2(nx=100, ny=100, cell_x=14, cell_y=8, cell_2=5)
#TI, TI_filename=mps.trainingimages.checkerboard2(nx=40, ny=40, cell_x=4, cell_y=4, cell_2=9)
#TI, TI_filename=mps.trainingimages.maze()

O1.par['ti_fnam']=TI_filename
O1.par['simulation_grid_size'][0]=35
O1.par['simulation_grid_size'][1]=35
O1.par['simulation_grid_size'][2]=1

O1.par['soft_data_fnam']='soft_case2.dat'
Ejemplo n.º 3
0
# mpslib_example.py
# example of using mpslib.py

#%%
import mpslib as mps;
import matplotlib.pyplot as plt;
import numpy as np;
from scipy import squeeze


O1 = mps.mpslib(method='mps_snesim_tree', n_real = 1)
O2 = mps.mpslib(method='mps_snesim_tree', n_real = 1)

#%%  Load and set training image
ti = mps.trainingimages.strebelle()[0]

O1.ti=ti
O2.ti=np.swapaxes(ti,0,1)

O1.par['ti_fnam']='ti1.dat'
O2.par['ti_fnam']='ti2.dat'

#%% SIMULATE
O1.run()
O2.run()

#%% plot the TI's and simulation results
plt.set_cmap('hot')
fig1 = plt.figure(1)
plt.subplot(2,2,1)
plt.title('TI')
import sys
import numpy as np
import time
from random import randint

# import mpslib
import mpslib as mps;

# import the RGBMatrix library from
# https://github.com/hzeller/rpi-rgb-led-matrix/tree/master/bindings
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from PIL import Image


#%% Setup MPSlib
O1 = mps.mpslib(method='mps_genesim', n_real = 1, verbose_level=-1)
#O1.par['simulation_grid_size'][0]=matrix.width;
#O1.par['simulation_grid_size'][1]=matrix.height;
O1.par['simulation_grid_size'][0]=32;
O1.par['simulation_grid_size'][1]=32;
O1.par['debug_level']=-1;
O1.par['n_cond']=25;
O1.ti= mps.trainingimages.maze()[0]
O1.ti = O1.ti[10:300:1][:,10:300:1]
#O1.ti = O1.ti[10:300:2][:,10:300:2]
#O1.ti= mps.trainingimages.checkerboard()[0]
O1.par['rseed']=0;
O1.par['shuffle_simulation_grid']=1;
O1.run()

#%% Configuration for the RGB matrix
Ejemplo n.º 5
0
TI2, TI_filename2 = mps.trainingimages.strebelle(di=2)
mps.eas.write_mat(TI2,TI_filename2)


plt.figure(1)
plt.subplot(121)
plt.imshow(np.transpose(squeeze(TI1)))
plt.title(TI_filename1)
plt.subplot(122)
plt.imshow(np.transpose(squeeze(TI2)))
plt.title(TI_filename2)
plt.show()

#%% MPS_SNESIM_TREE
grid_size = np.array([350, 200, 1])
O = mps.mpslib(method='mps_snesim_tree',
                    n_real = 1, verbose_level=-1)
#O = mps.mpslib(method='mps_genesim',
#                    n_real = 1, verbose_level=-1)
O.par['debug_level']=-1
O.par['n_cond']=49
O.par['simulation_grid_size']=grid_size


#%% USE MASK
d_mask1=np.zeros([grid_size[0],grid_size[1],grid_size[2]])
d_mask1[80:150,100:180]=1;
d_mask1[0:40,80:150,]=1;
d_mask2=1-d_mask1;

mask_fnam1='mask_01.dat'
mask_fnam2='mask_02.dat'
Ejemplo n.º 6
0
        ax = plt.Subplot(fig, inner[j])
        fig.add_subplot(ax)
        plt.imshow(np.transpose(TI2[:, :, j]))
        plt.axis('off')

#%% RUN THE SIMULATIONS

alg='mps_snesim_tree'
#alg='mps_genesim'
nc=8*8
rseed=1;
#nc=8*8
#Coarsen channel TI, using only coarsened TI

# Single coarsened TI
O1=mps.mpslib(method=alg)
O1.par['debug_level']=-1
O1.par['ti_fnam']='ti1.dat'
O1.par['simulation_grid_size'][0]=85
O1.par['simulation_grid_size'][1]=45
O1.ti = TI1
O1.par['simulation_grid_size'][2]=1
O1.par['shuffle_simulation_grid']=0
O1.par['n_cond']=nc
O1.par['rseed']=rseed
O1.par['n_real']=1
O1.parameter_filename='sim1.par'
O1.delete_local_files()
O1.run()

# Detailed Coarsened TI
# import
import sys
import numpy as np
import time
from random import randint

# import mpslib
import mpslib as mps

# import the RGBMatrix library from
# https://github.com/hzeller/rpi-rgb-led-matrix/tree/master/bindings
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from PIL import Image

#%% Setup MPSlib
O1 = mps.mpslib(method='mps_genesim', n_real=1, verbose_level=-1)
#O1.par['simulation_grid_size'][0]=matrix.width;
#O1.par['simulation_grid_size'][1]=matrix.height;
O1.par['simulation_grid_size'][0] = 32
O1.par['simulation_grid_size'][1] = 32
O1.par['debug_level'] = -1
O1.par['n_cond'] = 9
#O1.ti= mps.trainingimages.maze()[0]
O1.ti = mps.trainingimages.checkerboard()[0]
O1.ti = O1.ti[10:300:2][:, 10:300:2]
O1.par['rseed'] = 0

#%% Configuration for the RGB matrix
options = RGBMatrixOptions()
options.rows = 32
options.chain_length = 1
'''Python
Example of using sequential Gibbs simualtion to randoly pertub a realization
'''


import mpslib as mps
import matplotlib.pyplot as plt
import numpy as np
import random

O1=mps.mpslib(method='mps_snesim_tree')

TI1, TI_filename1 = mps.trainingimages.strebelle(3, coarse3d=1)
O1.ti=TI1

O1.par['n_multiple_grids']=2;
O1.par['n_cond']=49
O1.par['n_real']=1
O1.par['debug_level']=-1
O1.par['simulation_grid_size'][0]=35
O1.par['simulation_grid_size'][1]=30
O1.par['shuffle_simulation_grid']=1
O1.run()

step=0.75;


N_run = 3;

for i in range(0,N_run):
Ejemplo n.º 9
0
'''
import mpslib as mps
import time
import numpy as np
import os
import copy


#%% Initialize the MPS object, using a specific algorithm (def='mps_snesim_tree')
# for windows users : 
# IT IS SUPER IMPOERTANT TO ADD THE MEXT LINE IN ORDER TO PREVENT 
# PYTHON ENTERING AN INFINITE LOOP DOING PRALLEL SIMULATION!
if __name__ == '__main__':
    
    #%% Setup MPSlib
    O=mps.mpslib(method='mps_snesim_tree', simulation_grid_size=(80,70,1), origin=(0,0,0))
    #O=mps.mpslib(method='mps_genesim', simulation_grid_size=(80,70,1), origin=(0,0,0))
    
    
    O.par['n_real']=50
    O.par['n_cond']=4
    # Set training image
    O.ti = mps.trainingimages.strebelle()[0]
    #O.plot_ti()
    
    # Set hard and soft data
    O.delete_local_files() # Make sure no hard/soft data are conditioned to
    d_hard = np.array([[25,10,0,0],[28,13,0,1]])
    d_soft = np.array([[10,10,0,0.1, 0.9],[10,13,0,.1, 0.9],[30,53,0,.01, 0.99]])
    O.d_hard = d_hard
    O.d_soft = d_soft
Ejemplo n.º 10
0
# mpslib_example.py
# example of using mpslib.py

#%%
import mpslib as mps;
import matplotlib.pyplot as plt;
import numpy as np;
from scipy import squeeze


O1 = mps.mpslib(method='mps_snesim_tree', n_real = 1)
O2 = mps.mpslib(method='mps_snesim_tree', n_real = 1)

#%%  Load and set training image
ti = mps.trainingimages.strebelle()[0]
ti2=np.transpose(ti)

O1.ti=ti
O2.ti=np.swapaxes(ti,2,1)

#%% SIMULATE
O1.run()
O2.run()

#%% plot the TI's and simulation results
plt.set_cmap('hot')
fig1 = plt.figure(1)
plt.subplot(2,2,1)
plt.title('TI')
plt.imshow(squeeze(O1.ti))
plt.subplot(2,2,2)
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-
"""
Created on Thu Feb  1 20:44:17 2018

@author: Thomas Mejer Hansen
"""
##%load_ext autoreload
##%autoreload 2
##%%
#import sys
#sys.path.append('../mpslib')

import mpslib as mps
import numpy as np

O1=mps.mpslib(method='mps_genesim')
O1.par['debug_level']=-1
# when debug_level>-1 and the text output from mpslib increase, the mpslib exe file is detached from 
# python before it has finished running!!!
TI, TI_filename=mps.trainingimages.checkerboard2()
O1.ti = TI
O1.par['ti_fnam']=TI_filename
O1.par['simulation_grid_size'][0]=35
O1.par['simulation_grid_size'][1]=15
O1.par['simulation_grid_size'][2]=1
O1.par['soft_data_fnam']='soft_case2.dat'
O1.par['shuffle_simulation_grid']=2
O1.par['n_cond']=49
O1.par['rseed']=0
O1.par['n_real']=36
O1.d_hard=np.array([[10,10,0,2],[13,10,0,2]])
Ejemplo n.º 12
0
# mpslib_example_1.py
# example of using mpslib

#%%
import mpslib as mps
import matplotlib.pyplot as plt
plt.set_cmap('hot')



#%% MPS_SNESIM_TREE

O1 = mps.mpslib(method='mps_snesim_tree',
                    n_real = 4, verbose_level=-1)
O1.parameter_filename = 'mps_snesim.txt'
O1.par['debug_level']=-1
O1.par['n_cond']=49

TI, TI_fname = mps.trainingimages.checkerboard()
TI, TI_fname = mps.trainingimages.bangladesh()
#O1.ti=TI
O1.par['ti_fnam']=TI_fname

O1.run()

#%%
plt.figure(1)
O1.plot_reals()
plt.savefig(O1.method+'.png', dpi=600)
plt.show()
Ejemplo n.º 13
0
#%%
import mpslib as mps
import matplotlib.pyplot as plt
import numpy as np

#%%  LOAD TI

#%%  LOAD TI
ti = mps.trainingimages.bangladesh(di=2)[0]

ti_file1 = 'ti_1.dat'
ti_file2 = 'ti_2.dat'

#%% SIMULATE
O1 = mps.mpslib(method='mps_snesim_tree',
                n_real=1,
                verbose_level=0,
                ti_fnam=ti_file1)
O1.ti = ti
O1.run()

O1.blank_grid = np.zeros(
    (O1.par['simulation_grid_size'][1], O1.par['simulation_grid_size'][0]),
    dtype=np.int)
O1.blank_grid[0:20, :] = 1
O1.blank_sim()

O2 = mps.mpslib(method='mps_snesim_tree',
                n_real=1,
                verbose_level=0,
                ti_fnam=ti_file2)
O2.ti = np.transpose(ti)
Ejemplo n.º 14
0
'''
mpslib_hard_and_soft_data.py

Example of parsing hard and soft data to MPSLIB algorithms
'''

import mpslib as mps
import numpy as np
import matplotlib as plt
plt.ion()

if __name__ == '__main__':

    #%%
    #O1=mps.mpslib(method='mps_snesim_tree', parameter_filename='mps_snesim.txt')
    O1 = mps.mpslib(method='mps_genesim', parameter_filename='mps_genesim.txt')

    TI1, TI_filename1 = mps.trainingimages.strebelle(3, coarse3d=1)
    O1.par['soft_data_categories'] = np.array([0, 1])

    #TI1, TI_filename1 = mps.trainingimages.checkerboard2()
    #O1.par['soft_data_categories']=np.array([0,1,2])

    O1.ti = TI1

    #%%
    O1.par['rseed'] = 1
    O1.par['n_multiple_grids'] = 0
    O1.par['n_cond'] = 25
    O1.par['n_cond_soft'] = 3
    O1.par['n_real'] = 50
Ejemplo n.º 15
0
'''
mpslib_simple:
The simplest example of running MPSlib from python
'''
import mpslib as mps


#%% Initialize the MPS object, using a specific algorithm (def='mps_snesim_tree')
O=mps.mpslib(method='mps_snesim_tree')
#%% Select number of iterations [def=1]
O.par['n_real']=4


# Set training image
O.ti = mps.trainingimages.strebelle()[0]
O.plot_ti()

#%% Run MPSlib
O.run()

#%% Plot the results
O.plot_reals(hardcopy=1, hardcopy_filename='mpslib_simple_reals')

O.plot_etype(hardcopy=1, hardcopy_filename='mpslib_simple_etype')

# O.plot_reals_vtk()
Ejemplo n.º 16
0
# -*- coding: utf-8 -*-
"""
Created on Thu Feb  1 20:44:17 2018

@author: Thomas Mejer Hansen
"""
##%load_ext autoreload
##%autoreload 2
##%%
#import sys
#sys.path.append('../mpslib')

import matplotlib.pyplot as plt
import mpslib as mps

O1 = mps.mpslib(method='mps_genesim')
O1.par['debug_level'] = -1
# when debug_level>-1 and the text output from mpslib increase, the mpslib exe file is detached from
# python before it has finished running!!!
TI, TI_filename = mps.trainingimages.checkerboard2()
O1.ti = TI
O1.par['ti_fnam'] = TI_filename
O1.par['simulation_grid_size'][0] = 35
O1.par['simulation_grid_size'][1] = 35
O1.par['simulation_grid_size'][2] = 1
O1.par['soft_data_fnam'] = 'soft_case2.dat'
O1.par['shuffle_simulation_grid'] = 2
O1.par['n_cond'] = 25
O1.par['rseed'] = 0
O1.par['n_real'] = 16
O1.parameter_filename = 'plot.par'
'''
mpslib_hard_and_soft_data.py

Example of parsing hard and soft data to MPSLIB algorithms
'''

import mpslib as mps
import numpy as np

if __name__ == '__main__':
    
    
    #%%
    #O1=mps.mpslib(method='mps_snesim_tree', parameter_filename='mps_snesim.txt')
    O1=mps.mpslib(method='mps_genesim', parameter_filename='mps_genesim.txt')
    
    
    TI1, TI_filename1 = mps.trainingimages.strebelle(3, coarse3d=1)
    O1.par['soft_data_categories']=np.array([0,1])
    
    #TI1, TI_filename1 = mps.trainingimages.checkerboard2()
    #O1.par['soft_data_categories']=np.array([0,1,2])
    
    O1.ti=TI1
    
    #%%
    O1.par['rseed']=1
    O1.par['n_multiple_grids']=0;
    O1.par['n_cond']=25
    O1.par['n_cond_soft']=3
    O1.par['n_real']=50
Ejemplo n.º 18
0
# mpslib_example_3.py
# Example of 'blank_simulation' --> Currently not working!!

#%%
import mpslib as mps
import mpslib.eas as eas
import matplotlib.pyplot as plt
import numpy as np

#%%  LOAD TI
ti = mps.trainingimages.strebelle(3, 1)[0]

#%% SIMULATE
O1 = mps.mpslib(method='mps_snesim_tree', n_real=1, verbose_level=-1)
O1.ti = ti
O1.run()

O1.blank_grid = np.zeros(
    (O1.par['simulation_grid_size'][1], O1.par['simulation_grid_size'][0]),
    dtype=np.int)
O1.blank_grid[0:20, :] = 1
O1.blank_sim()

O2 = mps.mpslib(method='mps_snesim_tree', n_real=1, verbose_level=0)
O2.ti = np.transpose(ti)
O2.run()

O2.blank_grid = np.zeros(
    (O1.par['simulation_grid_size'][1], O1.par['simulation_grid_size'][0]),
    dtype=np.int)
O2.blank_grid[20:, :] = 1
Ejemplo n.º 19
0
                   [13., 16., 0., 0.14375, 0.85625],
                   [3., 14., 0., 0.14375, 0.85625]])

# The soft data, but coded as 'hard' data
d_soft_hard = np.array([[6., 14., 0., 0., 1.], [13., 16., 0., 0., 1.],
                        [3., 14., 0., 0., 1.]])

#%% Initialize the MPS object, using a specific algorithm (def='mps_snesim_tree')
nx = 20
ny = 30
nz = 1
x0 = 0
y0 = 0
z0 = 0
O = mps.mpslib(method='mps_genesim',
               simulation_grid_size=np.array([nx, ny, nz]),
               origin=np.array([x0, y0, z0]))
O.delete_local_files()  # Make sure no hard/soft data are conditioned to

# Use soft data

O.par['n_real'] = 100
O.par[
    'shuffle_simulation_grid'] = 2  # '2' indicates using a preferential simulation path
O.par['n_max_ite'] = 10000000
O.par['n_max_cpd_count'] = 20
# Direct sampling style
O.par['n_cond'] = 16
O.par['n_cond_soft'] = 0

O.par['max_search_radius'] = 100