Skip to content

Commit a22e4b3

Browse files
committed
Changed repr of interval to give correct representation as an object construction
1 parent e3a8b47 commit a22e4b3

File tree

1 file changed

+1
-72
lines changed

1 file changed

+1
-72
lines changed

src/python/interval.py

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, a, b=None):
8080
# Formatting functions:
8181
#
8282
def __repr__(self):
83-
return "Interval[{}, {}]".format(self.lo, self.hi)
83+
return "Interval({}, {})".format(repr(self.lo), repr(self.hi))
8484
#return "Interval[{}, {}]".format(repr(self.lo), repr(self.hi))
8585

8686

@@ -791,74 +791,3 @@ def make_interval(self, a):
791791
# raise ValueError("No such rounding mode; setting it to RoundToNearest")
792792
#
793793
# return a
794-
795-
796-
def random_interval( infimum=-10.0, supremum=10.0 ):
797-
num1a = np.random.uniform( infimum, supremum )
798-
num2a = np.random.uniform( infimum, supremum )
799-
800-
return Interval( num1a, num2a )
801-
802-
def split_interval( x, num_divisions=1 ):
803-
"""
804-
Divide un Interval en n=num_divisions Intervals iguales
805-
"""
806-
num_divisions = int(num_divisions)
807-
if num_divisions < 1:
808-
num_divisions = 1
809-
810-
edge_points = np.linspace(x.lo, x.hi, num_divisions+1)
811-
splited_intervals = [Interval(a, b) for (a,b) in
812-
zip(edge_points[0:num_divisions+1],edge_points[1:num_divisions+2]) ]
813-
814-
return splited_intervals
815-
816-
def range_interval_f( fun, subdivided_interval ):
817-
"""
818-
Evalua la función f(x) extendida sobre Intervals, en una lista de subIntervals
819-
y regresa el hull de todos ellos, es decir, una cota del rango de la función
820-
"""
821-
if not isinstance( subdivided_interval, list ):
822-
subdivided_interval = [ subdivided_interval ]
823-
824-
range_fun = [ fun(i) for i in subdivided_interval ]
825-
range_tot = range_fun[0]
826-
827-
for i in range_fun[1:]:
828-
range_tot = range_tot.hull(i)
829-
830-
return range_tot
831-
832-
def plot_interval_f( fun, x, pow2=0, num_points=101 ):
833-
"""
834-
This plots the interval extension of a function `fun` over the interval `x`,
835-
which is diveded in num=1,2,4,...,2**pow2 uniform subintervals.
836-
"""
837-
num_intervals = [ 2**p for p in range(pow2+1) ]
838-
plt.figure()
839-
plt.subplot(1, 1, 1)
840-
841-
for num in num_intervals:
842-
fact_alfa = num*1.0/num_intervals[-1] # for plotting
843-
844-
# Se divide los subIntervale en 2**num subIntervals iguales
845-
subdivided_intervals = split_interval( x, num )
846-
# Se calculan las extensiones de la función sobre el Interval, usando los subIntervals
847-
rango_total = range_interval_f( fun, subdivided_intervals )
848-
print "Rango_tot (N={}) = {}".format(num,rango_total)
849-
850-
# Hago el dibujo
851-
for x1 in subdivided_intervals:
852-
low = float(x1.lo)
853-
high = float(x1.hi)
854-
Ffun = fun(x1)
855-
xa1 = np.array([low, low, high, high])
856-
ya1 = np.array([float(Ffun.lo), float(Ffun.hi), float(Ffun.hi), float(Ffun.lo) ])
857-
plt.fill( xa1, ya1, 'b', alpha=fact_alfa )
858-
859-
low = float(x.lo)
860-
high = float(x.hi)
861-
xx = np.linspace(low,high,num_points)
862-
yy = fun(xx)
863-
plt.plot( xx, yy, 'red')
864-
return

0 commit comments

Comments
 (0)