This file contains 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 threading | |
class ListenThread(threading.Thread): | |
def __init__(self, kivy_app): | |
threading.Thread.__init__(self) | |
self.kivy_app = kivy_app | |
def run(self): | |
while True: |
This file contains 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 kivy.app | |
import kivy.uix.button | |
import kivy.uix.label | |
import kivy.uix.textinput | |
import kivy.uix.boxlayout | |
class ServerApp(kivy.app.App): | |
def __init__(self): | |
super().__init__() |
This file contains 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 kivy.app | |
import kivy.uix.button | |
import kivy.uix.label | |
import kivy.uix.textinput | |
import kivy.uix.boxlayout | |
class ServerApp(kivy.app.App): | |
def build(self): | |
self.create_socket_btn = kivy.uix.button.Button(text="Create Socket", disabled=False) |
This file contains 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 socket | |
import pickle | |
import threading | |
import time | |
import pygad | |
import pygad.nn | |
import pygad.gann | |
import numpy |
This file contains 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
def model_averaging(self, model, other_model): | |
model_weights = pygad.nn.layers_weights(last_layer=model, initial=False) | |
other_model_weights = pygad.nn.layers_weights(last_layer=other_model, initial=False) | |
new_weights = numpy.array(model_weights + other_model_weights)/2 | |
pygad.nn.update_layers_trained_weights(last_layer=model, final_weights=new_weights) |
This file contains 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
# Preparing the NumPy array of the inputs. | |
data_inputs = numpy.array([[1, 1], | |
[1, 0], | |
[0, 1], | |
[0, 0]]) | |
# Preparing the NumPy array of the outputs. | |
data_outputs = numpy.array([0, | |
1, | |
1, |
This file contains 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 socket | |
import pickle | |
import numpy | |
import pygad | |
import pygad.nn | |
import pygad.gann | |
def fitness_func(solution, sol_idx): | |
global GANN_instance, data_inputs, data_outputs |
This file contains 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 pygad | |
import pygad.nn | |
import pygad.gann | |
# Preparing the NumPy array of the inputs. | |
data_inputs = numpy.array([[0, 1], | |
[0, 0]]) | |
# Preparing the NumPy array of the outputs. | |
data_outputs = numpy.array([1, |
This file contains 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 socket | |
import pickle | |
import time | |
import threading | |
import pygad.gann | |
num_solutions = 6 | |
GANN_instance = pygad.gann.GANN(num_solutions=num_solutions, | |
num_neurons_input=2, | |
num_neurons_hidden_layers=[2], |
This file contains 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
def run(self): | |
while True: | |
self.recv_start_time = time.time() | |
time_struct = time.gmtime() | |
date_time = "Waiting to Receive Data Starting from {day}/{month}/{year} {hour}:{minute}:{second} GMT".format(year=time_struct.tm_year, month=time_struct.tm_mon, day=time_struct.tm_mday, hour=time_struct.tm_hour, minute=time_struct.tm_min, second=time_struct.tm_sec) | |
print(date_time) | |
received_data, status = self.recv() | |
if status == 0: | |
self.connection.close() | |
print("Connection Closed with {client_info} either due to inactivity for {recv_timeout} seconds or due to an error.".format(client_info=self.client_info, recv_timeout=self.recv_timeout), end="\n\n") |