Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,17 +17,14 @@ def generate_dataset(task_id):
|
|
17 |
class Net(keras.Model):
|
18 |
def __init__(self):
|
19 |
super(Net, self).__init__()
|
20 |
-
self.
|
21 |
-
self.
|
22 |
-
self.
|
23 |
|
24 |
def build(self, input_shape):
|
25 |
-
self.fc1.
|
26 |
-
|
27 |
-
self.
|
28 |
-
output_shape = self.fc2.compute_output_shape(output_shape)
|
29 |
-
self.fc3.build(output_shape)
|
30 |
-
self.built = True
|
31 |
|
32 |
def call(self, x):
|
33 |
x = self.fc1(x)
|
@@ -55,23 +52,17 @@ class GeneticAlgorithm:
|
|
55 |
self.population = [self.population[i] for i in np.argsort(fitness)[-self.population_size//2:]]
|
56 |
|
57 |
def crossover(self):
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
parent2_weights = parent2.get_weights()
|
70 |
-
child_weights = [(np.array(w1) + np.array(w2)) / 2 for w1, w2 in zip(parent1_weights, parent2_weights)]
|
71 |
-
child.set_weights(child_weights)
|
72 |
-
|
73 |
-
offspring.append(child)
|
74 |
-
self.population += offspring
|
75 |
|
76 |
def mutation(self):
|
77 |
X = np.random.rand(1, 10)
|
|
|
17 |
class Net(keras.Model):
|
18 |
def __init__(self):
|
19 |
super(Net, self).__init__()
|
20 |
+
self.units = 20
|
21 |
+
self.units2 = 10
|
22 |
+
self.units3 = 2
|
23 |
|
24 |
def build(self, input_shape):
|
25 |
+
self.fc1 = keras.layers.Dense(self.units, activation='relu', input_shape=(10,))
|
26 |
+
self.fc2 = keras.layers.Dense(self.units2, activation='relu')
|
27 |
+
self.fc3 = keras.layers.Dense(self.units3)
|
|
|
|
|
|
|
28 |
|
29 |
def call(self, x):
|
30 |
x = self.fc1(x)
|
|
|
52 |
self.population = [self.population[i] for i in np.argsort(fitness)[-self.population_size//2:]]
|
53 |
|
54 |
def crossover(self):
|
55 |
+
offspring = []
|
56 |
+
for _ in range(self.population_size//2):
|
57 |
+
parent1, parent2 = random.sample(self.population, 2)
|
58 |
+
child = Net()
|
59 |
+
child.build(input_shape=(None, 10))
|
60 |
+
parent1_weights = parent1.get_weights()
|
61 |
+
parent2_weights = parent2.get_weights()
|
62 |
+
child_weights = [(np.array(w1) + np.array(w2)) / 2 for w1, w2 in zip(parent1_weights, parent2_weights)]
|
63 |
+
child.set_weights(child_weights)
|
64 |
+
offspring.append(child)
|
65 |
+
self.population += offspring
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
def mutation(self):
|
68 |
X = np.random.rand(1, 10)
|