Example #1
0
    def run(self):
        self.totalList = [[] for i in range(0, self.T)]

        for t in range (1, self.T):
            crap = 0

            for i in self.fireflies:
                for j in i:
                    if j < 0 or j > 1:
                        print "Bounds error"

            for i in range(0, self.Nff):
                self.fireflies[i] = self.total_convergence(i, self.fireflies, self.fitnesses)

            for i in range(0, self.Nff):
                self.fireflies[i] = self.random_movements(self.fireflies[i], t, self.T)


            for i in range(0, self.Nff):
                self.fireflies[i] = np.sort(self.fireflies[i])
                self.responses[i] = self.response_model.angleSpectrum(self.fireflies[i])
                self.fitnesses[i] = self.response_model.calculateFitness(functions.convertDb(self.responses[i]))

            self.average_fitnesses_over_time[t] = np.mean(self.fitnesses)

        return self.fireflies, self.responses, self.fitnesses
Example #2
0
    def run(self):
        self.totalList = [[] for i in range(0, self.T)]

        for t in range (1, self.T):

            # for i in self.fireflies:
            #     for j in i:
            #         if j < 0 or j > 1:
            #             print "Bounds error"

            for i in range(0, self.Nff):
                self.fireflies[i] = self.total_convergence(i, self.fireflies, self.fitnesses)

            for i in range(0, self.Nff):
                self.separations[i] = self.spacing_model.calculateSpacings(self.fireflies[i])

                self.fireflies[i] = self.random_movements(self.fireflies[i], self.separations[i], t, self.T)

                self.fireflies[i] = np.sort(self.fireflies[i])
                self.responses[i] = self.response_model.angleSpectrum(self.fireflies[i])
                self.fitnesses[i] = self.response_model.calculateFitness(functions.convertDb(self.responses[i]))
                self.separations[i] = self.spacing_model.calculateSpacings(self.fireflies[i])
                self.goodSeparationCount[i] = self.spacing_model.checkSpacings(self.separations[i])

            self.averageGoodSeparationOverTime[t] = np.mean(self.goodSeparationCount)
            self.averageFitnessOverTime[t] = np.mean(self.fitnesses)
            self.averagePositionsOverTime[t] = np.mean(self.fireflies, axis=0)


        return self.fireflies, self.responses, self.fitnesses, self.goodSeparationCount, self.averageGoodSeparationOverTime, self.averageFitnessOverTime, self.averagePositionsOverTime
Example #3
0
    def checkRandomUniformSampling(self):
        fireflies = np.array([np.random.rand(self.N) for i in range (0, self.SAMPLES)])

        count, bins = np.histogram(fireflies, bins=128, range=[0, 1], density=True)
        plt.plot(bins[:-1], count)
        plt.xlim([0,1])
        plt.show()

        responses = np.empty([self.SAMPLES,self.N_phi])
        fitnesses = np.empty(self.SAMPLES)

        for index in range (0, self.SAMPLES):
            firefly = fireflies[index]
            responses[index] = self.response_model.angleSpectrum(firefly)
            fitnesses[index] = self.response_model.calculateFitness(functions.convertDb(responses[index]))

        averageResponse = np.mean(responses, axis=0)
        variance = np.var(responses, axis=0)

        modeledAverage = self.generateModeledResponse()
        modeledVariance = self.generateModeledVariance()

        meanFitness = np.mean(fitnesses)

        mse = ((averageResponse - modeledAverage) ** 2).mean(axis=None)

        DbAverageResponse = functions.convertDb(np.mean(responses, axis=0))
        DbModeledAverage = functions.convertDb(self.generateModeledResponse())

        fig = plt.figure()
        angleSpectrum = [(i*1.0/self.N_phi*180) for i in range (0, self.N_phi)]
        plt.plot(angleSpectrum, DbAverageResponse, label="Simulation")
        plt.plot(angleSpectrum, DbModeledAverage, label="Analytical Model")
        plt.plot(angleSpectrum, self.response_model.getRt(), label="Desired")
        plt.title("Mean Response Generated from\nRandom Uniform Sampling for Antenna Element Positions")
        plt.legend()
        plt.ylabel("Response (dB)")
        plt.xlabel("Angle (degrees)")
        plt.ylim([-65,5])
        plt.show()

        plt.plot(variance, label="Simulation")
        plt.plot(modeledVariance, label="Analytical Model")
        plt.legend()

        plt.show()
        return mse, DbAverageResponse
Example #4
0
 def generate_initials(self):
     rand.seed()
     self.fireflies = [np.sort(np.random.rand(self.N)) for i in range (0, self.Nff)]
     self.responses = [self.response_model.angleSpectrum(self.fireflies[j]) for j in range (0, self.Nff)]
     self.response_constraint = self.response_model.getRt()
     self.fitnesses = [self.response_model.calculateFitness(functions.convertDb(self.responses[k])) for k in range (0, self.Nff)]
     self.average_fitnesses_over_time = [0 for l in range (0, self.T)]
     self.average_fitnesses_over_time[0] = np.mean(self.fitnesses)
Example #5
0
    def sampleFromCDF(self):
        dfx = self.get_dataset()
        cdf = self.generateCDF(dfx)

        fireflies = np.array([np.array([self.sampleCDF(cdf) for j in range (0, self.N)]) for i in range (0, self.SAMPLES)])

        count, bins = np.histogram(fireflies, bins=128, range=[0, 1], density=True)
        plt.plot(bins[:-1], count)
        plt.xlim([0,1])
        plt.show()

        responses = np.empty([self.SAMPLES,self.N_phi])
        fitnesses = np.empty(self.SAMPLES)

        for index in range (0, self.SAMPLES):
            firefly = fireflies[index]
            responses[index] = self.response_model.angleSpectrum(firefly)
            fitnesses[index] = self.response_model.calculateFitness(functions.convertDb(responses[index]))

        averageResponse = np.mean(responses, axis=0)
        variance = np.var(responses, axis=0)

        modeledAverage = self.generateModeledResponse()
        modeledVariance = self.generateModeledVariance()

        meanFitness = np.mean(fitnesses)

        mse = ((averageResponse - modeledAverage) ** 2).mean(axis=None)

        DbAverageResponse = functions.convertDb(np.mean(responses, axis=0))
        DbModeledAverage = functions.convertDb(self.generateModeledResponse())

        fig = plt.figure()
        plt.plot(DbAverageResponse, label="Mean from CDF Sampled Antenna")
        plt.plot(DbModeledAverage, label="Random Uniform Sampling")
        plt.plot(self.response_model.getRt(), label="Desired")
        plt.legend()
        plt.ylim([-65,5])
        plt.show()

        plt.plot(variance, label="Simulation")
        plt.plot(modeledVariance, label="Random Uniform Sampling")
        plt.legend()
        plt.show()
        return mse, DbAverageResponse
Example #6
0
    def sampleUsingPercentileRanges(self):
        dfx = self.get_dataset()
        mins = np.percentile(dfx, 10.0, axis=0)
        medians = np.percentile(dfx, 50.0, axis=0)
        maxs = np.percentile(dfx, 90.0, axis=0)

        fireflies = np.array([self.samplePercentileRange(mins, maxs, self.N) for i in range (0, self.SAMPLES)])

        for i in range (0, 10):
            x = fireflies[:,i]
            count, bins = np.histogram(x, bins=128, range=[0, 1], density=True)
            plt.plot(bins[:-1], count)

        plt.xlim([0,1])
        plt.show()

        responses = np.empty([self.SAMPLES,self.N_phi])
        fitnesses = np.empty(self.SAMPLES)

        for index in range (0, self.SAMPLES):
            firefly = fireflies[index]
            responses[index] = self.response_model.angleSpectrum(firefly)
            fitnesses[index] = self.response_model.calculateFitness(functions.convertDb(responses[index]))

        averageResponse = functions.convertDb(np.mean(responses, axis=0))
        variance= np.var(responses, axis=0)

        medianResponse = functions.convertDb(self.response_model.angleSpectrum(medians))

        meanFitness = np.mean(fitnesses)

        fig = plt.figure()
        plt.plot(averageResponse, label="Mean Sampling from Range 10th to 90th Percentile")
        plt.plot(medianResponse, label="Response From Median")
        plt.plot(self.response_model.getRt(), label="Desired")
        plt.legend()
        plt.ylim([-65,5])
        plt.show()

        plt.plot(variance, label="Simulation")
        plt.legend()
        plt.show()
        return meanFitness, averageResponse
Example #7
0
    def analyze(self, fireflies, show=False):
        responses = np.empty([self.SAMPLES, self.N_phi])
        fitnesses = np.empty(self.SAMPLES)

        for index in range(0, self.SAMPLES):
            firefly = fireflies[index]
            responses[index] = self.response_model.angleSpectrum(firefly)
            fitnesses[index] = self.response_model.calculateFitness(
                functions.convertDb(responses[index]))

        averageResponse = functions.convertDb(np.mean(responses, axis=0))
        variance = np.var(responses, axis=0)

        meanFitness = np.mean(fitnesses)

        if show == True:
            for i in range(0, 10):
                x = fireflies[:, i]
                count, bins = np.histogram(x, bins=50, density=True)
                plt.plot(bins[:-1], count)
            plt.xlim([0, 1])
            plt.title("Positions Generated from Linear Regression")
            plt.show()

            fig = plt.figure()
            plt.plot(averageResponse, label="Mean from model")
            # plt.plot(average, label="Theoretical")
            plt.plot(self.response_model.getRt(), label="Desired")
            plt.legend()
            plt.ylim([-65, 5])
            plt.show()

            plt.plot(variance, label="Experimental")
            plt.legend()
            plt.show()

        print meanFitness
        return averageResponse, variance, meanFitness
Example #8
0
 def generate_initials(self):
     # self.fireflies = [np.sort(np.random.rand(self.N)) for i in range (0, self.Nff)]
     self.generateFireflies()
     self.responses = [self.response_model.angleSpectrum(self.fireflies[j]) for j in range (0, self.Nff)]
     self.response_constraint = self.response_model.getRt()
     self.fitnesses = [self.response_model.calculateFitness(functions.convertDb(self.responses[k])) for k in range (0, self.Nff)]
     self.averageFitnessOverTime = [0 for l in range (0, self.T)]
     self.averageFitnessOverTime[0] = np.mean(self.fitnesses)
     self.separations = [self.spacing_model.calculateSpacings(self.fireflies[i]) for i in range (0, self.Nff)]
     self.goodSeparationCount = [self.spacing_model.checkSpacings(self.separations[i]) for i in range (0, self.Nff)]
     self.averageGoodSeparationOverTime = np.empty(self.T)
     self.averageGoodSeparationOverTime[0] = np.mean(self.goodSeparationCount)
     self.averagePositionsOverTime = np.array([np.empty(self.N) for i in range (0, self.T)])
     self.averagePositionsOverTime[0] = np.mean(self.fireflies, axis=0)
Example #9
0
    # filename = "data/2018-07-27_16.40/"
    filename = "data/2018-08-02_16.32/"

    dfx = pd.read_csv(filename + "x.csv", header=None)
    dff = pd.read_csv(filename + "fitness.csv", header=None)

    dfff = dff.values.flatten()
    dropIndexs = []
    fig = plt.figure()
    count = 0

    for i, val in enumerate(dfff):
        antenna = dfx.iloc[i]
        antenna = antenna.as_matrix()
        response = model.angleSpectrum(antenna)
        fitness = model.calculateFitness(functions.convertDb(response))
        if fitness > 0.01:
            dropIndexs.append(i)
            count += 1
            # plt.plot(functions.convertDb(response))
            # plt.show()
            # print antenna

    print count

    # print dropIndexs, len(dropIndexs)
    dfx = dfx.drop(dropIndexs)
    dfx.to_csv(filename + "xNew.csv", index=False, header=False)

    dffNew = np.delete(dfff, dropIndexs)
    np.savetxt(filename + "fNew.csv", dffNew)