Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 0f0fbb87 authored by Akshay Mambakam's avatar Akshay Mambakam
Browse files

[CONSTANTS_AND_RESULTSET] Replaced constants. multidim_intersection_search now returns a ResultSet.

parent 18bc86d7
Pipeline #51715 failed with stages
in 60 minutes and 1 second
......@@ -22,7 +22,7 @@ actions on Evolutionary Computation, 2018.
"""
from ParetoLib.Geometry.Segment import Segment
import copy
import copy, math
# EPS = sys.float_info.epsilon
# DELTA = sys.float_info.epsilon
......@@ -86,7 +86,7 @@ def discrete_binary_search(x,
# dist = subtract(y.high, y.low)
dist = y.norm()
# while not less_equal(dist, error):
while dist > 1.42:
while dist > math.sqrt(2):
i += 1
# yval = div(add(y.low, y.high), 2.0)
yval = y.center_round()
......@@ -106,7 +106,9 @@ def discrete_binary_search(x,
# No intersection: -2
# There exists an intersection: +1
# Don't know: -1
(INTER, DKNOW, NO_INTER) = (1, -1, -2)
# The whole search space is in the intersection: 2
# There can be no intersection in the whole of the search space: -3
(INTERFULL, INTER, DKNOW, NO_INTER, INTERNULL) = (2, 1, -1, -2, -3)
def determine_intersection(y1, y2):
......@@ -157,12 +159,12 @@ def intersection_expansion_search(x,
intersect_indicator = DKNOW
if member1(y.low) and member2(y.high):
# All the cube belongs to B1
intersect_indicator = 2
intersect_indicator = INTERFULL
elif (not member1(y.high)) or (not member2(y.low)):
# All the cube belongs to B0
y.low = x.high
y.high = x.high
intersect_indicator = -3
intersect_indicator = INTERNULL
else:
# We don't know. We search for a point in the diagonal
# dist = subtract(y.high, y.low)
......
......@@ -23,9 +23,9 @@ from sortedcontainers import SortedListWithKey, SortedSet
import ParetoLib.Search as RootSearch
# (INTER, DKNOW, NO_INTER) = (1, -1, -2)
# (INTERFULL, INTER, DKNOW, NO_INTER, INTERNULL) = (2, 1, -1, -2, -3)
from ParetoLib.Search.CommonSearch import EPS, DELTA, STEPS, INTER, DKNOW, NO_INTER, binary_search, intersection_empty, \
from ParetoLib.Search.CommonSearch import EPS, DELTA, STEPS, INTERFULL, INTERNULL, INTER, DKNOW, NO_INTER, binary_search, intersection_empty, \
intersection_empty_constrained, intersection_expansion_search, discrete_binary_search
from ParetoLib.Search.ResultSet import ResultSet
......@@ -1138,8 +1138,8 @@ def multidim_intersection_search_opt_0(xspace, list_constraints,
min_bound, max_bound = bound_box_with_constraints(xrectangle, list_constraints)
flag = 0
rect_diag = xrectangle.diag()
if (max_bound < 0) or (min_bound > 1) or (min_bound > max_bound) or (min_bound + 0.00001 > max_bound):
intersect_indicator = -3
if (max_bound < 0) or (min_bound > 1) or (min_bound > max_bound) or (min_bound + (epsilon/100) > max_bound):
intersect_indicator = INTERNULL
continue
else:
if min_bound < 0:
......@@ -1147,8 +1147,8 @@ def multidim_intersection_search_opt_0(xspace, list_constraints,
if max_bound > 1:
max_bound = 1
if min_bound > 0 or max_bound < 1:
min_bound += 0.00001
max_bound -= 0.00001
min_bound += (epsilon/100)
max_bound -= (epsilon/100)
end_min = tuple(i + (j - i) * min_bound for i, j in zip(xrectangle.min_corner, xrectangle.max_corner))
end_max = tuple(i + (j - i) * max_bound for i, j in zip(xrectangle.min_corner, xrectangle.max_corner))
mod_rectangle = Rectangle(end_min, end_max)
......@@ -1162,11 +1162,11 @@ def multidim_intersection_search_opt_0(xspace, list_constraints,
y = yCover
RootSearch.logger.debug('y: {0}'.format(y))
if intersect_indicator >= 1:
if intersect_indicator >= INTER:
intersect_box = [Rectangle(yIn.low, yIn.high)]
intersect_region = [xrectangle]
break
elif intersect_indicator == -3:
elif intersect_indicator == INTERNULL:
if flag == 1: # (min_bound > 0 and max_bound < 1):
yrectangle = Rectangle(rect_diag.low, rect_diag.high)
i = interirect(incomparable_segment, yrectangle, xrectangle)
......@@ -1225,7 +1225,7 @@ def multidim_intersection_search_opt_0(xspace, list_constraints,
RootSearch.logger.info('total volume: {0}'.format(vol_total))
RootSearch.logger.info('percentage unexplored: {0}'.format((100.0 * vol_border) / vol_total))
return (intersect_box, border, xspace, intersect_region)
return ResultSet(border, intersection_region, intersect_box, xspace)
def posNegBoxGen(incompPos, incompNegDown, incompNegUp, yIn, yCover, xrectangle):
......@@ -1349,7 +1349,7 @@ def multidim_intersection_search_opt_1(xspace, list_constraints,
yrectangle = Rectangle(y.low, y.high)
RootSearch.logger.debug('y: {0}'.format(y))
if intersect_indicator == 2:
if intersect_indicator == INTERFULL:
intersect_box.append(Rectangle(y.low, y.high))
vol_xrest += xrectangle.volume()
vol_border = vol_total - vol_xrest
......@@ -1373,7 +1373,7 @@ def multidim_intersection_search_opt_1(xspace, list_constraints,
lower_rect = Rectangle(xrectangle.min_corner, yrectangle.max_corner)
upper_rect = Rectangle(yrectangle.min_corner, xrectangle.max_corner)
vol_xrest += lower_rect.volume() + upper_rect.volume() - yrectangle.volume()
elif intersect_indicator == -3:
elif intersect_indicator == INTERNULL:
vol_xrest += xrectangle.volume()
vol_border = vol_total - vol_xrest
RootSearch.logger.info(
......@@ -1429,7 +1429,7 @@ def multidim_intersection_search_opt_1(xspace, list_constraints,
RootSearch.logger.info('total volume: {0}'.format(vol_total))
RootSearch.logger.info('percentage unexplored: {0}'.format((100.0 * vol_border) / vol_total))
return (intersect_box, border, xspace, intersect_region)
return ResultSet(border, intersection_region, intersect_box, xspace)
def multidim_intersection_search_opt_2(xspace, list_constraints,
......@@ -1514,7 +1514,7 @@ def multidim_intersection_search_opt_2(xspace, list_constraints,
yrectangle = Rectangle(y.low, y.high)
RootSearch.logger.debug('y: {0}'.format(y))
if intersect_indicator == 2:
if intersect_indicator == INTERFULL:
intersect_box.append(Rectangle(y.low, y.high))
vol_xrest += xrectangle.volume()
vol_border = vol_total - vol_xrest
......@@ -1538,7 +1538,7 @@ def multidim_intersection_search_opt_2(xspace, list_constraints,
lower_rect = Rectangle(xrectangle.min_corner, yrectangle.max_corner)
upper_rect = Rectangle(yrectangle.min_corner, xrectangle.max_corner)
vol_xrest += lower_rect.volume() + upper_rect.volume() - yrectangle.volume()
elif intersect_indicator == -3:
elif intersect_indicator == INTERNULL:
vol_xrest += xrectangle.volume()
vol_border = vol_total - vol_xrest
RootSearch.logger.info(
......@@ -1594,4 +1594,4 @@ def multidim_intersection_search_opt_2(xspace, list_constraints,
RootSearch.logger.info('total volume: {0}'.format(vol_total))
RootSearch.logger.info('percentage unexplored: {0}'.format((100.0 * vol_border) / vol_total))
return (intersect_box, border, xspace, intersect_region)
return ResultSet(border, intersection_region, intersect_box, xspace)
......@@ -90,7 +90,8 @@ def get_range(ecg_name, formula_name1, incToken, decToken, bottomToken, low_limi
fp_scratch.close()
list_intervals = [(low_limit, high_limit)]
(intersection, border, xspace, intersect_region) = pareto_ND_Intersection(ecg_name, 1, "scratchInterFn", "scratchInterFp", list_intervals, [])
rs = pareto_ND_Intersection(ecg_name, 1, "scratchInterFn", "scratchInterFp", list_intervals, [])
intersection = rs.yup
return (intersection[0].min_corner[0], intersection[0].max_corner[0])
get_range_th = lambda x1,x2,x3,x4,x5: get_range(x1, x2, "(<= ", "(>= ", " p1)", x3, x4, x5)
......@@ -399,7 +400,8 @@ if find_a_formula:
# print dec_formula
print ':::::::::::::::::::::::::'
(intersection, border, xspace, intersect_region) = pareto_ND_Intersection_eps(str(sys.argv[1]), x, 'tempInterFn', 'tempInterFp', list_intervals, new_list_constraints)
rs = pareto_ND_Intersection_eps(str(sys.argv[1]), x, 'tempInterFn', 'tempInterFp', list_intervals, new_list_constraints)
intersection = rs.yup
print len(intersection)
if len(intersection) > 0:
numForFound += 1
......@@ -418,7 +420,8 @@ if find_a_formula:
exit(0)
list_intervals = [(0, 60), (0, 60), (-10, 10)]
list_constraints = [(1,1,0,60)]
(intersection, border, xspace, intersect_region) = pareto_ND_Intersection_eps(str(sys.argv[1]), 3, 'ecgInterTemplateEpsFnND', 'ecgInterTemplateEpsFpND', list_intervals, list_constraints)
rs = pareto_ND_Intersection_eps(str(sys.argv[1]), 3, 'ecgInterTemplateEpsFnND', 'ecgInterTemplateEpsFpND', list_intervals, list_constraints)
intersection = rs.yup
print len(intersection)
print intersection
#print border
......
......@@ -36,7 +36,5 @@ def pareto_2D_func_intersection(min_tuple, max_tuple):
simplify=True)
return output_intersect
(intersection, border, xspace, intersect_region) = pareto_2D_func_intersection((0.0, 0.0), (1.0, 1.0))
rs = ResultSet(border=border, yup=intersect_region, xspace=xspace)
rs = pareto_2D_func_intersection((0.0, 0.0), (1.0, 1.0))
rs.plot_2D()
\ No newline at end of file
......@@ -13,38 +13,6 @@ import copy
import time
def filter_dup_box(testBox, compareBox):
newBox = []
for i in range(len(testBox)):
insi = False
ri = testBox[i]
for j in range(len(compareBox)):
rj = compareBox[j]
if rj == ri:
continue
if rj.inside(ri.min_corner) and rj.inside(ri.max_corner):
insi = True
break
if not insi:
newBox.append(ri)
return newBox
def getIntersectRegion(setBoxes):
intersection = []
flambda = lambda x: (70.0-x[0], -x[1], -x[2])
for box in setBoxes:
minTuple = box.min_corner
maxTuple = box.max_corner
deltaIn = box.volume()/float(100)
rs1 = getParetoFrontFn3D('ecgTemplateFn3D', sys.argv[1]+'L', 'resultTmplFn3D', sys.argv[2], minTuple, maxTuple, deltaIn)
maxTuple2 = flambda(minTuple)
minTuple2 = flambda(maxTuple)
rs2 = getParetoFrontFp3D('ecgTemplateFp3D', sys.argv[1]+'L', 'resultTmplFp3D', sys.argv[3], minTuple2, maxTuple2, deltaIn)
boxPareto = computeIntersect3D(rs1, rs2, flambda)
intersection += boxPareto
return intersection
def pareto_3D_Intersection(ecg_name, numParams, formula_name1, formula_name2, min_tuple, max_tuple):
nfile1 = './ecgLearn1.txt'
nfile2 = './ecgLearn2.txt'
......@@ -129,10 +97,10 @@ def pareto_3D_Intersection(ecg_name, numParams, formula_name1, formula_name2, mi
t0 = time.time()
min_tuple = (0.0,-1.0,-1.0)
max_tuple = (70.0,1.00,1.0)
(intersection, border, xspace, intersect_region) = pareto_3D_Intersection(str(sys.argv[1]), 3, 'ecgInterTemplateFn3D', 'ecgInterTemplateFp3D', min_tuple, max_tuple)
rs1 = pareto_3D_Intersection(str(sys.argv[1]), 3, 'ecgInterTemplateFn3D', 'ecgInterTemplateFp3D', min_tuple, max_tuple)
intersection = rs1.yup
print "num intersection boxes:", len(intersection)
t1 = time.time()
print 'TRESIMP: Time taken for intersection pareto (1):', t1 - t0
rs1 = ResultSet(border=border, yup=intersection, ylow=intersect_region, xspace=xspace)
rs1.plot_3D(opacity=0.1, fig_title='Intersection of pareto fronts', var_names=['p1','p2','p3'],clip=True)
rs1.to_file(sys.argv[1]+"_characterizeOnlyOne"+sys.argv[5]+".zip")
\ No newline at end of file
......@@ -64,7 +64,5 @@ def pareto_3D_Intersection(ecg_name, numParams, formula_name1, formula_name2, mi
print output_intersect
return output_intersect
(intersection, border, xspace, intersect_region) = pareto_3D_Intersection('221', 3, 'ecg2_fn3D', 'ecg2_fp3D', (0, -5.0, -5.0), (70, 5.0, 5.0))
rs = ResultSet(border=border, yup=intersect_region, xspace=xspace)
rs = pareto_3D_Intersection('221', 3, 'ecg2_fn3D', 'ecg2_fp3D', (0, -5.0, -5.0), (70, 5.0, 5.0))
rs.plot_3D()
\ No newline at end of file
......@@ -162,13 +162,14 @@ if (sys.argv[4]) == '0':
list_intervals = [(0, 30), (0, 20), (-10, 10), (-10,10), (-10,10), (0, 100), (0, 100)]
list_constraints = []
numDim = 7
(intersection, border, xspace, intersect_region) = pareto_ND_Intersection_eps(str(sys.argv[1]), numDim, 'ecgInterTemplateEpsFnND', 'ecgInterTemplateEpsFpND', list_intervals, list_constraints)
rs1 = pareto_ND_Intersection_eps(str(sys.argv[1]), numDim, 'ecgInterTemplateEpsFnND', 'ecgInterTemplateEpsFpND', list_intervals, list_constraints)
else:
# Work with constraints.
list_intervals = [(0, 60), (0, 60), (-10, 10)]
list_constraints = [(1,1,0,60)]
numDim = 3
(intersection, border, xspace, intersect_region) = pareto_ND_Intersection_eps(str(sys.argv[1]), numDim, 'ecgInterTemplateEpsFnND', 'ecgInterTemplateEpsFpND', list_intervals, list_constraints)
rs1 = pareto_ND_Intersection_eps(str(sys.argv[1]), numDim, 'ecgInterTemplateEpsFnND', 'ecgInterTemplateEpsFpND', list_intervals, list_constraints)
intersection = rs1.yup
print len(intersection)
print intersection
intersect_region = []
......
......@@ -12,7 +12,7 @@ from exampleComputeIntersect3D import computeIntersect3D
orac1 = OracleVolTest(numPoints=10)
orac2 = OracleVolTest(lineIntercept=1.1)
output_intersect = SearchIntersection3D(oracle1=orac1, oracle2=orac2,
rs = SearchIntersection3D(oracle1=orac1, oracle2=orac2,
min_cornerx=min_x,
min_cornery=min_y,
min_cornerz=min_z,
......@@ -29,7 +29,7 @@ output_intersect = SearchIntersection3D(oracle1=orac1, oracle2=orac2,
logging=False,
simplify=True)
(intersection, border, xspace, intersect_region) = output_intersect
intersection = rs.yup
print 'length of intersection:', len(intersection)
intersect_region = []
border = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment