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>connectionsThe Connections of the network.Set<Connection>gatesThe Gates of the network.intinputThe Input size.List<Node>nodesThe Nodes of the network.intoutputThe Output size.doublescoreThe Score.Set<Connection>selfConnectionsThe 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 voidclear()Resets every node in this network.Connectionconnect(Node from, Node to)Connect two nodes with weight equals 0.Networkcopy()Copies a network.static @NotNull Networkcrossover(@NotNull Network network1, @NotNull Network network2, boolean equal)Create an offspring from two parent networks.voiddisconnect(@NotNull Node from, Node to)Removes the connection between two nodesbooleanequals(Object o)doubleevolve(double[][] inputs, double[][] outputs, EvolveOptions options)Evolves the network to reach a lower error on a dataset using the NEAT algorithm.static @NotNull NetworkfromJSON(@NotNull com.google.gson.JsonObject json)Convert a json object to a networkvoidgate(Node node, Connection connection)Makes a network node gate a connectioninthashCode()voidmutate(Mutation method)Mutates the network with the given method.voidremove(Node node)Removes a node from a network.voidremoveGate(Connection connection)Remove the gate of a connection.voidsetNodeIndices()Sets node indices.doubletest(double[][] inputs, double[][] outputs)Test the network on dataset.doubletest(double[][] inputs, double[][] outputs, Loss loss)Test the network on dataset with given loss function.com.google.gson.JsonObjecttoJSON()Convert a network to JsonObject.StringtoString()
-
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
-