Class Network
java.lang.Object
com.github.raimannma.architecture.Network
public class Network extends Object
The type Network.
- Author:
- Manuel Raimann
-
Field Summary
Fields Modifier and Type Field Description Set<Connection>
connections
The Connections of the network.Set<Connection>
gates
The Gates of the network.int
input
The Input size.List<Node>
nodes
The Nodes of the network.int
output
The Output size.double
score
The Score.Set<Connection>
selfConnections
The Self connections of the network. -
Constructor Summary
Constructors Constructor Description Network(int input, int output)
Instantiates a new Network. -
Method Summary
Modifier and Type Method Description void
clear()
Resets every node in this network.Connection
connect(Node from, Node to)
Connect two nodes with weight equals 0.Network
copy()
Copies a network.static @NotNull Network
crossover(@NotNull Network network1, @NotNull Network network2, boolean equal)
Create an offspring from two parent networks.void
disconnect(@NotNull Node from, Node to)
Removes the connection between two nodesboolean
equals(Object o)
double
evolve(double[][] inputs, double[][] outputs, EvolveOptions options)
Evolves the network to reach a lower error on a dataset using the NEAT algorithm.static @NotNull Network
fromJSON(@NotNull com.google.gson.JsonObject json)
Convert a json object to a networkvoid
gate(Node node, Connection connection)
Makes a network node gate a connectionint
hashCode()
void
mutate(Mutation method)
Mutates the network with the given method.void
remove(Node node)
Removes a node from a network.void
removeGate(Connection connection)
Remove the gate of a connection.void
setNodeIndices()
Sets node indices.double
test(double[][] inputs, double[][] outputs)
Test the network on dataset.double
test(double[][] inputs, double[][] outputs, Loss loss)
Test the network on dataset with given loss function.com.google.gson.JsonObject
toJSON()
Convert a network to JsonObject.String
toString()
-
Field Details
-
input
public final int inputThe Input size. -
output
public final int outputThe Output size. -
nodes
The Nodes of the network. -
score
public double scoreThe Score. used for NEAT. -
connections
The Connections of the network. -
selfConnections
The Self connections of the network. -
gates
The Gates of the network.
-
-
Constructor Details
-
Network
public Network(int input, int output)Instantiates a new Network.- Parameters:
input
- the input sizeoutput
- the output size
-
-
Method Details
-
crossover
@NotNull public static @NotNull Network crossover(@NotNull @NotNull Network network1, @NotNull @NotNull Network network2, boolean equal)Create an offspring from two parent networks.Networks are not required to have the same size, however input and output size should be the same!
- Parameters:
network1
- parent network 1network2
- parent network 2equal
- indicate that networks are equally fit- Returns:
- new network created from mixing parent networks
-
fromJSON
@NotNull public static @NotNull Network fromJSON(@NotNull @NotNull com.google.gson.JsonObject json)Convert a json object to a network- Parameters:
json
- A network represented as a JsonObject- Returns:
- the network created out of the JsonObject
-
connect
Connect two nodes with weight equals 0.- Parameters:
from
- the connection input nodeto
- the connection output node- Returns:
- the created connection
-
setNodeIndices
public void setNodeIndices()Sets node indices. -
gate
Makes a network node gate a connection- Parameters:
node
- the gating nodeconnection
- the connection to gate with node
-
mutate
Mutates the network with the given method.- Parameters:
method
- the mutation method
-
test
public double test(double[][] inputs, double[][] outputs)Test the network on dataset.- Parameters:
inputs
- the inputs of the datasetoutputs
- the outputs of the dataset- Returns:
- the error
-
test
Test the network on dataset with given loss function.- Parameters:
inputs
- the inputs of the datasetoutputs
- the outputs of the datasetloss
- the loss function- Returns:
- the error
-
evolve
Evolves the network to reach a lower error on a dataset using the NEAT algorithm.- Parameters:
inputs
- the inputs of the datasetoutputs
- the outputs of the datasetoptions
- options evolution options- Returns:
- the error of the network after evolution
-
remove
Removes a node from a network. All its connections will be redirected. If it gates a connection, the gate will be removed.- Parameters:
node
- Node to remove from the network
-
disconnect
Removes the connection between two nodes- Parameters:
from
- the incoming nodeto
- the outgoing node
-
removeGate
Remove the gate of a connection.- Parameters:
connection
- the connection to remove the gate from
-
clear
public void clear()Resets every node in this network. -
hashCode
public int hashCode() -
equals
-
toString
-
copy
Copies a network.- Returns:
- the copied network
-
toJSON
public com.google.gson.JsonObject toJSON()Convert a network to JsonObject.- Returns:
- the resulting json object
-