dDot.exportData(dataFolder + '/Run_' + str(runNum) + '.txt', 'data3', i + 1) runNum += 1 print "Subsequent " + str(len(order)) + " runs: ", time() - startTime #Generate CODA capacitive Matrix codaDataFolder = currentIterationFolder + '/CODA_data' if not os.path.exists(codaDataFolder): os.makedirs(codaDataFolder) outputFile = open(codaDataFolder + '/CODA_data.txt', 'w') for i in range(len(order) + 1): density, ts = analyzeDataFile(dataFolder + '/Run_' + str(i) + '.txt') outputVolts = currentVolts if i > 0: outputVolts[i - 1] += 0.001 outputFile.write( str(outputVolts + density.tolist() + ts.tolist()).replace( ',', '').replace(']', '').replace('[', '') + ' \n') if i > 0: outputVolts[i - 1] -= 0.001 outputFile.close() #Run CODA, select certain solutions plot, voltageChanges = l1ErrorPlot(codaDataFolder + '/CODA_data.txt', target) numTries = 10
#Generate base COMSOL data dataFolder = currentIterationFolder + '/COMSOL_data' #Run CODA, select certain solutions voltageChanges, totalDistance = findDirection( codaDataFolder + '/CODA_data.txt', target) solutionL2Norm = norm(voltageChanges, ord=2) paramMat = [] convergenceData = [[], []] minDistance = 10. runNum = 16 for alpha in logspace(-5, 0, 11): convergenceData[0] += [alpha * solutionL2Norm] density, ts = analyzeDataFile(dataFolder + '/Run_' + str(runNum) + '.txt') predictedDeps = predictDeps(codaDataFolder + '/CODA_data.txt', alpha * voltageChanges) differenceFromLinear = abs(density[0:2] - predictedDeps[0:2]).tolist() print alpha, density[0:2], predictedDeps[0:2] print alpha, array(map(log, ts)), predictedDeps[2:] differenceFromLinear += ( 0.5 * abs(array(map(log, ts)) - predictedDeps[2:])).tolist() differenceFromLinearNorm = norm(array(differenceFromLinear), ord=2) convergenceData[1] += [differenceFromLinearNorm / totalDistance] runNum += 1 if plotL1: import matplotlib matplotlib.use('Agg')
dDot.runSimulation('std2') for i in range(numTries[index]): dDot.exportData( dataFolder + '/Height_' + str(height) + '/Run_' + str(runNum) + '.txt', 'data3', i + 1) runNum += 1 print "Subsequent " + str(numTries[index]) + " runs: ", time() - startTime for index, heightParams in enumerate(params): convergenceData = [[], []] for i, dataIndex in enumerate(dataIndecesUsed[index]): convergenceData[0] += [data[index][0][dataIndex]] density, ts = analyzeDataFile(dataFolder + '/Height_' + str(heightParams[0]) + '/Run_' + str(i + 1) + '.txt') print convergenceData[0][-1], density, ts pointDistance = sum(abs(density[0:2] - target[0:2])) pointDistance += sum( abs(array(map(log, ts)) - array(map(log, target[4:])))) convergenceData[1] += [ pointDistance * data[index][2][dataIndex] / data[index][1][dataIndex] ] plt.cla() plt.clf() plt.plot(data[index][0], data[index][2], linewidth=2.) plt.plot(convergenceData[0], convergenceData[1], 's--', linewidth=2.) labels = ['Predicted Error', 'Actual Error']