Every diffusion coefficient can be subjected to some perturbation. This script presents perturbations that we investigate in the tests. It also shows the utilization of the 'buildcoef2d' class and its benefits in terms of perturbations. First, we show the original coefficient, determine the elements we want to perturb and simulate each perturbation. For further explanations of the 'buildcoef2d' perturbation functions, we refer to the thesis.
In [1]:
import os
import sys
import numpy as np
%matplotlib notebook
import matplotlib.pyplot as plt
from visualize import drawCoefficient, ExtradrawCoefficient
import buildcoef2d
In [2]:
bg = 0.05 #background
val = 1 #values
NWorldFine = np.array([42, 42])
CoefClass = buildcoef2d.Coefficient2d(NWorldFine,
bg = bg, # background
val = val, # values
length = 2, # length
thick = 2, # thickness
space = 2, # space between values
probfactor = 1, # probability of an value
right = 1, # shape 1
down = 0, # shape 2
diagr1 = 0, # shape 3
diagr2 = 0, # shape 4
diagl1 = 0, # shape 5
diagl2 = 0, # shape 6
LenSwitch = None, # various length
thickSwitch = None, # various thickness
ChannelHorizontal = None, # horizontal Channels
ChannelVertical = None, # vertical Channels
BoundarySpace = True # additional space on the boundary
)
A = CoefClass.BuildCoefficient() # coefficient in a numpy array
A = A.flatten()
plt.figure("Original")
drawCoefficient(NWorldFine, A)
plt.title("Original")
plt.show()
# What entries will be perturbed
numbers = [13,20,27,44,73]
In [3]:
B = CoefClass.SpecificValueChange( Number = numbers,
ratio = -0.4,
randomvalue = None,
negative = None,
ShapeRestriction = True,
ShapeWave = None,
probfactor = 1,
Original = True)
B = B.flatten()
plt.figure("Change in value")
drawCoefficient(NWorldFine, B)
plt.title("Change in value")
plt.show()
In [4]:
C = CoefClass.SpecificVanish( Number = numbers,
PartlyVanish = None,
probfactor = 1,
Original = True)
C = C.flatten()
plt.figure("Disappearance")
drawCoefficient(NWorldFine, C)
plt.title("Disappearance")
plt.show()
In [5]:
D = CoefClass.SpecificMove( Number = numbers,
steps = 1,
randomstep = None,
randomDirection = None,
Right = 1,
BottomRight = 1,
Bottom = 1,
BottomLeft = 1,
Left = 1,
TopLeft = 1,
Top = 1,
TopRight = 1,
Original = True)
D = D.flatten()
plt.figure("Shift")
drawCoefficient(NWorldFine, D)
plt.title("Shift")
plt.show()
In [6]:
plt.figure('Perturbatons')
ExtradrawCoefficient(NWorldFine, A, B, C, D)
plt.show()