Changeset 8338


Ignore:
Timestamp:
Feb 15, 2012, 12:18:12 PM (13 years ago)
Author:
pittj
Message:

linear regression added to get the equation

Location:
trunk/anuga_work/development/mem_time_tests/linearregression/area
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/mem_time_tests/linearregression/area/main.py

    r8332 r8338  
    66import csv
    77import os
     8import numpy
    89import time
    910import liststore
     
    2122final = 'final.csv'
    2223final_path = os.path.join(scenariodir, final)
     24equation = 'equation.csv'
     25equation_path = os.path.join(scenariodir, equation)
    2326
     27#------------------------------------------------------------------------------
     28# MAIN LOOP
    2429# this is the main loops that assigns the maximum triangle area (m) and the map side length(l)
    25 
     30#------------------------------------------------------------------------------
    2631n = 1 #number of processors to use
    2732for seed in range(0,30):
     
    5762
    5863    # time step  experiment
    59 
    6064    if (host == 'cyclone.agso.gov.au'):
    6165       subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,'~/machinefiles/lnrrun.machines_cyclone', '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py',str(vartimestep),str(stdtimelength),str(stdsidelength)])
     
    6973print 'Done'
    7074
     75#------------------------------------------------------------------------------
     76# LOG ANALYSE
     77# and the Linear Regression
     78#------------------------------------------------------------------------------
     79
    7180#get the important data for the experiments from the anuga experiments
    7281analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv'))
     
    7584metalog = csv.reader(open(meta_path,'rb'))
    7685final = csv.writer(open(final_path,'wb'))
     86eq = csv.writer(open(equation_path,'wb'))
    7787
    78 #list stores the index of the values requird
     88#lists used to condense the metalog file and the regression equation
    7989indexlist = []
     90triangles = []
     91trianglessquared = []
     92timelength = []
     93filewrites = []
     94timelist = []
     95space = []
    8096
    8197#read in the first row
     
    103119indexlist.append(firstrow.index("numberofcpus"))
    104120indexlist.append(firstrow.index("host"))
    105 
    106 
    107121
    108122#write the header for the final csv
     
    137151                   row[(indexlist[15])],row[(indexlist[16])],
    138152                   row[(indexlist[17])],row[(indexlist[18])]])
     153     
     154    #make a list of all the data points, to be used in the regression
     155    timelist.append(float(taken))
     156    space.append(float(row[(indexlist[7])]))
     157    triangles.append(float(row[(indexlist[8])]))
     158    trianglessquared.append(float(row[(indexlist[8])])**2)
     159    timelength.append(float(row[(indexlist[9])]))
     160    filewrites.append(float(row[(indexlist[9])])/float(row[(indexlist[10])]))
    139161
    140 subprocess.call(['python','pmain.py'])
     162#convert these lists to arrays
     163spa = numpy.asarray(space)
     164tim = numpy.asarray(timelist)     
     165tri = numpy.asarray(triangles)
     166trisq = numpy.asarray(trianglessquared)
     167timlen = numpy.asarray(timelength)
     168filwrit = numpy.asarray(filewrites)
     169
     170#manipulate the arrays, to stack them into one array that will work the way we want for regression
     171multivariatearray = numpy.column_stack([tri.flat,trisq.flat,timlen.flat,filwrit.flat, numpy.ones(90,float)])
     172multivariatearrayspace = numpy.column_stack([tri.flat, numpy.ones(90,float)])
     173
     174#get the equations for both time and memory
     175timequation = numpy.linalg.lstsq(multivariatearray,tim)[0]
     176spaequation = numpy.linalg.lstsq(multivariatearrayspace,spa)[0]
     177
     178#calculate the R squared values for each equation
     179resid1 = numpy.linalg.lstsq(multivariatearray,tim)[1]
     180resid2 = numpy.linalg.lstsq(multivariatearrayspace,spa)[1]
     181r2 = 1 - resid1 / (tim.size * tim.var())
     182r3 = 1 - resid2 / (spa.size * spa.var())
     183
     184#write these values back to lists
     185listtime = timequation.tolist()
     186listspace = spaequation.tolist()
     187
     188#write the equation data to file
     189eq.writerow(['Dependent Variable', 'Number of Triangles','Number of Triangles Squared','Time Length','File Writes','Constant', 'R Squared'])
     190eq.writerow(['Time']+listtime + r2.tolist())
     191eq.writerow(['Dependent Variable', 'Number of Triangles','Constant', 'R Squared'])
     192eq.writerow(['Space']+listspace + r3.tolist())
     193
     194
  • trunk/anuga_work/development/mem_time_tests/linearregression/area/pmain.py

    r8332 r8338  
    77import os
    88import time
    9 import liststore
    109from anuga.abstract_2d_finite_volumes.util import add_directories
    1110from anuga.utilities.log_analyser import analyse_log
     
    2221final_path = os.path.join(scenariodir, final)
    2322
     23#------------------------------------------------------------------------------
     24# MAIN LOOP
    2425# this is the main loops that assigns the maximum triangle area (m) and the map side length(l)
    25 
     26#------------------------------------------------------------------------------
    2627
    2728for n in range(0,24):
     
    4243print 'Done'
    4344
     45#------------------------------------------------------------------------------
     46# LOG ANALYSE
     47# and the Linear Regression (This has not been implemented as the nature of the
     48# relationship between the number of cpus and time as well as memory)
     49#------------------------------------------------------------------------------
     50
    4451#get the important data for the experiments from the anuga experiments
    4552analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv'))
     
    4956final = csv.writer(open(final_path,'wb'))
    5057
    51 #list stores the index of the values requird
     58#lists used to condense the metalog file
    5259indexlist = []
    5360
     
    7582indexlist.append(firstrow.index("percentageofwatercover"))
    7683indexlist.append(firstrow.index("numberofcpus"))
     84indexlist.append(firstrow.index("myid"))
    7785indexlist.append(firstrow.index("host"))
    78 
    79 
    8086
    8187#write the header for the final csv
     
    8894                firstrow[(indexlist[13])],firstrow[(indexlist[14])],
    8995                firstrow[(indexlist[15])],firstrow[(indexlist[16])],
    90                 firstrow[(indexlist[17])],firstrow[(indexlist[18])]])
     96                firstrow[(indexlist[17])],firstrow[(indexlist[18])]],
     97                firstrow[(indexlist[19])]])
    9198
    9299#write the data for each column in the final csv
     
    109116                   row[(indexlist[13])],row[(indexlist[14])],
    110117                   row[(indexlist[15])],row[(indexlist[16])],
    111                    row[(indexlist[17])],row[(indexlist[18])]])
    112 
     118                   row[(indexlist[17])],row[(indexlist[18])]],
     119                   row[(indexlist[19])]])
     120     
  • trunk/anuga_work/development/mem_time_tests/linearregression/area/pruncairns.py

    r8332 r8338  
    55import time
    66import sys
    7 import liststore
    87import anuga
    98from anuga_parallel import distribute, numprocs, myid
     
    3736log.timingInfo(msg=('numberofcpus,'+str(numprocs))) #write the variable to be measured to file
    3837log.timingInfo(msg=('host,'+str(os.getenv('HOST')))) #write the variable to be measured to file
    39 
     38log.timingInfo(msg=('myid,'+str(myid)) #write the variable to be measured to file
    4039
    4140log.timingInfo(msg=('beforetime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation
Note: See TracChangeset for help on using the changeset viewer.