Commit f5046d56 authored by Marc Serramia's avatar Marc Serramia

Added plotter

parent d30e196c
# Default ignored files
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/value-aligned-norm-systems.iml" filepath="$PROJECT_DIR$/.idea/value-aligned-norm-systems.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -18,58 +18,28 @@ PROB_VALUE_NORMS = 0.2
PROB_TREE = 1
ROOTS = None
GENERALISATION_PROB = 0.2
ROUNDS = 100
ROUNDS = 10
SOLVE_TIME_LIMIT = 3600
#-----------------PLOTTING PARAMETERS-------------------
PLOT_TYPE = 7
WHAT_TO_PLOT = ["time"]#, "norms"]
PLOT_TYPE = "RATIO"
RATIO_TYPE = "D"
PLOT_NORMS = 1000
CUT = False
QUARTILE_CUT = 0
SHOW_X_RANGE = [0, 1e55]
SHOW_Y_RANGE = [0, 600]
PATH1 = "/home/marc/PycharmProjects/NormNets/PLOTDATA/1000N100V/plot1000N100V.txt"
PATH2 = "/home/marc/PycharmProjects/NormNets/PLOTDATA/1000N500V/plot1000N500V.txt"
ESTIMATOR = "MEAN"
EXPERIMENTS_WITH_VALUES = False
PLOTDOT_SIZE = 10
NUM_NORMS_PLOT = 1000
NUM_GOODS_PLOT = 'ALL'
MAX_TIME_PLOT = float('inf')
FIX_BUDGET = True
SHOW_BUDGET = False
BUDGET = [1]
BUDGET_COLOR = ['orange']
FIX_GEN = True
GEN = [0.5]
POINT_COLOR = "blue"
POINT_SIZE = 10
SAVE = True
SHOW = True
SAVE = False
QUARTILE_CUT = 0 #FOR INTERQUARTILE PUT UP AND LOW TO TRUE
UP = False
LOW = False
#QUARTILE_CUT_REGRESSION = 0
FIX_REPOWS = True
REPOWS = ['I']
ENRICH = False
DISTRIBUTE_NUM_NORMS = True
NUM_NORMS_ENRICH = None
NUM_GOODS_ENRICH = None
REG_DIMENSION = 100
REGRESSION_LINE = False
REGRESSION_LINE_COLOR = 'blue'
POINTS_COLOR = 'orange'
SHOW_POINTS = True
SAMPLING = None
#-----------------PROBLEM VISUALIZER-----------------------
GRAPH_NORMS = 6
GRAPH_GOODS = 3
GRAPH_HEIGHT = 1
GRAPH_WIDTH = 1
GRAPH_BUDGET = 25
GRAPH_GEN = 50
GRAPH_NORMS = 1000
GRAPH_HEIGHT = 2
GRAPH_WIDTH = 2
GRAPH_ROUND = 0
GRAPH_REPOWER = "I"
GRAPH_PROBLEM_TYPE = "MNSPLB"
SHOW_SOLUTION = True
GRAPH_SOLUTION = True
import os
import PARAMETERS
import numpy as np
import matplotlib.pyplot as plt
class Plot:
def __init__(self, plotfile):
self.plot_filename = plotfile
@staticmethod
def sortData(x, y):
for passnum in range(len(x) - 1, 0, -1):
for i in range(passnum):
if x[i] > x[i + 1]:
temp = x[i]
x[i] = x[i + 1]
x[i + 1] = temp
temp = y[i]
y[i] = y[i + 1]
y[i + 1] = temp
def loadScatterPoints(self):
size = os.path.getsize(self.plot_filename)
plotfile = open(self.plot_filename, "r")
x = []
y = []
while size:
line = plotfile.readline()
data = line.strip('\n').split(',')
height = data[0]
width = data[1]
num_inc = data[2]
num_dgen = data[3]
num_igen = data[4]
time = data[5]
if PARAMETERS.PLOT_TYPE == "RATIO":
if PARAMETERS.RATIO_TYPE == "D":
x.append(float(num_dgen)/float(num_inc))
elif PARAMETERS.RATIO_TYPE == "I":
x.append(float(num_igen) / float(num_inc))
else:
print "INVALID RATIO TYPE"
y.append(float(time))
size -= len(line)
plotfile.close()
return x, y
def plotratio(self):
plot_fig_path = self.plot_filename[:-4]+"Plot"+PARAMETERS.RATIO_TYPE+"Ratio"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Effect of the problem structure on the execution time', size=16)
ax.set_xlabel('Ratio (Generalisation relations / Exclusivity relations)', size=12)
ax.set_ylabel('Time (sec)', size=12)
x, y = self.loadScatterPoints()
self.sortData(x,y)
if PARAMETERS.CUT:
toRemove = []
upper_cut = np.percentile(y, 100-PARAMETERS.QUARTILE_CUT)
for i in range(len(x)):
if x[i] < PARAMETERS.SHOW_X_RANGE[0] or x[i] > PARAMETERS.SHOW_X_RANGE[1]:
toRemove.append(i)
if y[i] < PARAMETERS.SHOW_Y_RANGE[0] or y[i] > PARAMETERS.SHOW_Y_RANGE[1]:
toRemove.append(i)
if y[i] > upper_cut:
toRemove.append(i)
toRemove.sort(reverse=True)
for i in toRemove:
x.pop(i)
y.pop(i)
plt.scatter(x, y, color=PARAMETERS.POINT_COLOR, s=PARAMETERS.POINT_SIZE)
if PARAMETERS.SAVE:
plt.savefig(plot_fig_path)
if PARAMETERS.SHOW:
plt.show()
plt.close(fig)
def main():
plot_data_file = os.getcwd()+"/PLOTDATA/plot"+str(PARAMETERS.PLOT_NORMS)+"N.txt"
if os.path.exists(plot_data_file):
pl = Plot(plot_data_file)
if PARAMETERS.PLOT_TYPE == "RATIO":
pl.plotratio()
else:
print "INEXISTENT PLOT FILE"
if __name__ == "__main__":
main()
......@@ -20,7 +20,7 @@ class Problem:
self.values = {}
self.normvalues = {}
self.va = {}
self.numexcl = 0
self.num_incomp = 0
self.direct_gen = 0
self.indirect_gen = 0
self.lp = None
......@@ -107,7 +107,7 @@ class Problem:
# TODO: MAKE ANCESTORS
def generateIncomp(self):
self.num_excl = 0
self.num_incomp = 0
filename = os.getcwd()+"/"+str(self.num_norms)+"N/INC/INC_"+str(self.num_norms)+"N_" + str(self.height) + "H_" + str(self.width) + "W_" + str(self.round) + ".txt"
f = open(filename, "w")
for n1 in self.norms.keys()[:-1]:
......@@ -117,10 +117,10 @@ class Problem:
if ran < PARAMETERS.INCOMPATIBILITY_PROB:
f.write(str(n1)+", "+str(n2)+"\n")
self.inc_constraints.append([n1, n2])
self.num_excl += 1
self.num_incomp += 1
def readIncompatibilities(self, cats_filename):
self.num_excl = 0
self.num_incomp = 0
print "NOT IMPLEMENTED"
#TODO: Not yet implemented
......@@ -190,7 +190,7 @@ class Problem:
lp_file.write('/* # Width: ' + str(self.width) + ' */\n')
lp_file.write('/* # Direct generalisation relations: ' + str(self.direct_gen) + ' */\n')
lp_file.write('/* # Indirect generalisation relations: ' + str(self.indirect_gen) + ' */\n')
lp_file.write('/* # Exclusivity relations: ' + str(self.num_excl) + ' */\n')
lp_file.write('/* # Exclusivity relations: ' + str(self.num_incomp) + ' */\n')
lp_file.write("/*--------------------*/\n")
#Optimisation formula
......@@ -262,6 +262,6 @@ class Problem:
final_time = time.time() - start_time
print "Solved in "+str(final_time)+"s"
m.solution.write(self.sol)
plotfile.write(str(self.height)+", "+str(self.width)+", "+str(self.num_excl)+", "+str(self.direct_gen)+", "+str(self.indirect_gen)+", "+str(final_time))
plotfile.write(str(self.height)+","+str(self.width)+","+str(self.num_incomp)+","+str(self.direct_gen)+","+str(self.indirect_gen)+","+str(final_time))
except cplex.exceptions.CplexError:
print "UNABLE TO SOLVE "+self.lp
\ No newline at end of file
......@@ -23,7 +23,7 @@ class ProblemIterator:
problem.build()
if PARAMETERS.SOLVE:
problem.solve(f)
f.close()
f.close()
def hwcases(self):
cases = []
......
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