Skip to content

Commit

Permalink
Add docstring for noise_sampler.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SoloWayG committed Nov 21, 2023
1 parent 4020c3c commit e2e9ffa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
28 changes: 19 additions & 9 deletions gefest/tools/samplers/rand_gen/noise_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@
import numpy as np
from gefest.core.geometry.geometry_2d import Geometry2D


class NoisedPoly():
geometry = Geometry2D()
"""Сlass for revers mutation of synthetic geometry. It is a sampler of geometry,
that generate simillary to reference polygons.
class apply a noise for every point of polygon (except first and last for close geometry!!!),
than it can rotate and resize obtained polygon.
Args:
scale (float): - scale factor mapped to domain side. Necessary for obtain
'sigma' arg for uniform noise function.
Recommend from 0.01 to 0.05.
May be tested for other examples;
init_poly (Polygon): - Reference polygon necessary to generate new reverse mutated geometry;
resize_scale (List[min,max]): range of min and max value for
random.uniform generation x_scale and y_scale: (scale value for **x** axis ;scale value for **y** axis).
Necessary for resize_polygon function;
degrees_to_rotate (int;float): +/- degrees to rotate polygon;
rules (List[Rules]): List of geometry validation rules
"""
class for revers mutation of synthetic geometry. It is a sampler of geometry,
that generate simillary to reference polygons.
geometry = Geometry2D()

class apply a noise for every point of polygon (except first and last for close geometry!!!),
than it can rotate and resize obtained polygon.
"""
def __init__(self, init_poly:Polygon, scale:float=0.1,
def __init__(self, init_poly:Polygon, scale:float=0.01,
resize_scale:List=None, probability:float=0.75,
degrees_to_rotate:int=180, rules:List= None,
domain=None):
Expand Down Expand Up @@ -76,8 +87,7 @@ def remove_points(self,poly: Polygon) -> Polygon:
return poly

def resize_polygon(self,poly: Polygon) -> Polygon:
"""
resize polygon size
"""resize polygon size func
"""
if np.random.uniform(0, 1) < self.proba:
poly = self.geometry.resize_poly(poly,self.x_scale,self.y_scale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@
geometry = Geometry2D()

path_=f"{root}/cases/synthetic/syn_gen/Comsol_points/lightning.txt"
#best_poly = poly_from_comsol_txt(path=path_).polygons[0]
best_poly = poly_from_comsol_txt(path=path_).polygons[0]

best_poly = random_star_shaped_polygon(num_points=4)
best_poly = Polygon([Point(p[0]*min(coord_X)+len_x/2,p[1]*min(coord_Y)+len_y/2) for p in best_poly])
# best_poly = random_star_shaped_polygon(num_points=4)
# best_poly = Polygon([Point(p[0]*min(coord_X)+len_x/2,p[1]*min(coord_Y)+len_y/2) for p in best_poly])
#best_poly.points.append(best_poly.points[0])



plt.ion()
noise = NoisedPoly(init_poly=best_poly,scale=0.01,degrees_to_rotate=10)
noise = NoisedPoly(init_poly=best_poly,scale=0.06,degrees_to_rotate=30)
for _ in range(200):
#angle = np.random.randint(-100, 100)
plt.clf()
Expand Down

0 comments on commit e2e9ffa

Please sign in to comment.