def runChoices(numberofRunsChoice, maxIterationsChoice, stochasticTypeChoice,
               sizeofLinearSystemChoice, randomInputsTypeChoice,
               stepSizeTypeChoice, momentumTypeChoice, momentumParamChoice,
               momentumParam2Choice):
    # We create lists for possible choices below:
    numberofRunsQues, numberofRunsList, maxIterationsQues, maxIterationsList, stochasticTypeQues, stochasticTypeList, \
    sizeofLinearSystemQues, sizeofLinearSystemList, randomInputTypeQues, randomInputTypeList, \
    stepSizeTypeQues, stepSizeTypeList, momentumTypeQues, momentumTypeList, \
    momentumParamQues, momentumParamList, momentumParam2Ques, momentumParam2List = interface.choicesData()

    # We retrieve all user inputs
    numberofRuns = numberofRunsList[numberofRunsChoice - 1]
    maxIterations = maxIterationsList[maxIterationsChoice - 1]
    stochasticType = stochasticTypeList[stochasticTypeChoice - 1]
    sizeofLinearSystem = sizeofLinearSystemList[sizeofLinearSystemChoice - 1]
    randomInputType = randomInputTypeList[randomInputsTypeChoice - 1]
    stepSizeType = stepSizeTypeList[stepSizeTypeChoice - 1]
    momentumType = momentumTypeList[momentumTypeChoice - 1]
    momentumParam = momentumParamList[momentumParamChoice - 1]
    momentumParam2 = momentumParam2List[momentumParam2Choice - 1]

    # We get the size of the system
    numStates, numFeatures = getSizeofLinearSystemFromSizeString(
        sizeofLinearSystem)

    # We use seed so that all files generated use same seed for repeatability
    random.seed(8)
    # Below is the location where the log files and charts generated will be stored
    filesLocation = "Outputs/runAllOutputs/"
    simName = getSimName(sizeofLinearSystem, stochasticType, randomInputType,
                         stepSizeType, momentumType, momentumTypeChoice,
                         momentumParam, momentumParam2)
    logFileName = simName + "_Log.txt"
    # We now create the file
    f = open(filesLocation + logFileName, "w")
    f.close()
    errorType = 8
    # We set some basic variables below
    maxIters = maxIterations
    totalErrors, meanErrors = np.zeros(maxIters), np.zeros(maxIters)
    totalIterations = numberofRuns
    # We loop for each iteration below
    for iter in range(totalIterations):
        # We generate the required matrices
        A, b = generateAbasPerChoiceInputs(randomInputsTypeChoice, numStates,
                                           numFeatures)
        start_x = generator.GenerateRandomVector(numFeatures)
        # This is the transition probability matrix, now set to uniform
        probDist = 1 / numStates * np.ones(numStates)
        # We set the print rules
        np.set_printoptions(precision=3)
        # This is the main caller. It calls CodeRunner from oneRing.py which retrieves all errors for choices.
        x_out, errors = oneRing.CodeRunner(A,
                                           b,
                                           start_x,
                                           probDist,
                                           maxIters,
                                           errorType=errorType,
                                           stochasticType=stochasticType,
                                           stepSizeType=stepSizeType,
                                           momentumType=momentumType,
                                           momentumParam=momentumParam,
                                           momentumParam2=momentumParam2)
        # We now write these errors to file.
        f = open(filesLocation + logFileName, "a")
        f.write("Errors for iteration: %d\n" % (iter + 1))
        for i in range(len(errors)):
            f.write("%d,%.2e\n" % (i + 1, errors[i]))
        f.close()
        # We compute the total error so far
        totalErrors = totalErrors + errors

        # We plot the errors into chart
        chartTitle = getChartName(sizeofLinearSystem, stochasticType,
                                  randomInputType, stepSizeType, momentumType,
                                  momentumTypeChoice, momentumParam,
                                  momentumParam2)
        chartFileName = str(iter + 1) + "-" + simName

        DrawingCharting.drawSavePlot(maxIters,
                                     errors,
                                     chartTitle,
                                     label='Total Projections Error',
                                     color="mediumorchid",
                                     logErrors=True,
                                     plotShow=False,
                                     location=filesLocation,
                                     fileName=chartFileName + ".png")

    # We now calculate the mean error over all the iterations
    meanErrors = totalErrors / totalIterations
    # We paste these mean errors into the log file
    f = open(filesLocation + logFileName, "a")
    f.write("Average Errors\n")
    for i in range(len(meanErrors)):
        f.write("%d,%.2e\n" % (i + 1, meanErrors[i]))
    f.close()
Exemple #2
0
                                    tpType="Reg")
            print("Errors for iteration: %d,momentum = %.2f" %
                  (iter + 1, momentum))
            for i in range(len(errors)):
                print("%d,%.2e" % (i + 1, errors[i]))
            #
            simName = str(
                iter +
                1) + "Long Stochastic CurvatureStep TP with RMS Prop Momentum"
            chartTitle = "Errors for Long Stochastic CurvatureStep TP with RMS Prop Momentum"
            DrawingCharting.drawSavePlotwithHorizontalLine(
                maxIters,
                errors,
                chartTitle,
                label='Total Projections Error',
                color="mediumorchid",
                logErrors=True,
                plotShow=False,
                location=filesLocation,
                fileName=simName + ".png",
                lineVal=lstSqError,
                lineLabel="Least Squares Error")

            LStSqBetterIters = maxIters
            for i in range(maxIters):
                if (errors[i] - lstSqError < 0):
                    LStSqBetterIters = i
                    break
            ourError = errorCalcs.getErrorMethod(A,
                                                 b,
                                                 x_out,
                                                 probDist,
Exemple #3
0
                                   start_x,
                                   probDist,
                                   maxIters,
                                   errorType=errorType,
                                   utType="Reg",
                                   tpType="Reg")
        print("Errors for iteration: %d" % (iter + 1))
        for i in range(len(errors)):
            print("%d,%.2e" % (i + 1, errors[i]))
        simName = str(iter + 1) + "Long Stochastic Plain TP"
        chartTitle = "Errors for Long Stochastic Plain TP"
        DrawingCharting.drawSavePlot(maxIters,
                                     errors,
                                     chartTitle,
                                     label='Total Projections Error',
                                     color="mediumorchid",
                                     logErrors=True,
                                     plotShow=False,
                                     location=filesLocation,
                                     fileName=simName + ".png")

        LStSqBetterIters = maxIters
        for i in range(maxIters):
            if (errors[i] - lstSqError < 0):
                LStSqBetterIters = i
                break
        ourError = errorCalcs.getErrorMethod(A,
                                             b,
                                             x_out,
                                             probDist,
                                             errorType,