Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

356 nnet #378

Merged
merged 68 commits into from
Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
df49252
import DeepNetts and create NNetwork
S010MON Jun 6, 2022
a9eb9a7
removes module components
S010MON Jun 6, 2022
99ffba0
removes gradle components
S010MON Jun 6, 2022
d674d31
Tensor Loader and Saver added with testing
S010MON Jun 6, 2022
fb5b1f4
remove exclusion and outdated comment
S010MON Jun 6, 2022
af59fa7
add network manager testing
S010MON Jun 6, 2022
b99346a
fixes network issues
S010MON Jun 6, 2022
dfeb3a7
Network training complete
S010MON Jun 6, 2022
bcd5ef9
add normalisation of data
S010MON Jun 7, 2022
9c0e6d0
add data cleaning and reset data
S010MON Jun 7, 2022
6225c24
model training patched
S010MON Jun 7, 2022
3c49649
update code style
S010MON Jun 7, 2022
27775f3
failed to sort out training, swapping to GA
S010MON Jun 7, 2022
a7f96b0
complete genetic algorithm
S010MON Jun 7, 2022
baf4572
complete genetic algorithm v2
S010MON Jun 7, 2022
5440dc9
update with NN that can achieve 20%
S010MON Jun 7, 2022
81e3386
adds new method of cross pollination
S010MON Jun 7, 2022
5794a0c
adds smart method of update for safer overwriting
S010MON Jun 7, 2022
eb5ec14
60% nnet trained
S010MON Jun 8, 2022
9c98143
Merge remote-tracking branch 'origin/356-nnet' into 356-nnet
S010MON Jun 8, 2022
2bbb784
update new (larger) neural net
S010MON Jun 8, 2022
91f3418
add less frequent breeding and asexual reproduction
S010MON Jun 8, 2022
d8b0f9f
adds incremental increased
S010MON Jun 8, 2022
fe4a0ed
add stagnation measures to cause breeding
S010MON Jun 8, 2022
4d59ad2
fix hidden layer sizes
S010MON Jun 8, 2022
90318c4
add new hidden layers
S010MON Jun 8, 2022
8437880
Changes the way that outputs are converted to movements
S010MON Jun 8, 2022
efecf63
remove stagnation checks
S010MON Jun 8, 2022
5b71e0c
add sprint speeds to intruders
S010MON Jun 8, 2022
6e0b1f4
update weights and biases
S010MON Jun 8, 2022
3c45f00
update weights and biases
S010MON Jun 8, 2022
0eb56d5
update weights and biases
S010MON Jun 8, 2022
308af94
update weights and biases
S010MON Jun 8, 2022
1ba0041
set the goddamn new network
S010MON Jun 8, 2022
2d84a80
Delete network.json
S010MON Jun 8, 2022
af32f7f
remove all trace of the old architecture
S010MON Jun 8, 2022
d03a710
Merge remote-tracking branch 'origin/356-nnet' into 356-nnet
S010MON Jun 8, 2022
360270f
add new JSON
S010MON Jun 8, 2022
c549d62
new architecture
S010MON Jun 8, 2022
53fb475
Delete network.json
S010MON Jun 8, 2022
7905a12
new architecture again
S010MON Jun 8, 2022
83ddf53
12% in 7
S010MON Jun 8, 2022
cd7347b
try again to remove tanh
S010MON Jun 8, 2022
7b2f6d7
i dunno anymore ...
S010MON Jun 8, 2022
fc57a14
Delete network.json
S010MON Jun 8, 2022
d79a5f4
Delete biases_layer_0
S010MON Jun 8, 2022
3b75861
Delete biases_layer_1
S010MON Jun 8, 2022
b590eec
Delete biases_layer_2
S010MON Jun 8, 2022
7aa2c75
Delete biases_layer_3
S010MON Jun 8, 2022
d767d58
Delete biases_layer_4
S010MON Jun 8, 2022
fa42fbf
Delete weights_layer_1
S010MON Jun 8, 2022
5af4fa1
Delete weights_layer_2
S010MON Jun 8, 2022
e4e20d7
Delete weights_layer_3
S010MON Jun 8, 2022
bda569e
Delete weights_layer_4
S010MON Jun 8, 2022
03d5b51
new attempt
S010MON Jun 8, 2022
38e8927
working NNet
S010MON Jun 8, 2022
c2279cf
Merge branch 'master' into 356-nnet
S010MON Jun 9, 2022
502a09e
adjust evaluation function to kill after no moves
S010MON Jun 11, 2022
1ff2a20
Merge branch 'master' into 356-nnet
S010MON Jun 12, 2022
fe9c6f1
Merge branch 'master' into 356-nnet
S010MON Jun 13, 2022
34ee5cd
Import changes from master
S010MON Jun 13, 2022
580988c
adds generational saving
S010MON Jun 14, 2022
7f5fc7d
remove extra terminal output
S010MON Jun 14, 2022
b940f53
add all networks
S010MON Jun 14, 2022
69a8de1
Hopefully final attempt at evaluation function
S010MON Jun 14, 2022
db771c4
100 tics
S010MON Jun 14, 2022
94f2519
remove mutation from unchanged parents
S010MON Jun 16, 2022
25bc5a9
fix issue with mutation
S010MON Jun 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ plugins {
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.1'
id 'io.freefair.lombok' version '6.4.0'

// Note: the java modularity plugin is added by default with javafx, this manual addition is to override the version
// more info here https://discuss.gradle.org/t/unable-to-build-project-with-gradle-7-3-1-on-java-17/41601
// id 'org.javamodularity.moduleplugin' version '1.8.10'
// Removed 16 Feb - Seems to have had no effect
}

version '1.0'
Expand Down Expand Up @@ -39,7 +34,6 @@ tasks.withType(JavaCompile) {
}

application {
mainModule = 'app'
mainClass = 'app.App'
}

Expand All @@ -54,6 +48,9 @@ dependencies {
implementation 'org.jgrapht:jgrapht-core:1.5.1'
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")

// https://mvnrepository.com/artifact/com.deepnetts/deepnetts-core
implementation group: 'com.deepnetts', name: 'deepnetts-core', version: '1.13.0'
}

test {
Expand Down
Binary file removed build/libs/multi-agent-surveillance-1.2.jar
Binary file not shown.
70 changes: 70 additions & 0 deletions data_cleaning.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 23,
"id": "805f63e6",
"metadata": {},
"outputs": [],
"source": [
"with open('src/main/resources/nNet/data.csv') as file:\n",
" data = file.readlines()\n",
" \n",
"clean = []"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "2f8a53e9",
"metadata": {},
"outputs": [],
"source": [
"for line in data:\n",
" \n",
" if not 'NaN' in line:\n",
" clean.append(line)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "120244af",
"metadata": {},
"outputs": [],
"source": [
"with open('src/main/resources/nNet/data.csv', 'w') as file:\n",
" file.writelines(clean)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95f5fbfc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file removed libs/jogging-2.0.1.jar
Binary file not shown.
Binary file added libs/jogging-2.0.4.jar
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/java/app/controller/io/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.Scanner;

public class FileManager
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public abstract class RandomSettingsGenerator

public static Settings generateRandomSettings()
{
clearRandomGenerator();
initialiseTemplates();

Settings randomSettings = createBaseSettings();
createRandomObstacles(randomSettings);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/app/controller/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class Settings
private double sprintSpeedIntruder;
private double timeStep;
private double scaling;
private AgentType guardType = AgentType.ACO;
private AgentType IntruderType = AgentType.WALL_FOLLOW;
private AgentType guardType = AgentType.ACO_MOMENTUM_SPIRAL_AVOIDANCE;
private AgentType IntruderType = AgentType.NEURAL_NET;
private ArrayList<SettingsObject> furniture = new ArrayList<>();
private ArrayList<SettingsObject> soundSources = new ArrayList<>();
private ArrayList<SettingsObject> soundFurniture = new ArrayList<>();
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/app/model/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class Map

public Map(Settings settings)
{
System.out.print("Loading settings ... ");
this.settings = settings;
this.width = settings.getWidth();
this.height = settings.getHeight();
Expand Down Expand Up @@ -93,7 +92,6 @@ public Map(Settings settings)
activateHuman();

this.coverage = new Coverage(this);
System.out.print(" done");
}

public Map(Agent agent, ArrayList<Furniture> obstacles)
Expand Down Expand Up @@ -157,6 +155,18 @@ public MemoryGraph createFullGraph()
return fullGraph;
}

public void addAgent(Agent agent)
{
if(agent.getType() == Type.INTRUDER)
agent.setPosition(randPosition(intruderSpawn));
else if(agent.getType() == Type.GUARD)
agent.setPosition(randPosition(guardSpawn));

agent.setDirection(randDirection());
agents.add(agent);
}


public void updateAllSeen(Agent agent)
{
if(agent.getType() == Type.GUARD)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/app/model/agents/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface Agent extends Boundary

Vector getPosition();

void setPosition(Vector position);

Vector getDirection();

void setDirection(Vector direction);
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/app/model/agents/AgentImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
import app.model.agents.Capture.DijkstraCaptureAgent;
import app.view.agentView.AgentView;
import app.view.simulation.Info;
import java.util.ArrayList;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;


public class AgentImp implements Agent
{
@Getter @Setter protected double maxWalk = 10;
Expand All @@ -33,15 +31,15 @@ public class AgentImp implements Agent
@Getter @Setter protected Vector typePosition;
@Getter @Setter protected Vector tgtDirection;
@Getter @Setter protected ArrayList<Ray> view;
@Getter @Setter protected World world;
@Getter @Setter protected Vector position;
@Getter protected Type type;
@Getter protected Vector position;
@Getter protected double radius;
@Getter protected ArrayList<SoundVector> heard;
@Getter protected VectorSet seen;
@Getter protected AgentView agentViewWindow;
protected final boolean DRAW_HEARD = false;

@Getter @Setter protected World world;


public AgentImp(Vector position, Vector direction, double radius, Type type)
Expand Down Expand Up @@ -276,4 +274,22 @@ public Agent nextState()
{
return StateTable.lookupState(this);
}

protected float[] normalise(float[] data)
{
float max = 0f;
for(int i = 0; i < data.length; i++)
{
if(data[i] > max)
max = data[i];
}

for(int i = 0; i < data.length; i++)
{
if(data[i] != -1)
data[i] = data[i] / 1000;
}

return data;
}
}
17 changes: 13 additions & 4 deletions src/main/java/app/model/agents/AgentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import app.controller.linAlg.Vector;
import app.model.Type;
import app.model.agents.ACO.*;
import app.model.agents.Capture.BaselineCaptureAgent;
import app.model.agents.Capture.CaptureAgent;
import app.model.agents.Capture.DijkstraCaptureAgent;
import app.model.agents.Evasion.*;
import app.model.agents.Capture.*;
import app.model.agents.WallFollow.WFMedDirHeuristic;
import app.model.agents.WallFollow.WFHighDirHeuristic;
import app.model.agents.WallFollow.WallFollowAgent;
import app.model.agents.nNet.NeuralNet;

public enum AgentType
{
Expand All @@ -18,18 +21,20 @@ public enum AgentType
ACO_RANKING,
ACO_COLONY,
WALL_FOLLOW,
WALL_FOLLOW_MED_DIR_HEURISTIC,
WALL_FOLLOW_HIGH_DIR_HEURISTIC,
EVASION_RANDOM,
EVASION_DIRECTED,
EVASION_RANDOMDIRECTED,
WALL_FOLLOW_MED_DIR_HEURISTIC,
WALL_FOLLOW_HIGH_DIR_HEURISTIC,
EVASION_INTELLIGENT,
EVASION_DISTANCE_MAX,
EVASION_HIDEY,
CAPTURE_BASELINE,
EVASION_RUNAWAY,
CAPTURE_DIJKSTRA,
CAPTURE,
RANDOM;
RANDOM,
NEURAL_NET;

public static Agent agentOf(AgentType agentType, Vector position, Vector direction, double radius, Type type)
{
Expand Down Expand Up @@ -92,6 +97,10 @@ public static Agent agentOf(AgentType agentType, Vector position, Vector directi
case RANDOM -> {
return new AgentImp(position, direction, radius, type);
}
case NEURAL_NET ->
{
return new NeuralNet(position, direction, radius, type);
}
default -> throw new RuntimeException("Agent type not recognized");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ else if (!noWallDetected(getAngleOfLeftRay()) && leftCell.getObstacle())
Move nextMove = new Move(newDirection, deltaPos);
direction = nextMove.getEndDir();
noMovesDone = false;

return nextMove;
}

Expand Down
Loading