This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include "/home/tollie/Development/Maximilian/maximilian.h" | |
| #include <vector> | |
| #include <algorithm> | |
| #include <chrono> | |
| size_t amount = 1; | |
| std::vector<maxiOsc> maxiObjects; | |
| void process() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| modulator_frequency = 4.0 | |
| carrier_frequency = 40.0 | |
| modulation_index = 1.0 | |
| time = np.arange(44100.0) / 44100.0 | |
| modulator = np.sin(2.0 * np.pi * modulator_frequency * time) * modulation_index | |
| carrier = np.sin(2.0 * np.pi * carrier_frequency * time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Possibly the best Machine Learning library ever | |
| import numpy as np | |
| # Let's print the output nicely | |
| np.set_printoptions(precision=3, suppress=True) | |
| # Population Size | |
| size = 100 | |
| # How regularily the flies are dispersed |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for i, p in enumerate(self.population): | |
| if elitism > 0 and i in n_fittest: | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| self.disturbance_threshold *= decay |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| envs = [gym.make(self.env_name) for _ in range(multiprocessing.cpu_count())] | |
| amount_per_thread = int(np.floor(self.population_size / multiprocessing.cpu_count())) | |
| left_over = self.population_size - amount_per_thread * multiprocessing.cpu_count() | |
| fitnesses = np.zeros(len(self.population)) | |
| def get_weights_reward(begin, size, env): | |
| for i in range(begin, begin + size): | |
| fitnesses[i] = -self.get_reward(self.population[i], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| swarms_best_index = np.argmin(fitnesses) | |
| self.swarms_best_score = np.amin(fitnesses) | |
| self.swarms_best = self.population[swarms_best_index] | |
| if self.swarms_best_score <= self.all_time_best_score: | |
| self.all_time_best_score = self.swarms_best_score | |
| self.all_time_best = self.swarms_best |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if self.mode == 'original': | |
| if r[i][x] < self.disturbance_threshold: | |
| p[x] = np.random.normal(dev, mean) | |
| else: | |
| leader_rate = np.random.uniform(0.0, 1.0) | |
| update = self.swarms_best[x] - best_neighbour[x] | |
| p[x] = best_neighbour[x] + leader_rate * update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| elif self.mode == 'hybrid': | |
| if r[i][x] < self.disturbance_threshold: | |
| p[x] = np.random.normal(dev, mean) | |
| else: | |
| leader_rate = np.random.uniform(0.0, 1.0) | |
| update = (best_neighbour[x] + self.swarms_best[x]) / 2.0 - p[x] | |
| p[x] = p[x] + leader_rate * update |
OlderNewer